Test Failed
Push — master ( 2d53c5...8b1ae1 )
by Kirill
02:39
created

DependentTypeDefinitionNode::getOpcodes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
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\AST\Dependent;
11
12
use Railt\Parser\Ast\Rule;
13
use Railt\Parser\Ast\RuleInterface;
14
use Railt\SDL\Frontend\AST\ProvidesDescription;
15
use Railt\SDL\Frontend\AST\ProvidesName;
16
use Railt\SDL\Frontend\AST\ProvidesOpcode;
17
use Railt\SDL\Frontend\AST\ProvidesType;
18
use Railt\SDL\Frontend\AST\Support\DependentNameProvider;
19
use Railt\SDL\Frontend\AST\Support\DescriptionProvider;
20
use Railt\SDL\Frontend\Context;
21
use Railt\SDL\Frontend\IR\Opcode;
22
use Railt\SDL\Frontend\IR\Opcode\DefineOpcode;
23
use Railt\SDL\Frontend\IR\OpcodeHeap;
24
use Railt\SDL\Frontend\IR\OpcodeInterface;
25
26
/**
27
 * Class DependentTypeDefinitionNode
28
 */
29 View Code Duplication
abstract class DependentTypeDefinitionNode extends Rule implements
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    ProvidesType,
31
    ProvidesName,
32
    ProvidesOpcode,
33
    ProvidesDescription
34
{
35
    use DependentNameProvider;
36
    use DescriptionProvider;
37
38
    /**
39
     * @return int
40
     */
41
    public function getOffset(): int
42
    {
43
        $node = $this->getNameNode();
44
45
        if ($node instanceof RuleInterface) {
46
            return $node->getOffset();
47
        }
48
49
        return parent::getOffset();
50
    }
51
52
    /**
53
     * @param Context $context
54
     * @return iterable
55
     */
56
    public function getOpcodes(Context $context): iterable
57
    {
58
        $current = $context->create();
59
60
        $joinable = yield new DefineOpcode($this->getFullName(), $this->getType(), $current);
0 ignored issues
show
Bug introduced by
It seems like $current defined by $context->create() on line 58 can also be of type object<Railt\SDL\Frontend\IR\JoinableOpcode>; however, Railt\SDL\Frontend\IR\Op...neOpcode::__construct() does only seem to accept null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
61
62
        if ($description = $this->getDescriptionNode()) {
63
            yield $description => new Opcode(Opcode::RL_DESCRIPTION, $joinable, $this->getDescription());
64
        }
65
    }
66
}
67