Passed
Push — master ( 375c2c...1647ec )
by Korotkov
07:42 queued 13s
created

Interpreter::getDataFromRegistry()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
c 0
b 0
f 0
nc 5
nop 2
dl 0
loc 15
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
    private array $registryData;
15
16
    public function __construct(RegistryInterface $registry)
17
    {
18
        $this->registryData = $registry->getData();
19
    }
20
21
    public function interpret(string $input): string
22
    {
23
        $num    = 0;
24
        $output = [];
25
26
        if (preg_match('~[0-9]+~', $input, $match)) {
27
            $num = $match[0] - 1;
28
        }
29
30
        if (preg_match('~author~', $input)) {
31
            $output[] = $this->registryData[$num]->getAuthor();
32
        }
33
34
        if (preg_match('~album~', $input)) {
35
            $output[] = $this->registryData[$num]->getAlbum();
36
        }
37
38
        return implode(' ', $output) . "\n";
39
    }
40
}
41