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

TypeDefinitionNode   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 35
loc 35
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOpcodes() 10 10 2
A getOffset() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Definition;
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\ProvidesDirectiveNodes;
16
use Railt\SDL\Frontend\AST\ProvidesName;
17
use Railt\SDL\Frontend\AST\ProvidesOpcode;
18
use Railt\SDL\Frontend\AST\ProvidesType;
19
use Railt\SDL\Frontend\AST\Support\DescriptionProvider;
20
use Railt\SDL\Frontend\AST\Support\DirectivesProvider;
21
use Railt\SDL\Frontend\AST\Support\TypeNameProvider;
22
use Railt\SDL\Frontend\Context;
23
use Railt\SDL\Frontend\IR\Opcode;
24
use Railt\SDL\Frontend\IR\Opcode\DefineOpcode;
25
26
/**
27
 * Class TypeDefinitionNode
28
 */
29 View Code Duplication
abstract class TypeDefinitionNode extends Rule implements ProvidesName, ProvidesType, ProvidesDescription, ProvidesDirectiveNodes, ProvidesOpcode
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
{
31
    use TypeNameProvider;
32
    use DirectivesProvider;
33
    use DescriptionProvider;
34
35
    /**
36
     * @param Context $context
37
     * @return iterable
38
     */
39
    public function getOpcodes(Context $context): iterable
40
    {
41
        $current = $context->create();
42
43
        $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 41 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...
44
45
        if ($description = $this->getDescriptionNode()) {
46
            yield $description => new Opcode(Opcode::RL_DESCRIPTION, $joinable, $this->getDescription());
47
        }
48
    }
49
50
    /**
51
     * @return int
52
     */
53
    public function getOffset(): int
54
    {
55
        $node = $this->getTypeNameNode();
56
57
        if ($node instanceof RuleInterface) {
58
            return $node->getOffset();
59
        }
60
61
        return parent::getOffset();
62
    }
63
}
64