<?phpenum Mood:string{case Content ='content';case Fine ='fine';case Tired ='tired';case Anxious ='anxious';}classPerson{privateconst MAX_ENERGY =100;privateconst HOURS_NEEDED =8;privateint$energy= self::MAX_ENERGY;privatefloat$stress=0.0;privateint$sleepDebt=0;// hours owedprivateint$openLoops=0;// things you said you'd doprivatearray$closeness=[];// name => 0.0 .. 1.0publicfunction__construct(public readonly string$name,private readonly bool$introvert=true,){}publicfunctionsleep(int$hours):void{$this->sleepDebt=max(0,$this->sleepDebt+ self::HOURS_NEEDED-$hours);$this->energy=min(self::MAX_ENERGY,$hours*12-$this->sleepDebt*5);$this->stress*=0.7;// sleep helps. a bit.}publicfunctionwork(int$hours,int$meetings=0):void{$this->drain($hours*6+$meetings*8);$this->stress+=$meetings*0.15;$this->openLoops+=intdiv($meetings,2);// every other meeting = a new action item}publicfunctionsocialise(Person$other,int$minutes):void{// introverts pay for it; extroverts get paid$this->introvert?$this->drain(intdiv($minutes,2)):$this->energy=min(self::MAX_ENERGY,$this->energy+intdiv($minutes,5));$current=$this->closeness[$other->name]??0.0;$this->closeness[$other->name]=min(1.0,$current+$minutes/600);}publicfunctionpromise():void{$this->openLoops++;$this->stress+=0.1;}publicfunctionfollowThrough():void{if($this->openLoops===0){return;}$this->openLoops--;$this->stress=max(0.0,$this->stress-0.2);}publicfunctionmood():Mood{returnmatch(true){$this->energy<20=> Mood::Tired,$this->stress>1.0,$this->openLoops>5=> Mood::Anxious,$this->energy>70&&$this->stress<0.3=> Mood::Content,default=> Mood::Fine,};}// the public interfacepublicfunctionhowAreYou():Mood{return Mood::Fine;}publicfunctionclosestFriend():?string{if(!$this->closeness){returnnull;}arsort($this->closeness);returnarray_key_first($this->closeness);}privatefunctiondrain(int$amount):void{$this->energy=max(0,$this->energy-$amount);}}$me=new Person('pooper');$me->sleep(hours:5);$me->work(hours:9, meetings:6);echo$me->howAreYou()->value;// fineecho$me->mood()->value;// tired