freeEntries = $free_entries; } /** * Combine this state with another state from the same shift. * * @param ShiftSignupState $shiftSignupState The other state to combine */ public function combineWith(ShiftSignupState $shiftSignupState) { $this->freeEntries += $shiftSignupState->getFreeEntries(); if ($this->valueForState($shiftSignupState->state) > $this->valueForState($this->state)) { $this->state = $shiftSignupState->state; } } /** * @param string $state * @return int */ private function valueForState($state) { return match ($state) { ShiftSignupState::NOT_ARRIVED, ShiftSignupState::NOT_YET, ShiftSignupState::SHIFT_ENDED => 100, ShiftSignupState::SIGNED_UP => 90, ShiftSignupState::FREE => 80, ShiftSignupState::ANGELTYPE, ShiftSignupState::COLLIDES => 70, ShiftSignupState::OCCUPIED, ShiftSignupState::ADMIN => 60, default => 0, }; } /** * Returns true, if signup is allowed * * @return bool */ public function isSignupAllowed() { return match ($this->state) { ShiftSignupState::FREE, ShiftSignupState::ADMIN => true, default => false, }; } /** * Return the shift signup state * * @return string */ public function getState() { return $this->state; } /** * How many places are free in this shift for the angeltype? * * @return int */ public function getFreeEntries() { return $this->freeEntries; } }