Completed
Pull Request — master (#37)
by Alberto
03:40
created

VisibilityTrait::getVisibility()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 5
nop 1
dl 0
loc 29
ccs 15
cts 15
cp 1
crap 6
rs 8.439
c 0
b 0
f 0
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 14
    protected static function getVisibility(\Reflector $reflector): string
19
    {
20
        if (
21 14
            !$reflector instanceof \ReflectionMethod &&
22 14
            !$reflector instanceof \ReflectionProperty
23
        ) {
24 1
            throw new InvalidArgumentException(
25 1
                sprintf(
26 1
                    'Reflector must be an instance of "%s" or "%s"',
27 1
                    \ReflectionMethod::class,
28 1
                    \ReflectionProperty::class
29
                )
30
            );
31
        }
32
33 13
        if ($reflector->isPublic()) {
34 12
            return 'public';
35
        }
36
37 2
        if ($reflector->isProtected()) {
38 1
            return 'protected';
39
        }
40
41 2
        if ($reflector->isPrivate()) {
42 1
            return 'private';
43
        }
44
45 1
        throw new \RuntimeException('Witness me!');
46
    }
47
}
48