AbstractInspection::addIssue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Freshcells\StateInspector\Inspection;
4
5
use Freshcells\StateInspector\Exception\StateInspectorException;
6
use Freshcells\StateInspector\Issue\Issue;
7
use Freshcells\StateInspector\Issue\IssueInterface;
8
9
/**
10
 * Class AbstractInspection
11
 * @package Freshcells\StateInspector\Inspection
12
 */
13
abstract class AbstractInspection implements InspectionInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    private $issues = [];
19
20
    /**
21
     * @param $object
22
     * @return bool
23
     */
24
    abstract public function inspect($object):bool;
25
26
    /**
27
     * @param mixed $object
28
     * @return bool
29
     */
30
    abstract public function supports($object):bool;
31
32
    /**
33
     *
34
     */
35 2
    public function success()
36
    {
37
        // hooray i could celebrate now
38 2
    }
39
40
    /**
41
     * you probably want to override this
42
     * @throws StateInspectorException
43
     */
44
    public function failure()
45
    {
46
        $issue = new Issue(
47
            'Something is not right in the State of Denmark',
48
            'You probably want to override this method',
49
            'This would be the solution'
50
        );
51
        $this->addIssue($issue);
52
        throw new StateInspectorException($issue);
53
    }
54
55
    /**
56
     * @param IssueInterface $issue
57
     */
58 2
    public function addIssue(IssueInterface $issue)
59
    {
60 2
        $this->issues[] = $issue;
61 2
    }
62
63
    /**
64
     * @return IssueInterface[]
65
     */
66 3
    public function getIssues():array
67
    {
68 3
        return $this->issues;
69
    }
70
}
71