VisibilityTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getVisibility() 0 24 5
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Generator\Template;
5
6
use Moka\Exception\InvalidArgumentException;
7
8
/**
9
 * Trait VisibilityTrait
10
 * @package Moka\Generator\Template
11
 */
12
trait VisibilityTrait
13
{
14
    /**
15
     * @param \Reflector $reflector
16
     * @return string
17
     *
18
     * @throws InvalidArgumentException
19
     * @throws \RuntimeException
20
     */
21 14
    protected static function getVisibility(\Reflector $reflector): string
22
    {
23
        if (
24 14
            !$reflector instanceof \ReflectionMethod &&
25 14
            !$reflector instanceof \ReflectionProperty
26
        ) {
27 1
            throw new InvalidArgumentException(
28 1
                sprintf(
29 1
                    'Reflector must be an instance of "%s" or "%s", "%s" given',
30 1
                    \ReflectionMethod::class,
31 1
                    \ReflectionProperty::class,
32 1
                    \get_class($reflector)
33
                )
34
            );
35
        }
36
37 13
        foreach (['Public', 'Protected', 'Private'] as $visibility) {
38 13
            if ($reflector->{'is' . $visibility}()) {
39 12
                return strtolower($visibility);
40
            }
41
        }
42
43 1
        throw new \RuntimeException('Witness me!');
44
    }
45
}
46