Completed
Push — master ( 556a60...b1e8a1 )
by Nikola
02:34
created

MethodUtils::getVisibility()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 15
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 5
nop 2
crap 30
1
<?php
2
3
namespace RunOpenCode\AbstractBuilder\Utils;
4
5
use PhpParser\Node\Stmt\Class_;
6
use RunOpenCode\AbstractBuilder\Ast\Metadata\MethodMetadata;
7
8
final class MethodUtils
9
{
10
    private function __construct() { /* noop */ }
11
12
    /**
13
     * Get method visibility from AST definition
14
     *
15
     * @param int $value
16
     * @param string $default
17
     *
18
     * @return string
19
     */
20
    public static function getVisibility($value, $default = MethodMetadata::PUBLIC)
21
    {
22
        if (($value & Class_::MODIFIER_PUBLIC) !== 0) {
23
            return MethodMetadata::PUBLIC;
24
        }
25
26
        if (($value & Class_::MODIFIER_PROTECTED) !== 0) {
27
            return MethodMetadata::PROTECTED;
28
        }
29
30
        if (($value & Class_::MODIFIER_PRIVATE) !== 0) {
31
            return MethodMetadata::PRIVATE;
32
        }
33
34
        if (null === $value) {
35
            return $default;
36
        }
37
    }
38
}
39