Completed
Push — master ( 9e738d...c82206 )
by Korotkov
02:43 queued 01:18
created

Interpreter::interpret()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 6
b 0
f 0
nc 3
nop 1
dl 0
loc 8
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;
0 ignored issues
show
Unused Code introduced by
The assignment to $item is dead and can be removed.
Loading history...
33
        $input = explode(" ", $input);
34
35
        foreach ($input as $value) {
36
            if (is_numeric($value)) {
37
                $this->getDataFromRegistry($input, $this->registry[$value - 1]);
38
            }
39
        }
40
    }
41
42
    /**
43
     * @param  array  $input
44
     * @param $item
45
     */
46
    private function getDataFromRegistry(array $input, ItemInterface $item): void
47
    {
48
        foreach ($input as $value) {
49
            if ($value === "album") {
50
                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

50
                printf("%s ", $item->/** @scrutinizer ignore-call */ getName());
Loading history...
51
            }
52
53
            if ($value === "author") {
54
                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

54
                printf("%s", $item->/** @scrutinizer ignore-call */ getAuthor());
Loading history...
55
            }
56
        }
57
58
        printf("%s", PHP_EOL);
59
    }
60
}
61