| Conditions | 10 |
| Paths | 20 |
| Total Lines | 51 |
| Code Lines | 27 |
| Lines | 14 |
| Ratio | 27.45 % |
| Tests | 31 |
| CRAP Score | 10.0686 |
| Changes | 4 | ||
| 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 | $initialValues = AutoConstructReader::getPropertiesToInitialize($this); |
|
| 31 | 29 | foreach ($initialValues as $propertyName => $value) { |
|
| 32 | 29 | if ($initializeValueValidationEnabled) { |
|
| 33 | 29 | $this->assertPropertyValue($propertyName, $value); |
|
|
1 ignored issue
–
show
|
|||
| 34 | 29 | } |
|
| 35 | |||
| 36 | 29 | $this->$propertyName = $value; |
|
| 37 | |||
| 38 | 29 | View Code Duplication | if (empty($this->_collectionsItemNames['byProperty'][$propertyName])) { |
|
1 ignored issue
–
show
|
|||
| 39 | 29 | $this->updatePropertyAssociation($propertyName, array("oldValue" => null, "newValue" => $value)); |
|
|
1 ignored issue
–
show
|
|||
| 40 | 29 | } else { |
|
| 41 | 29 | foreach ($value as $newValue) { |
|
| 42 | 8 | $this->updatePropertyAssociation($propertyName, array("oldValue" => null, "newValue" => $newValue)); |
|
|
1 ignored issue
–
show
|
|||
| 43 | 29 | } |
|
| 44 | } |
||
| 45 | 29 | } |
|
| 46 | |||
| 47 | // Initialize the propeties using given arguments |
||
| 48 | 29 | $neededArguments = AutoConstructReader::getConstructArguments($this); |
|
| 49 | |||
| 50 | 29 | if ($neededArguments !== null && $properties !== null) { |
|
| 51 | 3 | $numberOfNeededArguments = count($neededArguments); |
|
| 52 | |||
| 53 | 3 | MethodCallManager::assertArgsNumber($numberOfNeededArguments, $properties); |
|
| 54 | |||
| 55 | 3 | for ($i = 0; $i < $numberOfNeededArguments; $i++) { |
|
| 56 | 3 | $property = $neededArguments[$i]; |
|
| 57 | 3 | $argument = $properties[$i]; |
|
| 58 | |||
| 59 | 3 | $this->assertPropertyValue($property, $argument); |
|
|
1 ignored issue
–
show
|
|||
| 60 | |||
| 61 | 2 | $this->$property = $argument; |
|
| 62 | |||
| 63 | // Manage associations |
||
| 64 | 2 | View Code Duplication | if (empty($this->_collectionsItemNames['byProperty'][$property])) { |
| 65 | 2 | $this->updatePropertyAssociation($property, array("oldValue" => null, "newValue" => $argument)); |
|
|
1 ignored issue
–
show
|
|||
| 66 | 2 | } else { |
|
| 67 | foreach ($argument as $value) { |
||
| 68 | $this->updatePropertyAssociation($property, array("oldValue" => null, "newValue" => $value)); |
||
|
1 ignored issue
–
show
|
|||
| 69 | } |
||
| 70 | } |
||
| 71 | 2 | } |
|
| 72 | 2 | } |
|
| 73 | 28 | } |
|
| 74 | } |
||
| 75 |
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
Idableprovides a methodequalsIdthat 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.