Test Failed
Push — master ( e081e8...a6938b )
by Kirill
02:31
created

FieldDefinitionNode   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 30.77 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 8
loc 26
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 4 1
A getOpcodes() 8 8 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\Dependent;
11
12
use Railt\Reflection\Contracts\TypeInterface;
13
use Railt\Reflection\Type;
14
use Railt\SDL\Frontend\AST\ProvidesArgumentNodes;
15
use Railt\SDL\Frontend\AST\ProvidesTypeHint;
16
use Railt\SDL\Frontend\AST\Support\ArgumentsProvider;
17
use Railt\SDL\Frontend\AST\Support\TypeHintProvider;
18
use Railt\SDL\Frontend\Context;
19
use Railt\SDL\Frontend\IR\Opcode\AddDefinitionOpcode;
20
use Railt\SDL\Frontend\IR\OpcodeInterface;
21
22
/**
23
 * Class FieldDefinitionNode
24
 */
25
class FieldDefinitionNode extends DependentTypeDefinitionNode implements ProvidesArgumentNodes, ProvidesTypeHint
26
{
27
    use ArgumentsProvider;
28
    use TypeHintProvider;
29
30
    /**
31
     * @return TypeInterface
32
     */
33
    public function getType(): TypeInterface
34
    {
35
        return Type::of(Type::FIELD);
36
    }
37
38
    /**
39
     * @param Context $context
40
     * @return iterable
41
     */
42 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...
43
    {
44
        yield from \iterator_each(parent::getOpcodes($context), function($result) {
0 ignored issues
show
Documentation introduced by
parent::getOpcodes($context) is of type object<Generator>, but the function expects a object<iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
            if ($result instanceof AddDefinitionOpcode) {
46
                $result->rebind(OpcodeInterface::RL_ADD_FIELD);
47
            }
48
        });
49
    }
50
}
51