Completed
Push — master ( c82206...61b4b1 )
by Korotkov
03:12 queued 01:47
created

Interpreter::addAlbumToRegistry()   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
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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  AlbumInterface  $item
21
     */
22
    public function addAlbumToRegistry(AlbumInterface $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, AlbumInterface $item): void
47
    {
48
        foreach ($input as $value) {
49
            if ($value === "album") {
50
                printf("%s ", $item->getName());
51
            }
52
53
            if ($value === "author") {
54
                printf("%s", $item->getAuthor());
55
            }
56
        }
57
58
        printf("%s", PHP_EOL);
59
    }
60
}
61