Completed
Push — master ( c1a156...8cadde )
by Kirill
08:14
created

Dictionary   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 36.84%

Importance

Changes 0
Metric Value
dl 0
loc 51
ccs 7
cts 19
cp 0.3684
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addLoggerListener() 0 15 3
A onTypeNotFound() 0 8 2
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Compiler;
11
12
use Psr\Log\LoggerAwareInterface;
13
use Psr\Log\LoggerAwareTrait;
14
use Railt\Io\Readable;
15
use Railt\Reflection\Contracts\Definition;
16
use Railt\Reflection\Dictionary\CallbackDictionary;
17
use Railt\SDL\Compiler;
18
19
/**
20
 * Class Dictionary
21
 */
22
class Dictionary extends CallbackDictionary implements LoggerAwareInterface
23
{
24
    use LoggerAwareTrait;
25
26
    /**
27
     * @var Compiler
28
     */
29
    private $compiler;
30
31
    /**
32
     * Dictionary constructor.
33
     * @param Compiler $compiler
34
     */
35 119
    public function __construct(Compiler $compiler)
36
    {
37 119
        $this->compiler = $compiler;
38
39 119
        $this->addLoggerListener();
40 119
    }
41
42
    /**
43
     * @return void
44
     */
45
    private function addLoggerListener(): void
46
    {
47 119
        parent::onTypeNotFound(function (string $type, ?Definition $from): void {
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (onTypeNotFound() instead of addLoggerListener()). Are you sure this is correct? If so, you might want to change this to $this->onTypeNotFound().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
48
            if ($this->logger) {
49
                $direct = 'Try to load type %s from direct method executing';
50
                $context = 'Try to load type %s from %s (%s:%d)';
51
52
                $message = $from === null
53
                    ? \sprintf($direct, $type)
54
                    : \sprintf($context, $type, $from, $from->getFile(), $from->getLine());
55
56
                $this->logger->debug($message);
57
            }
58 119
        });
59 119
    }
60
61
    /**
62
     * @param \Closure $then
63
     */
64
    public function onTypeNotFound(\Closure $then): void
65
    {
66
        parent::onTypeNotFound(function (string $type, ?Definition $from) use ($then): void {
67
            if (($file = $then($type, $from)) instanceof Readable) {
68
                $this->compiler->compile($file);
69
            }
70
        });
71
    }
72
}
73