VisibilityAssertTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 17 6
1
<?php
2
/**
3
 * ShouldPHP
4
 *
5
 * @author  Gabriel Jacinto <[email protected]>
6
 * @status  dev
7
 * @link    https://github.com/GabrielJMJ/ShouldPHP
8
 * @license MIT
9
 */
10
11
namespace Gabrieljmj\Should\Assert\Traits;
12
13
use Gabrieljmj\Should\Options\Visibility;
14
use Gabrieljmj\Should\Exception\ShouldException;
15
16
trait VisibilityAssertTrait
17
{
18
    protected function check($ref, $visibility)
19
    {
20
        if (!$ref instanceof \ReflectionMethod && !$ref instanceof \ReflectionProperty) {
21
            throw new \InvalidArgumentException('The reflection param passed should be an instance of ReflectionMethod or RelfectionProperty');
22
        }
23
24
        switch($visibility){
25
            case Visibility::AS_PUBLIC:
26
                return $ref->isPublic();
27
            case Visibility::AS_PROTECTED:
28
                return $ref->isProtected();
29
            case Visibility::AS_PRIVATE:
30
                return $ref->isPrivate();
31
            default:
32
                ShouldException::invalidVisibilityType($visibility);
33
        }
34
    }
35
}