Test Failed
Push — master ( b7ab7b...94ee03 )
by Kirill
02:59
created

Dictionary   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 0
cts 25
cp 0
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 14 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
    public function __construct(Compiler $compiler)
36
    {
37
        $this->compiler = $compiler;
38
39
        $this->addLoggerListener();
40
    }
41
42
    /**
43
     * @return void
44
     */
45
    private function addLoggerListener(): void
46
    {
47
        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 ? \sprintf($direct, $type) : \sprintf($context, $type, $from,
53
                    $from->getFile(), $from->getLine());
54
55
                $this->logger->debug($message);
56
            }
57
        });
58
    }
59
60
    /**
61
     * @param \Closure $then
62
     */
63
    public function onTypeNotFound(\Closure $then): void
64
    {
65
        parent::onTypeNotFound(function (string $type, ?Definition $from) use ($then): void {
66
            if (($file = $then($type, $from)) instanceof Readable) {
67
                $this->compiler->compile($file);
68
            }
69
        });
70
    }
71
}
72