1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace WsdlToPhp\PhpGenerator\Element; |
||
6 | |||
7 | use InvalidArgumentException; |
||
8 | |||
9 | trait AccessRestrictedElementTrait |
||
10 | { |
||
11 | protected string $access; |
||
12 | |||
13 | 110 | public function setAccess(?string $access): AbstractElement |
|
14 | { |
||
15 | 110 | if (!static::accessIsValid($access)) { |
|
16 | 2 | throw new InvalidArgumentException(sprintf('Access "%s" is invalid, please provide one of these accesses: %s', $access, implode(', ', AccessRestrictedElementInterface::ACCESSES))); |
|
17 | } |
||
18 | 110 | $this->access = $access; |
|
19 | |||
20 | 110 | return $this; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
21 | } |
||
22 | |||
23 | 82 | public function getAccess(): string |
|
24 | { |
||
25 | 82 | return $this->access; |
|
26 | } |
||
27 | |||
28 | 110 | public static function accessIsValid(?string $access): bool |
|
29 | { |
||
30 | 110 | return '' === $access || in_array($access, AccessRestrictedElementInterface::ACCESSES, true); |
|
31 | } |
||
32 | |||
33 | 82 | protected function getPhpAccess(): string |
|
34 | { |
||
35 | 82 | return '' === $this->getAccess() ? '' : sprintf('%s ', $this->getAccess()); |
|
36 | } |
||
37 | } |
||
38 |