Completed
Push — master ( 631b00...2fe979 )
by Alex
01:43
created

Processor::__construct()   A

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 1
1
<?php declare(strict_types=1);
2
3
4
namespace FeedIo\Check;
5
6
use FeedIo\Feed;
7
use FeedIo\FeedIo;
8
9
/**
10
 * Class Processor
11
 * @codeCoverageIgnore
12
 */
13
class Processor
14
{
15
16
    /**
17
     * Checks to perform
18
     *
19
     * @var array<CheckInterface>
20
     */
21
    protected $checks = [];
22
23
    /**
24
     * @var FeedIo
25
     */
26
    protected $feedIo;
27
28
    /**
29
     * @param FeedIo $feedIo
30
     */
31
    public function __construct(FeedIo $feedIo)
32
    {
33
        $this->feedIo = $feedIo;
34
    }
35
36
    /**
37
     * @param CheckInterface $check
38
     * @return $this
39
     */
40
    public function add(CheckInterface $check): Processor
41
    {
42
        $this->checks[] = $check;
43
44
        return $this;
45
    }
46
47
    /**
48
     * @param string $url
49
     * @return Result
50
     */
51
    public function run(string $url): Result
52
    {
53
        $result = new Result($url);
54
        $feed = (new Feed())->setUrl($url);
55
        try {
56
            /** @var CheckInterface $check */
57
            foreach ($this->checks as $check) {
58
                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...
59
                    $result->setNotAccessible();
60
                    return $result;
61
                }
62
            }
63
        } catch (\Throwable $exception) {
64
            $result->setNotAccessible();
65
            return $result;
66
        }
67
68
69
        return $result;
70
    }
71
}
72