Test Failed
Push — master ( a0eed4...bb00ac )
by Kirill
149:40
created

Backend::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL;
11
12
use Psr\Log\LoggerAwareInterface;
13
use Psr\Log\LoggerAwareTrait;
14
use Railt\Io\Readable;
15
use Railt\Reflection\Contracts\Document;
16
use Railt\Reflection\Contracts\Reflection;
17
use Railt\SDL\Backend\Generator;
18
use Railt\SDL\Backend\Validator;
19
use Railt\SDL\IR\Definition;
20
21
/**
22
 * Class Generator
23
 */
24
class Backend implements LoggerAwareInterface
25
{
26
    use LoggerAwareTrait;
27
28
    /**
29
     * @var Generator
30
     */
31
    private $generator;
32
33
    /**
34
     * @var Validator
35
     */
36
    private $validator;
37
38
    /**
39
     * Generator constructor.
40
     * @param Reflection $reflection
41
     */
42
    public function __construct(Reflection $reflection)
43
    {
44
        $this->generator = new Generator($reflection);
45
        $this->validator = new Validator();
46
    }
47
48
    /**
49
     * @param Readable $file
50
     * @param iterable|Definition[] $ir
51
     * @return Document
52
     * @throws Exception\InternalException
53
     */
54
    public function run(Readable $file, iterable $ir): Document
55
    {
56
        return $this->generator->generate($file, $this->validate($ir));
0 ignored issues
show
Documentation introduced by
$this->validate($ir) is of type object<Generator>, but the function expects a object<Railt\SDL\Backend\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
    }
58
59
    /**
60
     * @param iterable|Definition[] $ir
61
     * @return iterable|Definition[]
62
     * @throws Exception\InternalException
63
     */
64
    private function validate(iterable $ir): iterable
65
    {
66
        foreach ($ir as $definition) {
67
            yield $this->validator->validate($definition);
68
        }
69
    }
70
}
71