Passed
Push — feature/issue-11 ( b7a9d0 )
by Mikaël
03:18
created

AccessRestrictedElementTrait::getAccesses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 1
b 0
f 1
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 108
    public function setAccess(?string $access): AbstractElement
14
    {
15 108
        if (!static::accessIsValid($access)) {
16 2
            throw new InvalidArgumentException(sprintf('Access "%s" is invalid, please provide one of these accesses: %s', $access, implode(', ', self::getAccesses())));
17
        }
18 108
        $this->access = $access;
19
20 108
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type WsdlToPhp\PhpGenerator\E...sRestrictedElementTrait which is incompatible with the type-hinted return WsdlToPhp\PhpGenerator\Element\AbstractElement.
Loading history...
21
    }
22
23 80
    public function getAccess(): string
24
    {
25 80
        return $this->access;
26
    }
27
28 108
    public static function getAccesses(): array
29
    {
30 54
        return [
31 54
            AccessRestrictedElementInterface::ACCESS_PRIVATE,
32
            AccessRestrictedElementInterface::ACCESS_PROTECTED,
33 40
            AccessRestrictedElementInterface::ACCESS_PUBLIC,
34
        ];
35 40
    }
36
37 54
    public static function accessIsValid(?string $access): bool
38
    {
39 54
        return null === $access || in_array($access, self::getAccesses(), true);
40
    }
41
42 40
    protected function getPhpAccess(): string
43
    {
44 40
        return null === $this->getAccess() ? '' : sprintf('%s ', $this->getAccess());
0 ignored issues
show
introduced by
The condition null === $this->getAccess() is always false.
Loading history...
45
    }
46
}
47