Completed
Push — master ( 605cf4...2dcac2 )
by Richard
05:16
created

Invoke   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 84
Duplicated Lines 42.86 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 6
dl 36
loc 84
ccs 60
cts 60
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A visitorJumpLabels() 0 8 1
A enterMethodCall() 16 16 2
A enterFunctionCall() 20 20 3
A enterExit() 0 16 2
A enterEval() 0 8 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
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 *
5
 * Copyright (c) 2016 Richard Klees <[email protected]>
6
 *
7
 * This software is licensed under The MIT License. You should have received
8
 * a copy of the license along with the code.
9
 */
10
11
namespace Lechimp\Dicto\Rules;
12
13
use Lechimp\Dicto\Variables\Variable;
14
use Lechimp\Dicto\Indexer\ASTVisitor;
15
use Lechimp\Dicto\Indexer\Location;
16
use Lechimp\Dicto\Indexer\Insert;
17
use PhpParser\Node as N;
18
19
/**
20
 * A class of function is considered to invoke something, it that thing is invoked
21
 * in its body.
22
 */
23
class Invoke extends Relation implements ASTVisitor {
24
    /**
25
     * @inheritdoc
26
     */
27 55
    public function name() {
28 55
        return "invoke";
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34 14
    public function visitorJumpLabels() {
35
        return
36
            [ N\Expr\MethodCall::class => "enterMethodCall"
37 14
            , N\Expr\FuncCall::class => "enterFunctionCall"
38 14
            , N\Expr\Exit_::class => "enterExit"
39 14
            , N\Expr\Eval_::class => "enterEval"
40 14
            ];
41
    }
42
43 2 View Code Duplication
    public function enterMethodCall(Insert $insert, Location $location, N\Expr\MethodCall $node) {
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...
44
        // The 'name' could also be a variable like in $this->$method();
45 2
        if (is_string($node->name)) {
46 2
            $method_reference = $insert->_method_reference
47 2
                ( $node->name
48 2
                , $location->_file()
49 2
                , $location->_line()
50 2
                , $location->_column()
51 2
                );
52 2
            $this->insert_relation_into
53 2
                ( $insert
54 2
                , $location
55 2
                , $method_reference
56 2
                );
57 2
        }
58 2
    }
59
60 6 View Code Duplication
    public function enterFunctionCall(Insert $insert, Location $location, N\Expr\FuncCall $node) {
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...
61
        // Omit calls to closures, we would not be able to
62
        // analyze them anyway atm.
63
        // Omit functions in arrays, we would not be able to
64
        // analyze them anyway atm.
65 6
        if (!($node->name instanceof N\Expr\Variable ||
66 6
              $node->name instanceof N\Expr\ArrayDimFetch)) {
67 6
            $function_reference = $insert->_function_reference
68 6
                ( $node->name->parts[0]
69 6
                , $location->_file()
70 6
                , $location->_line()
71 6
                , $location->_column()
72 6
                );
73 6
            $this->insert_relation_into
74 6
                ( $insert
75 6
                , $location
76 6
                , $function_reference
77 6
                );
78 6
        }
79 6
    }
80
81 4
    public function enterExit(Insert $insert, Location $location, N\Expr\Exit_ $node) {
82 4
        if ($node->getAttribute("kind") == N\Expr\Exit_::KIND_EXIT) {
83 2
            $kind = "exit";
84 2
        }
85
        else {
86 2
            $kind = "die";
87
        }
88 4
        $exit_or_die = $insert->_language_construct
89 4
            ( $kind
90 4
            );
91 4
        $this->insert_relation_into
92 4
            ( $insert
93 4
            , $location
94 4
            , $exit_or_die
95 4
            );
96 4
    }
97
98 1
    public function enterEval(Insert $insert, Location $location, N\Expr\Eval_ $node) {
0 ignored issues
show
Unused Code introduced by
The parameter $node is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
99 1
        $eval_ = $insert->_language_construct("eval");
100 1
        $this->insert_relation_into
101 1
            ( $insert
102 1
            , $location
103 1
            , $eval_
104 1
            );
105 1
    }
106
}
107