Completed
Pull Request — master (#8)
by Korotkov
02:51
created

Interpreter::printValue()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 5
nop 1
dl 0
loc 11
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Behavioral\Interpreter;
11
12
/**
13
 * Class Interpreter
14
 * @package Behavioral\Interpreter
15
 */
16
class Interpreter implements InterpreterInterface
17
{
18
    /**
19
     * @var Item
20
     */
21
    protected $item;
22
    /**
23
     * @var Depository
24
     */
25
    protected $depository;
26
27
    /**
28
     * Interpreter constructor.
29
     * @param Depository $depository
30
     */
31
    public function __construct(Depository $depository)
32
    {
33
        $this->depository = $depository;
34
    }
35
36
    /**
37
     * @param string $input
38
     */
39
    public function interpret(string $input): void
40
    {
41
        $input = explode(" ", $input);
42
43
        foreach ($input as $value) {
44
            if (is_numeric($value)) {
45
                $item = $this->depository->getItems()[$value - 1];
46
            }
47
        }
48
49
        foreach ($input as $value) {
50
            if ($value == "album") {
51
                printf("%s ", $item->getAlbum());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $item does not seem to be defined for all execution paths leading up to this point.
Loading history...
52
            }
53
54
            if ($value == "author") {
55
                printf("%s", $item->getAuthor());
56
            }
57
        }
58
59
        printf("%s", PHP_EOL);
60
    }
61
}
62