Completed
Push — issue/300 ( fd6ec3 )
by Alex
01:38
created

Processor::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
4
namespace FeedIo\Check;
5
6
7
use FeedIo\Feed;
8
use FeedIo\FeedIo;
9
10
/**
11
 * Class Processor
12
 * @codeCoverageIgnore
13
 */
14
class Processor
15
{
16
17
    /**
18
     * Checks to perform
19
     *
20
     * @var array<CheckInterface>
21
     */
22
    protected $checks = [];
23
24
    /**
25
     * @var FeedIo
26
     */
27
    protected $feedIo;
28
29
    /**
30
     * @param FeedIo $feedIo
31
     */
32
    public function __construct(FeedIo $feedIo)
33
    {
34
        $this->feedIo = $feedIo;
35
    }
36
37
    /**
38
     * @param CheckInterface $check
39
     * @return $this
40
     */
41
    public function add(CheckInterface $check): Processor
42
    {
43
        $this->checks[] = $check;
44
45
        return $this;
46
    }
47
48
    /**
49
     * @param string $url
50
     * @return Result
51
     */
52
    public function run(string $url): Result
53
    {
54
        $result = new Result($url);
55
        $feed = (new Feed())->setUrl($url);
56
        try {
57
            /** @var CheckInterface $check */
58
            foreach ($this->checks as $check) {
59
                if (!$check->perform($this->feedIo, $feed, $result)) {
0 ignored issues
show
Compatibility introduced by
$feed of type object<FeedIo\FeedInterface> is not a sub-type of object<FeedIo\Feed>. It seems like you assume a concrete implementation of the interface FeedIo\FeedInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
60
                    $result->setNotAccessible();
61
                    return $result;
62
                }
63
            }
64
        } catch (\Throwable $exception) {
65
            $result->setNotAccessible();
66
            return $result;
67
        }
68
69
70
        return $result;
71
    }
72
73
}