| Conditions | 1 |
| Paths | 1 |
| Total Lines | 131 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 111 | public function configProvider() |
||
| 112 | { |
||
| 113 | return [ |
||
| 114 | 'empty config' => [ |
||
| 115 | // $config |
||
| 116 | [], |
||
| 117 | |||
| 118 | // $requestedDataMapperEntity |
||
| 119 | 'anything', |
||
| 120 | |||
| 121 | // $expectedException |
||
| 122 | [ InvalidArgumentException::class, 'Could not find data mapper service name' ], |
||
| 123 | ], |
||
| 124 | 'no data mappers' => [ |
||
| 125 | // $config |
||
| 126 | [ |
||
| 127 | 'entity_data_mapper_map' => [], |
||
| 128 | ], |
||
| 129 | |||
| 130 | // $requestedDataMapperEntity |
||
| 131 | 'anything', |
||
| 132 | |||
| 133 | // $expectedException |
||
| 134 | InvalidArgumentException::class, |
||
| 135 | ], |
||
| 136 | 'valid data mapper config' => [ |
||
| 137 | // $config |
||
| 138 | [ |
||
| 139 | 'entity_data_mapper_map' => [ |
||
| 140 | Asset\Entity::class => 'SomeDataMapperServiceName', |
||
| 141 | ], |
||
| 142 | 'factories' => [ |
||
| 143 | 'SomeDataMapperServiceName' => function () { |
||
| 144 | $mock = $this->getMock(DataMapperInterface::class); |
||
| 145 | $mock->expects($this->any())->method('getEntityClass')->willReturn(Asset\Entity::class); |
||
| 146 | |||
| 147 | return $mock; |
||
| 148 | }, |
||
| 149 | ], |
||
| 150 | ], |
||
| 151 | |||
| 152 | // $requestedDataMapperEntity |
||
| 153 | Asset\Entity::class, |
||
| 154 | |||
| 155 | // $expectedException |
||
| 156 | null, |
||
| 157 | ], |
||
| 158 | 'inexistent service' => [ |
||
| 159 | // $config |
||
| 160 | [ |
||
| 161 | 'entity_data_mapper_map' => [ |
||
| 162 | Asset\AnotherEntity::class => 'SomeDataMapperServiceName', |
||
| 163 | ], |
||
| 164 | ], |
||
| 165 | |||
| 166 | // $requestedDataMapperEntity |
||
| 167 | Asset\Entity::class, |
||
| 168 | |||
| 169 | // $expectedException |
||
| 170 | [ InvalidArgumentException::class, 'Could not find data mapper service name'], |
||
| 171 | ], |
||
| 172 | [ |
||
| 173 | // $config |
||
| 174 | [ |
||
| 175 | 'entity_data_mapper_map' => [ |
||
| 176 | Asset\Entity::class => 'SomeDataMapperServiceName', |
||
| 177 | Asset\AnotherEntity::class => 'SomeDataMapperServiceName', |
||
| 178 | ], |
||
| 179 | 'factories' => [ |
||
| 180 | 'SomeDataMapperServiceName' => function () { |
||
| 181 | $mock = $this->getMock(DataMapperInterface::class); |
||
| 182 | $mock->expects($this->any())->method('getEntityClass')->willReturn(Asset\AnotherEntity::class); |
||
| 183 | |||
| 184 | return $mock; |
||
| 185 | }, |
||
| 186 | ], |
||
| 187 | ], |
||
| 188 | |||
| 189 | // $requestedDataMapperEntity |
||
| 190 | Asset\Entity::class, |
||
| 191 | |||
| 192 | // $expectedException |
||
| 193 | [ RuntimeException::class, 'entity class mismatch' ], |
||
| 194 | ], |
||
| 195 | [ |
||
| 196 | // $config |
||
| 197 | [ |
||
| 198 | 'entity_data_mapper_map' => [ |
||
| 199 | Asset\Entity::class => 'SomeDataMapperServiceName', |
||
| 200 | Asset\AnotherEntity::class => 'SomeDataMapperServiceName', |
||
| 201 | ], |
||
| 202 | 'factories' => [ |
||
| 203 | 'SomeDataMapperServiceName' => function () { |
||
| 204 | $mock = $this->getMock(DataMapperInterface::class); |
||
| 205 | $mock->expects($this->any())->method('getEntityClass')->willReturn(Asset\AnotherEntity::class); |
||
| 206 | |||
| 207 | return $mock; |
||
| 208 | }, |
||
| 209 | ], |
||
| 210 | ], |
||
| 211 | |||
| 212 | // $requestedDataMapperEntity |
||
| 213 | Asset\AnotherEntity::class, |
||
| 214 | |||
| 215 | // $expectedException |
||
| 216 | null, |
||
| 217 | ], |
||
| 218 | [ |
||
| 219 | // $config |
||
| 220 | [ |
||
| 221 | 'entity_data_mapper_map' => [ |
||
| 222 | SluggableInterface::class => 'SomeDataMapperServiceName', |
||
| 223 | ], |
||
| 224 | 'factories' => [ |
||
| 225 | 'SomeDataMapperServiceName' => function () { |
||
| 226 | $mock = $this->getMock(DataMapperInterface::class); |
||
| 227 | $mock->expects($this->any())->method('getEntityClass')->willReturn(Asset\Entity::class); |
||
| 228 | |||
| 229 | return $mock; |
||
| 230 | }, |
||
| 231 | ], |
||
| 232 | ], |
||
| 233 | |||
| 234 | // $requestedDataMapperEntity |
||
| 235 | SluggableInterface::class, |
||
| 236 | |||
| 237 | // $expectedException |
||
| 238 | null, |
||
| 239 | ], |
||
| 240 | ]; |
||
| 241 | } |
||
| 242 | |||
| 253 |
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.