Completed
Push — master ( b2a65d...63a169 )
by Kirill
02:18
created

Builder/Definition/ObjectDefinitionBuilder.php (1 issue)

private methods are used.

Unused Code Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Frontend\Builder\Definition;
11
12
use Railt\Parser\Ast\RuleInterface;
13
use Railt\SDL\Frontend\Builder\BaseBuilder;
14
use Railt\SDL\Frontend\Context\ContextInterface;
15
use Railt\SDL\Frontend\Deferred\DeferredInterface;
16
use Railt\SDL\Frontend\Definition\DefinitionInterface;
17
use Railt\SDL\Frontend\Definition\InvocationInterface;
18
use Railt\SDL\IR\Definition\InterfaceDefinitionValueObject;
19
use Railt\SDL\IR\Definition\ObjectDefinitionValueObject;
20
use Railt\SDL\IR\DefinitionValueObject;
21
use Railt\SDL\IR\SymbolTable\ValueInterface;
22
23
/**
24
 * Class ObjectDefinitionBuilder
25
 */
26
class ObjectDefinitionBuilder extends BaseBuilder
27
{
28
    /**
29
     * @param RuleInterface $rule
30
     * @return bool
31
     */
32
    public function match(RuleInterface $rule): bool
33
    {
34
        return $rule->getName() === 'ObjectDefinition';
35
    }
36
37
    /**
38
     * @param ContextInterface $ctx
39
     * @param RuleInterface $rule
40
     * @return mixed|\Generator|void
41
     */
42
    public function reduce(ContextInterface $ctx, RuleInterface $rule)
43
    {
44
        /** @var DeferredInterface $definition */
45
        $definition = yield $rule->first('> #TypeDefinition');
46
47
        $definition->then(function (DefinitionInterface $definition, InvocationInterface $from) {
48
            /** @var ContextInterface $local */
49
            $local = yield $definition->getLocalContext(); // Open local context
50
51
            // $message = "Call type '%s'\n - Defined in %s\n - From %s";
52
            // $message = \sprintf($message, $definition->getName(), $local, $from->getContext());
53
54
            //echo $message;die;
55
56
            //yield $definition->getContext(); // Close
57
        });
58
    }
59
60
    /**
61
     * @param ContextInterface $local
62
     * @param ObjectDefinitionValueObject $vo
63
     * @param RuleInterface $rule
64
     * @return \Generator
65
     * @throws \Railt\SDL\Exception\NotFoundException
66
     */
67
    private function loadInterfaces(
0 ignored issues
show
This method is not used, and could be removed.
Loading history...
68
        ContextInterface $local,
69
        ObjectDefinitionValueObject $vo,
70
        RuleInterface $rule
71
    ): \Generator {
72
        foreach ($rule->find('> #TypeDefinitionImplements') as $impl) {
73
            /** @var ValueInterface $result */
74
            $result = yield $impl->getChild(0);
75
76
            yield from $iterator = $this->invoke($result->getValue(), $local);
77
78
            /** @var InterfaceDefinitionValueObject $interface */
79
            $interface = $this->loadInterface($iterator->getReturn());
80
81
            $vo->implements[] = $interface->name;
82
        }
83
    }
84
85
    private function loadInterface(DefinitionValueObject $dto)
86
    {
87
        return $dto;
88
    }
89
}
90