TheMethod   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDescription() 0 4 1
A createFailMessage() 0 5 1
A execute() 0 5 1
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 TheMethod extends AbstractClassAssert
16
{
17
    /**
18
     * @var string
19
     */
20
    private $method;
21
    
22
    /**
23
     * @param string|object $class
24
     * @param string        $method
25
     */
26
    public function __construct($class, $method)
27
    {
28
        parent::__construct($class);
29
        $this->method = $method;
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 method';
40
    }
41
42
    /**
43
     * Creates the fail message
44
     *
45
     * @return string
46
     */
47
    protected function createFailMessage()
48
    {
49
        $class = $this->classToStr($this->class);
50
        return 'The class ' . $class . ' has not the method ' . $this->method;
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->hasMethod($this->method);
62
    }
63
}