TheProperty::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
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\TheClass\Have;
12
13
use Gabrieljmj\Should\Assert\TheClass\AbstractClassAssert;
14
15
class TheProperty extends AbstractClassAssert
16
{
17
    /**
18
     * @var string
19
     */
20
    private $property;
21
    
22
    /**
23
     * @param string|object $class
24
     * @param string        $property
25
     */
26
    public function __construct($class, $property)
27
    {
28
        parent::__construct($class);
29
        $this->property = $property;
30
    }
31
32
    /**
33
     * Returns the assert description
34
     *
35
     * @return string
36
     */
37
    public function getDescription()
38
    {
39
        return 'Tests if a class has certain property';
40
    }
41
42
    /**
43
     * Creates the fail message
44
     *
45
     * @return string
46
     */
47
    protected function createFailMessage()
48
    {
49
        $class = is_object($this->class) ? get_class($this->class) : $this->class;
50
        return 'The class ' . $class . ' has not the property ' . $this->property;
51
    }
52
53
    /**
54
     * Executes the assert
55
     *
56
     * @return boolean
57
     */
58
    public function execute()
59
    {
60
        $ref = new \ReflectionClass($this->class);
61
        return $ref->hasProperty($this->property);
62
    }
63
}