Conditions | 10 |
Paths | 20 |
Total Lines | 48 |
Code Lines | 25 |
Lines | 14 |
Ratio | 29.17 % |
Tests | 29 |
CRAP Score | 10.0822 |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
23 | 29 | protected function initializeProperties($properties = null) |
|
24 | { |
||
25 | 29 | $this->getPropertiesInfo(); |
|
1 ignored issue
–
show
|
|||
26 | |||
27 | // Initialize the properties that were defined using the Initialize / InitializeObject annotations |
||
28 | 29 | $initializeValueValidationEnabled = Configuration::isInitializeValuesValidationEnabled(); |
|
29 | |||
30 | 29 | foreach ($this->_initialPropertiesValues as $propertyName => $value) { |
|
1 ignored issue
–
show
|
|||
31 | 29 | if ($initializeValueValidationEnabled) { |
|
32 | 29 | $this->assertPropertyValue($propertyName, $value); |
|
1 ignored issue
–
show
|
|||
33 | 29 | } |
|
34 | |||
35 | 29 | $this->$propertyName = $value; |
|
36 | |||
37 | 29 | View Code Duplication | if (empty($this->_collectionsItemNames['byProperty'][$propertyName])) { |
1 ignored issue
–
show
|
|||
38 | 29 | $this->updatePropertyAssociation($propertyName, array("oldValue" => null, "newValue" => $value)); |
|
1 ignored issue
–
show
|
|||
39 | 29 | } else { |
|
40 | 29 | foreach ($value as $newValue) { |
|
41 | 8 | $this->updatePropertyAssociation($propertyName, array("oldValue" => null, "newValue" => $newValue)); |
|
1 ignored issue
–
show
|
|||
42 | 29 | } |
|
43 | } |
||
44 | 29 | } |
|
45 | |||
46 | // Initialize the propeties using given arguments |
||
47 | 29 | if ($this->_initializationNeededArguments !== null && $properties !== null) { |
|
48 | 3 | $numberOfNeededArguments = count($this->_initializationNeededArguments); |
|
1 ignored issue
–
show
|
|||
49 | |||
50 | 3 | MethodCallManager::assertArgsNumber($numberOfNeededArguments, $properties); |
|
51 | |||
52 | 3 | for ($i = 0; $i < $numberOfNeededArguments; $i++) { |
|
53 | 3 | $property = $this->_initializationNeededArguments[$i]; |
|
54 | 3 | $argument = $properties[$i]; |
|
55 | |||
56 | 3 | $this->assertPropertyValue($property, $argument); |
|
1 ignored issue
–
show
|
|||
57 | |||
58 | 2 | $this->$property = $argument; |
|
59 | |||
60 | // Manage associations |
||
61 | 2 | View Code Duplication | if (empty($this->_collectionsItemNames['byProperty'][$property])) { |
62 | 2 | $this->updatePropertyAssociation($property, array("oldValue" => null, "newValue" => $argument)); |
|
1 ignored issue
–
show
|
|||
63 | 2 | } else { |
|
64 | foreach ($argument as $value) { |
||
65 | $this->updatePropertyAssociation($property, array("oldValue" => null, "newValue" => $value)); |
||
1 ignored issue
–
show
|
|||
66 | } |
||
67 | } |
||
68 | 2 | } |
|
69 | 2 | } |
|
70 | 28 | } |
|
71 | } |
||
72 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.