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

DirectiveInvocationNode   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 32 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
dl 8
loc 25
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOpcodes() 8 8 1
A getType() 0 4 1

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\Invocation;
11
12
use Railt\Parser\Ast\Rule;
13
use Railt\Reflection\Contracts\TypeInterface;
14
use Railt\Reflection\Type;
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\TypeNameProvider;
19
use Railt\SDL\Frontend\Context;
20
use Railt\SDL\Frontend\IR\Opcode;
21
use Railt\SDL\Frontend\IR\Opcode\CallOpcode;
22
use Railt\SDL\Frontend\IR\Opcode\CompareOpcode;
23
use Railt\SDL\Frontend\IR\Opcode\FetchOpcode;
24
25
/**
26
 * Class DirectiveInvocationNode
27
 */
28
class DirectiveInvocationNode extends Rule implements ProvidesType, ProvidesName, ProvidesOpcode
29
{
30
    use TypeNameProvider;
31
32
    /**
33
     * @param Context $context
34
     * @return iterable
35
     */
36 View Code Duplication
    public function getOpcodes(Context $context): iterable
0 ignored issues
show
Duplication introduced by
This method 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...
37
    {
38
        $current = $context->create();
39
40
        $fetched = yield new FetchOpcode($this->getFullName(), $current, false);
0 ignored issues
show
Bug introduced by
It seems like $current defined by $context->create() on line 38 can also be of type object<Railt\SDL\Frontend\IR\JoinableOpcode>; however, Railt\SDL\Frontend\IR\Op...chOpcode::__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...
41
        yield new CompareOpcode($fetched, $this->getType());
42
        yield new CallOpcode($fetched);
43
    }
44
45
    /**
46
     * @return TypeInterface
47
     */
48
    public function getType(): TypeInterface
49
    {
50
        return Type::of(Type::DIRECTIVE);
51
    }
52
}
53