| Conditions | 12 |
| Paths | 2048 |
| Total Lines | 74 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 46 |
| CRAP Score | 13.0352 |
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 |
||
| 100 | 3 | public function __sleep() |
|
| 101 | { |
||
| 102 | // This metadata is always serialized/cached. |
||
| 103 | $serialized = array( |
||
| 104 | 3 | 'fieldMappings', |
|
| 105 | 3 | 'associationMappings', |
|
| 106 | 3 | 'identifier', |
|
| 107 | 3 | 'name', |
|
| 108 | 3 | 'namespace', // TODO: REMOVE |
|
| 109 | 3 | 'db', |
|
| 110 | 3 | 'collection', |
|
| 111 | 3 | 'rootDocumentName', |
|
| 112 | 3 | 'generatorType', |
|
| 113 | 3 | 'generatorOptions', |
|
| 114 | 3 | 'idGenerator', |
|
| 115 | 3 | 'indexes', |
|
| 116 | 3 | ); |
|
| 117 | |||
| 118 | // The rest of the metadata is only serialized if necessary. |
||
| 119 | 3 | if ($this->changeTrackingPolicy != self::CHANGETRACKING_DEFERRED_IMPLICIT) { |
|
| 120 | $serialized[] = 'changeTrackingPolicy'; |
||
| 121 | } |
||
| 122 | |||
| 123 | 3 | if ($this->customRepositoryClassName) { |
|
| 124 | 1 | $serialized[] = 'customRepositoryClassName'; |
|
| 125 | 1 | } |
|
| 126 | |||
| 127 | 3 | if ($this->inheritanceType != self::INHERITANCE_TYPE_NONE) { |
|
| 128 | 1 | $serialized[] = 'inheritanceType'; |
|
| 129 | 1 | $serialized[] = 'discriminatorField'; |
|
| 130 | 1 | $serialized[] = 'discriminatorValue'; |
|
| 131 | 1 | $serialized[] = 'discriminatorMap'; |
|
| 132 | 1 | $serialized[] = 'defaultDiscriminatorValue'; |
|
| 133 | 1 | $serialized[] = 'parentClasses'; |
|
| 134 | 1 | $serialized[] = 'subClasses'; |
|
| 135 | 1 | } |
|
| 136 | |||
| 137 | 3 | if ($this->isMappedSuperclass) { |
|
| 138 | $serialized[] = 'isMappedSuperclass'; |
||
| 139 | } |
||
| 140 | |||
| 141 | 3 | if ($this->isEmbeddedDocument) { |
|
| 142 | $serialized[] = 'isEmbeddedDocument'; |
||
| 143 | } |
||
| 144 | |||
| 145 | 3 | if ($this->isVersioned) { |
|
| 146 | $serialized[] = 'isVersioned'; |
||
| 147 | $serialized[] = 'versionField'; |
||
| 148 | } |
||
| 149 | |||
| 150 | 3 | if ($this->lifecycleCallbacks) { |
|
|
|
|||
| 151 | $serialized[] = 'lifecycleCallbacks'; |
||
| 152 | } |
||
| 153 | |||
| 154 | 3 | if ($this->file) { |
|
| 155 | 1 | $serialized[] = 'file'; |
|
| 156 | 1 | } |
|
| 157 | |||
| 158 | 3 | if ($this->slaveOkay) { |
|
| 159 | 1 | $serialized[] = 'slaveOkay'; |
|
| 160 | 1 | } |
|
| 161 | |||
| 162 | 3 | if ($this->distance) { |
|
| 163 | 1 | $serialized[] = 'distance'; |
|
| 164 | 1 | } |
|
| 165 | |||
| 166 | 3 | if ($this->collectionCapped) { |
|
| 167 | 1 | $serialized[] = 'collectionCapped'; |
|
| 168 | 1 | $serialized[] = 'collectionSize'; |
|
| 169 | 1 | $serialized[] = 'collectionMax'; |
|
| 170 | 1 | } |
|
| 171 | |||
| 172 | 3 | return $serialized; |
|
| 173 | } |
||
| 174 | |||
| 207 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.