GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AbstractEntry   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
c 2
b 0
f 0
lcom 2
cbo 2
dl 0
loc 138
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getId() 0 4 1
A setId() 0 6 1
A getWorkflowName() 0 4 1
A setWorkflowName() 0 6 1
A getState() 0 4 1
A setState() 0 6 1
A isInitialized() 0 4 1
A getSteps() 0 4 1
A addCurrentStep() 0 9 2
1
<?php
2
/**
3
 * @link    https://github.com/old-town/workflow-doctrine
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace OldTown\Workflow\Spi\Doctrine\Entity;
7
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\ORM\Mapping as ORM;
10
11
12
/**
13
 * Class WorkflowName
14
 *
15
 * @ORM\Entity()
16
 * @ORM\Table(name="wf_entry")
17
 * @ORM\InheritanceType(value="SINGLE_TABLE")
18
 * @ORM\DiscriminatorColumn(name="type", type="string")
19
 *
20
 * @package OldTown\Workflow\Spi\Doctrine
21
 */
22
abstract class AbstractEntry implements EntryInterface
23
{
24
    /**
25
     * @ORM\Id()
26
     * @ORM\Column(name="id", type="integer")
27
     * @ORM\GeneratedValue(strategy="IDENTITY")
28
     *
29
     * @var string
30
     */
31
    protected $id;
32
33
    /**
34
     * @ORM\Column(name="workflow_name", type="string", length=60)
35
     *
36
     *
37
     * @var string
38
     */
39
    protected $workflowName;
40
41
    /**
42
     * @ORM\Column(name="state", type="integer")
43
     *
44
     *
45
     * @var integer
46
     */
47
    protected $state;
48
49
    /**
50
     * Шаги привязанные к процессу wf
51
     *
52
     * @ORM\OneToMany(targetEntity="Step", mappedBy="entry")
53
     *
54
     * @var StepInterface
55
     */
56
    protected $steps;
57
58
    /**
59
     * AbstractEntry constructor.
60
     */
61
    public function __construct()
62
    {
63
        $this->steps = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type object<OldTown\Workflow\...e\Entity\StepInterface> of property $steps.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getId()
70
    {
71
        return $this->id;
72
    }
73
74
    /**
75
     * @param string $id
76
     *
77
     * @return $this
78
     */
79
    public function setId($id)
80
    {
81
        $this->id = (integer)$id;
0 ignored issues
show
Documentation Bug introduced by
The property $id was declared of type string, but (int) $id is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
82
83
        return $this;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getWorkflowName()
90
    {
91
        return $this->workflowName;
92
    }
93
94
    /**
95
     * @param string $workflowName
96
     *
97
     * @return $this
98
     */
99
    public function setWorkflowName($workflowName)
100
    {
101
        $this->workflowName = (string)$workflowName;
102
103
        return $this;
104
    }
105
106
    /**
107
     * @return integer
108
     */
109
    public function getState()
110
    {
111
        return $this->state;
112
    }
113
114
    /**
115
     * @param integer $state
116
     *
117
     * @return $this
118
     */
119
    public function setState($state)
120
    {
121
        $this->state = (integer)$state;
122
123
        return $this;
124
    }
125
126
    /**
127
     * Определяет иницилазирован ли процесс workflow
128
     *
129
     * @return bool
130
     */
131
    public function isInitialized()
132
    {
133
        return $this->state > 0;
134
    }
135
136
137
    /**
138
     * @return ArrayCollection|StepInterface[]
139
     */
140
    public function getSteps()
141
    {
142
        return $this->steps;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->steps; (OldTown\Workflow\Spi\Doctrine\Entity\StepInterface) is incompatible with the return type declared by the interface OldTown\Workflow\Spi\Doc...ntryInterface::getSteps of type Doctrine\Common\Collecti...\Entity\StepInterface[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
143
    }
144
145
    /**
146
     * @param StepInterface $step
147
     *
148
     * @return $this
149
     */
150
    public function addCurrentStep(StepInterface $step)
151
    {
152
        $step->setEntry($this);
153
        if (!$this->getSteps()->contains($step)) {
0 ignored issues
show
Bug introduced by
The method contains() does not seem to exist on object<OldTown\Workflow\...e\Entity\StepInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
154
            $this->getSteps()->add($step);
0 ignored issues
show
Bug introduced by
The method add() does not seem to exist on object<OldTown\Workflow\...e\Entity\StepInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
155
        }
156
157
        return $this;
158
    }
159
}
160