diff --git a/phpstan.neon b/phpstan.neon index 5e8d0fbe..9c3358ee 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -23,6 +23,10 @@ parameters: # 3rd party library message: '#Access to an undefined property Skautis\\Skautis::\$OrganizationUnit\.#' path: src\Skautis\SkautisService.php + - + # database manipulation + message: '#kissj\\Participant\\Patrol\\PatrolParticipant::\$patrolLeader \(kissj\\Participant\\Patrol\\PatrolLeader\) does not accept null\.#' + path: src\Participant\ParticipantService.php exceptions: uncheckedExceptionRegexes: - '#Exception#' diff --git a/src/Participant/ParticipantService.php b/src/Participant/ParticipantService.php index ab5dab99..ce0b1205 100755 --- a/src/Participant/ParticipantService.php +++ b/src/Participant/ParticipantService.php @@ -12,6 +12,7 @@ use kissj\Mailer\PhpMailerWrapper; use kissj\Participant\Guest\Guest; use kissj\Participant\Patrol\PatrolLeader; +use kissj\Participant\Patrol\PatrolParticipant; use kissj\Participant\Troop\TroopLeader; use kissj\Participant\Troop\TroopParticipant; use kissj\Participant\Troop\TroopParticipantRepository; @@ -499,6 +500,14 @@ public function tryChangeRoleWithMessages(string $roleFromBody, Participant $par return false; } + + if ($participant instanceof PatrolParticipant) { + $participant->patrolLeader = null; + } + + if ($participant instanceof TroopParticipant) { + $participant->troopLeader = null; + } $participant->role = $role; $this->participantRepository->persist($participant);