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

MethodUtils   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 31
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
B getVisibility() 0 18 5
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