VisibilityAssertTrait::check()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.0777
c 0
b 0
f 0
cc 6
nc 5
nop 2
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
}