Completed
Push — master ( cc06f5...b0a397 )
by Korotkov
02:50 queued 01:19
created

Interpreter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
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 $depository;
18
19
    /**
20
     * @param ItemInterface $item
21
     */
22
    public function addItem(ItemInterface $item): void
23
    {
24
        $this->depository[] = $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->depository[$value - 1];
38
            }
39
        }
40
41
        foreach ($input as $value) {
42
            if ($value == "album") {
43
                printf("%s ", $item->getName());
44
            }
45
46
            if ($value == "author") {
47
                printf("%s", $item->getAuthor());
48
            }
49
        }
50
51
        printf("%s", PHP_EOL);
52
    }
53
}
54