-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Service\Lpa\ResolveActor; | ||
|
||
use App\Entity\LpaStore\LpaStoreAttorney; | ||
use App\Entity\LpaStore\LpaStoreDonor; | ||
use App\Entity\LpaStore\LpaStoreTrustCorporations; | ||
|
||
/** | ||
* @psalm-require-implements HasActorInterface | ||
*/ | ||
trait LpaStoreHasActorTrait | ||
{ | ||
/** @var LpaStoreAttorney[] */ | ||
public readonly ?array $attorneys; | ||
|
||
/** @psalm-var ?LpaStoreDonor */ | ||
public readonly ?object $donor; | ||
|
||
/** @var LpaStoreTrustCorporations[] */ | ||
public readonly ?array $trustCorporations; | ||
|
||
public function hasActor(string $uid): ?LpaActor | ||
{ | ||
// Determine if the actor is a primary attorney | ||
$actor = $this->isAPrimaryAttorney($uid); | ||
|
||
// If not an attorney or tc, check if they're the donor. | ||
if ($actor === null) { | ||
$actor = $this->isADonor($uid); | ||
Check warning on line 32 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php Codecov / codecov/patchservice-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L31-L32
|
||
} | ||
|
||
// Is the actor a trust corporation | ||
if ($actor === null) { | ||
$actor = $this->isATrustCorporation($uid); | ||
Check warning on line 37 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php Codecov / codecov/patchservice-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L36-L37
|
||
} | ||
|
||
return $actor; | ||
} | ||
|
||
private function isAPrimaryAttorney(string $uid): ?LpaActor | ||
{ | ||
foreach ($this->attorneys as $attorney) { | ||
if ((string) $attorney->uId === $uid) { | ||
return new LpaActor($attorney, ActorType::ATTORNEY); | ||
Check warning on line 47 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php Codecov / codecov/patchservice-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L45-L47
|
||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private function isADonor(string $uid): ?LpaActor | ||
{ | ||
if ($this->donor->uId === $uid) { | ||
return new LpaActor($this->donor, ActorType::DONOR); | ||
Check warning on line 57 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php Codecov / codecov/patchservice-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L56-L57
|
||
} | ||
|
||
return null; | ||
} | ||
|
||
private function isATrustCorporation(string $uid): ?LpaActor | ||
{ | ||
foreach ($this->trustCorporations as $tc) { | ||
if ($tc->uId === $uid) { | ||
return new LpaActor($tc, ActorType::TRUST_CORPORATION); | ||
Check warning on line 67 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php Codecov / codecov/patchservice-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L65-L67
|
||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |