Passed
Push — master ( b0a397...b0f745 )
by Korotkov
01:50 queued 10s
created

Interpreter::addItemToRegistry()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author  : Jagepard <[email protected]>
7
 * @license https://mit-license.org/ MIT
8
 */
9
10
namespace Behavioral\Interpreter;
11
12
class Interpreter implements InterpreterInterface
13
{
14
    /**
15
     * @var array
16
     */
17
    private $registry;
18
19
    /**
20
     * @param  ItemInterface  $item
21
     */
22
    public function addItemToRegistry(ItemInterface $item): void
23
    {
24
        $this->registry[] = $item;
25
    }
26
27
    /**
28
     * @param  string  $input
29
     */
30
    public function interpret(string $input): void
31
    {
32
        $item = null;
33
        $input = explode(" ", $input);
34
35
        foreach ($input as $value) {
36
            if (is_numeric($value)) {
37
                $item = $this->registry[$value - 1];
38
            }
39
        }
40
41
        if ($item instanceof ItemInterface) {
42
            foreach ($input as $value) {
43
                if ($value === "album") {
44
                    printf("%s ", $item->getName());
0 ignored issues
show
Bug introduced by
The method getName() does not exist on Behavioral\Interpreter\ItemInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Behavioral\Interpreter\ItemInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
                    printf("%s ", $item->/** @scrutinizer ignore-call */ getName());
Loading history...
45
                }
46
47
                if ($value === "author") {
48
                    printf("%s", $item->getAuthor());
0 ignored issues
show
Bug introduced by
The method getAuthor() does not exist on Behavioral\Interpreter\ItemInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Behavioral\Interpreter\ItemInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
                    printf("%s", $item->/** @scrutinizer ignore-call */ getAuthor());
Loading history...
49
                }
50
            }
51
52
            printf("%s", PHP_EOL);
53
        } else {
54
            throw new \InvalidArgumentException('Missing id');
55
        }
56
    }
57
}
58