Lines
100.00%
3 / 3
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AgentStatVoter | 100.00% | 3 / 3 | 100.00% | 2 / 2 | 4 | 100.00% | 1 / 1 | |||
| supports | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | |||||
| voteOnAttribute | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace App\Security\Voter; | |
| 6 | ||
| 7 | use App\Entity\AgentStat; | |
| 8 | use App\Entity\User; | |
| 9 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | |
| 10 | use Symfony\Component\Security\Core\Authorization\Voter\Vote; | |
| 11 | use Symfony\Component\Security\Core\Authorization\Voter\Voter; | |
| 12 | ||
| 13 | /** | |
| 14 | * @extends Voter<string, AgentStat> | |
| 15 | */ | |
| 16 | final class AgentStatVoter extends Voter | |
| 17 | { | |
| 18 | public const string VIEW = 'AGENT_STAT_VIEW'; | |
| 19 | ||
| 20 | #[\Override] | |
| 21 | protected function supports(string $attribute, mixed $subject): bool | |
| 22 | { | |
| 23 | return self::VIEW === $attribute && $subject instanceof AgentStat; | |
| 24 | } | |
| 25 | ||
| 26 | #[\Override] | |
| 27 | protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token, ?Vote $vote = null): bool | |
| 28 | { | |
| 29 | $user = $token->getUser(); | |
| 30 | ||
| 31 | return $user instanceof User && $subject->owner->id === $user->id; | |
| 32 | } | |
| 33 | } |