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

AccessRestrictedElementTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 9
c 2
b 0
f 1
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAccess() 0 3 1
A setAccess() 0 8 2
A getPhpAccess() 0 3 2
A accessIsValid() 0 3 2
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