Completed
Push — master ( 7db57b...89e945 )
by Nikolas
04:32
created

GenericObjectAction   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 28.85 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 7
Bugs 0 Features 2
Metric Value
wmc 8
c 7
b 0
f 2
lcom 2
cbo 2
dl 15
loc 52
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 1
A generic() 0 3 1
A executeWith() 0 3 1
A execute() 0 3 1
A caption() 0 3 1
A description() 0 3 1
A parameters() 0 3 1
A fill() 0 3 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
namespace rtens\domin\reflection;
3
4
use rtens\domin\reflection\types\TypeFactory;
5
6
class GenericObjectAction extends ObjectAction {
7
8
    /** @var callable */
9
    private $execute;
10
11
    /** @var GenericAction */
12
    private $generic;
13
14 View Code Duplication
    public function __construct($class, TypeFactory $types, CommentParser $parser, callable $execute) {
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...
15
        parent::__construct($class, $types, $parser);
16
        $this->execute = $execute;
17
        $this->generic = new GenericAction($this);
18
        $this->generic
19
            ->setCaption(parent::caption())
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (caption() instead of __construct()). Are you sure this is correct? If so, you might want to change this to $this->caption().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
20
            ->setDescription(parent::description())
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (description() instead of __construct()). Are you sure this is correct? If so, you might want to change this to $this->description().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
21
            ->setParameters(parent::parameters())
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (parameters() instead of __construct()). Are you sure this is correct? If so, you might want to change this to $this->parameters().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
22
            ->setExecute(function ($parameters) {
23
                return parent::execute($parameters);
24
            })
25
            ->setFill(function ($parameters) {
26
                return $parameters;
27
            });
28
    }
29
30
    public function generic() {
31
        return $this->generic;
32
    }
33
34
    protected function executeWith($object) {
35
        return call_user_func($this->execute, $object);
36
    }
37
38
    public function execute(array $parameters) {
39
        return $this->generic->execute($parameters);
40
    }
41
42
    public function caption() {
43
        return $this->generic->caption();
44
    }
45
46
    public function description() {
47
        return $this->generic->description();
48
    }
49
50
    public function parameters() {
51
        return $this->generic->parameters();
52
    }
53
54
    public function fill(array $parameters) {
55
        return $this->generic->fill(parent::fill($parameters));
56
    }
57
}