Passed
Push — develop ( 6b3bb3...b964e0 )
by Mikaël
01:53 queued 11s
created

AccessRestrictedElementTrait::setAccess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
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 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
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 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