VisibleAs::getDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\TheProperty\Be;
12
13
use Gabrieljmj\Should\Assert\TheProperty\AbstractPropertyAssert;
14
use Gabrieljmj\Should\Exception\InvalidVisibilityTypeException;
15
use Gabrieljmj\Should\Options\Visibility;
16
17
class VisibleAs extends AbstractPropertyAssert
18
{
19
    use \Gabrieljmj\Should\Assert\Traits\VisibilityAssertTrait;
20
21
    private $visibility;
22
23
    private $texts = [
24
        Visibility::AS_PUBLIC => 'public',
25
        Visibility::AS_PROTECTED => 'protected',
26
        Visibility::AS_PRIVATE => 'private'
27
    ];
28
29
    public function __construct($class, $property, $visibility)
30
    {
31
        parent::__construct($class, $property);
32
        $this->visibility = $visibility;
33
    }
34
35
    /**
36
     * Executes the assert
37
     *
38
     * @return boolean
39
     */
40
    public function execute()
41
    {
42
        $ref = new \ReflectionProperty($this->class, $this->property);
43
44
        return $this->check($ref, $this->visibility);
45
    }
46
47
    /**
48
     * Returns the assert description
49
     *
50
     * @return string
51
     */
52
    public function getDescription()
53
    {
54
        return 'Tests if the visibility of a property is the same as the determined.';
55
    }
56
57
    /**
58
     * Creates the fail message
59
     *
60
     * @return string
61
     */
62
    protected function createFailMessage()
63
    {
64
        $class = is_object($this->class) ? get_class($this->class) : $this->class;
65
        return 'The property ' . $this->property . ' of the class ' . $class . ' is not ' . $this->texts[$this->visibility];
66
    }
67
}