MethodUtils   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
B getVisibility() 0 20 5
1
<?php
2
/*
3
 * This file is part of the Abstract builder package, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\AbstractBuilder\Utils;
11
12
use PhpParser\Node\Stmt\Class_;
13
use PhpParser\Node\Stmt\ClassMethod;
14
use RunOpenCode\AbstractBuilder\Ast\Metadata\MethodMetadata;
15
16
/**
17
 * Class MethodUtils
18
 *
19
 * @package RunOpenCode\AbstractBuilder\Utils
20
 */
21
final class MethodUtils
22
{
23
    private function __construct() { /* noop */ }
24
25
    /**
26
     * Get method visibility from AST definition of method
27
     *
28
     * @param int|ClassMethod $value
29
     * @param string $default
30
     *
31
     * @return string
32
     */
33 5
    public static function getVisibility($value, $default = MethodMetadata::PUBLIC)
34
    {
35 5
        if ($value instanceof ClassMethod) {
36 1
            $value = $value->flags;
37
        }
38
39 5
        if (($value & Class_::MODIFIER_PUBLIC) !== 0) {
40 1
            return MethodMetadata::PUBLIC;
41
        }
42
43 4
        if (($value & Class_::MODIFIER_PROTECTED) !== 0) {
44 1
            return MethodMetadata::PROTECTED;
45
        }
46
47 3
        if (($value & Class_::MODIFIER_PRIVATE) !== 0) {
48 1
            return MethodMetadata::PRIVATE;
49
        }
50
51 2
        return $default;
52
    }
53
}
54