Completed
Push — develop ( cec1b5...82146f )
by Paul
02:04
created

VisibilityTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseVisibility() 0 12 4
1
<?php
2
3
namespace PhpUnitGen\Parser\NodeParserTrait;
4
5
use PhpParser\Node;
6
use PhpUnitGen\Model\PropertyInterface\VisibilityInterface;
7
8
/**
9
 * Trait VisibilityTrait.
10
 *
11
 * @author     Paul Thébaud <[email protected]>.
12
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
13
 * @license    https://opensource.org/licenses/MIT The MIT license.
14
 * @link       https://github.com/paul-thebaud/phpunit-generator
15
 * @since      Class available since Release 2.0.0.
16
 */
17
trait VisibilityTrait
18
{
19
    /**
20
     * Retrieve the visibility of a node.
21
     *
22
     * @param Node $node The node.
23
     *
24
     * @return int The visibility as an integer.
25
     */
26
    protected function parseVisibility(Node $node): int
27
    {
28
        if (! method_exists($node, 'isPrivate')) {
29
            return VisibilityInterface::UNKNOWN;
0 ignored issues
show
Bug Best Practice introduced by
The expression return PhpUnitGen\Model\...ilityInterface::UNKNOWN returns the type null which is incompatible with the type-hinted return integer.
Loading history...
30
        }
31
        if ($node->isPrivate()) {
32
            return VisibilityInterface::PRIVATE;
33
        }
34
        if ($node->isProtected()) {
0 ignored issues
show
Bug introduced by
The method isProtected() does not exist on PhpParser\Node. It seems like you code against a sub-type of PhpParser\Node such as PhpParser\Node\Stmt\Property or PhpParser\Node\Stmt\ClassMethod or PhpParser\Node\Stmt\ClassConst or PhpParser\Node\Stmt\ClassMethod. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        if ($node->/** @scrutinizer ignore-call */ isProtected()) {
Loading history...
35
            return VisibilityInterface::PROTECTED;
36
        }
37
        return VisibilityInterface::PUBLIC;
38
    }
39
}
40