| Conditions | 14 |
| Paths | 1152 |
| Total Lines | 144 |
| Code Lines | 96 |
| Lines | 0 |
| Ratio | 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 |
||
| 173 | public function testAssemble(array $configuration, array $transitionDefinition) |
||
| 174 | { |
||
| 175 | $steps = array( |
||
| 176 | 'step' => $this->createStep() |
||
| 177 | ); |
||
| 178 | |||
| 179 | $attributes = array( |
||
| 180 | 'attribute' => $this->createAttribute() |
||
| 181 | ); |
||
| 182 | |||
| 183 | $expectedCondition = null; |
||
| 184 | $expectedPreCondition = $this->createCondition(); |
||
| 185 | $expectedAction = null; |
||
| 186 | $defaultAclPrecondition = array(); |
||
| 187 | $preConditions = array(); |
||
| 188 | |||
| 189 | if (isset($configuration['acl_resource'])) { |
||
| 190 | $defaultAclPrecondition = array( |
||
| 191 | '@acl_granted' => array( |
||
| 192 | 'parameters' => array($configuration['acl_resource']) |
||
| 193 | ) |
||
| 194 | ); |
||
| 195 | |||
| 196 | if (isset($configuration['acl_message'])) { |
||
| 197 | $defaultAclPrecondition['@acl_granted']['message'] = $configuration['acl_message']; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | if (isset($transitionDefinition['pre_conditions']) && $defaultAclPrecondition) { |
||
|
|
|||
| 202 | $preConditions = array( |
||
| 203 | '@and' => array( |
||
| 204 | $defaultAclPrecondition, |
||
| 205 | $transitionDefinition['pre_conditions'] |
||
| 206 | ) |
||
| 207 | ); |
||
| 208 | } elseif (isset($transitionDefinition['pre_conditions'])) { |
||
| 209 | $preConditions = $transitionDefinition['pre_conditions']; |
||
| 210 | } |
||
| 211 | |||
| 212 | $count = 0; |
||
| 213 | |||
| 214 | if ($preConditions) { |
||
| 215 | $this->conditionFactory->expects($this->at($count)) |
||
| 216 | ->method('create') |
||
| 217 | ->with(ConfigurableCondition::ALIAS, $preConditions) |
||
| 218 | ->will($this->returnValue($expectedPreCondition)); |
||
| 219 | $count++; |
||
| 220 | } |
||
| 221 | |||
| 222 | if (array_key_exists('conditions', $transitionDefinition)) { |
||
| 223 | $expectedCondition = $this->createCondition(); |
||
| 224 | $this->conditionFactory->expects($this->at($count)) |
||
| 225 | ->method('create') |
||
| 226 | ->with(ConfigurableCondition::ALIAS, $transitionDefinition['conditions']) |
||
| 227 | ->will($this->returnValue($expectedCondition)); |
||
| 228 | } |
||
| 229 | |||
| 230 | $actionFactoryCallCount = 0; |
||
| 231 | |||
| 232 | if (array_key_exists('post_actions', $transitionDefinition)) { |
||
| 233 | $actionFactoryCallCount++; |
||
| 234 | } |
||
| 235 | |||
| 236 | if (array_key_exists('init_actions', $transitionDefinition)) { |
||
| 237 | $actionFactoryCallCount++; |
||
| 238 | } |
||
| 239 | |||
| 240 | if ($actionFactoryCallCount) { |
||
| 241 | $expectedAction = $this->createAction(); |
||
| 242 | $this->actionFactory->expects($this->exactly($actionFactoryCallCount)) |
||
| 243 | ->method('create') |
||
| 244 | ->with(ConfigurableAction::ALIAS, $transitionDefinition['post_actions']) |
||
| 245 | ->will($this->returnValue($this->createAction())); |
||
| 246 | } |
||
| 247 | |||
| 248 | $this->formOptionsAssembler->expects($this->once()) |
||
| 249 | ->method('assemble') |
||
| 250 | ->with( |
||
| 251 | isset($configuration['form_options']) ? $configuration['form_options'] : array(), |
||
| 252 | $attributes, |
||
| 253 | 'transition', |
||
| 254 | 'test' |
||
| 255 | ) |
||
| 256 | ->will($this->returnArgument(0)); |
||
| 257 | |||
| 258 | $transitions = $this->assembler->assemble( |
||
| 259 | array('test' => $configuration), |
||
| 260 | $this->transitionDefinitions, |
||
| 261 | $steps, |
||
| 262 | $attributes |
||
| 263 | ); |
||
| 264 | |||
| 265 | $configuration = array_merge( |
||
| 266 | array( |
||
| 267 | 'is_start' => false, |
||
| 268 | 'form_type' => WorkflowTransitionType::NAME, |
||
| 269 | 'form_options' => array(), |
||
| 270 | 'frontend_options' => array(), |
||
| 271 | ), |
||
| 272 | $configuration |
||
| 273 | ); |
||
| 274 | |||
| 275 | $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $transitions); |
||
| 276 | $this->assertCount(1, $transitions); |
||
| 277 | $this->assertTrue($transitions->containsKey('test')); |
||
| 278 | |||
| 279 | /** @var Transition $actualTransition */ |
||
| 280 | $actualTransition = $transitions->get('test'); |
||
| 281 | $this->assertEquals('test', $actualTransition->getName(), 'Incorrect name'); |
||
| 282 | $this->assertEquals($steps['step'], $actualTransition->getStepTo(), 'Incorrect step_to'); |
||
| 283 | $this->assertEquals($configuration['label'], $actualTransition->getLabel(), 'Incorrect label'); |
||
| 284 | |||
| 285 | $expectedDisplayType = WorkflowConfiguration::DEFAULT_TRANSITION_DISPLAY_TYPE; |
||
| 286 | |||
| 287 | if (isset($configuration['display_type'])) { |
||
| 288 | $expectedDisplayType = $configuration['display_type']; |
||
| 289 | } |
||
| 290 | |||
| 291 | $this->assertEquals($expectedDisplayType, $actualTransition->getDisplayType(), 'Incorrect display type'); |
||
| 292 | $this->assertEquals( |
||
| 293 | $configuration['frontend_options'], |
||
| 294 | $actualTransition->getFrontendOptions(), |
||
| 295 | 'Incorrect frontend_options' |
||
| 296 | ); |
||
| 297 | $this->assertEquals($configuration['is_start'], $actualTransition->isStart(), 'Incorrect is_start'); |
||
| 298 | $this->assertEquals($configuration['form_type'], $actualTransition->getFormType(), 'Incorrect form_type'); |
||
| 299 | $this->assertEquals( |
||
| 300 | $configuration['form_options'], |
||
| 301 | $actualTransition->getFormOptions(), |
||
| 302 | 'Incorrect form_options' |
||
| 303 | ); |
||
| 304 | |||
| 305 | $this->assertTemplate('page', $configuration, $actualTransition); |
||
| 306 | $this->assertTemplate('dialog', $configuration, $actualTransition); |
||
| 307 | |||
| 308 | if ($preConditions) { |
||
| 309 | $this->assertEquals($expectedPreCondition, $actualTransition->getPreCondition(), 'Incorrect Precondition'); |
||
| 310 | } else { |
||
| 311 | $this->assertNull($actualTransition->getPreCondition(), 'Incorrect Precondition'); |
||
| 312 | } |
||
| 313 | |||
| 314 | $this->assertEquals($expectedCondition, $actualTransition->getCondition(), 'Incorrect condition'); |
||
| 315 | $this->assertEquals($expectedAction, $actualTransition->getPostAction(), 'Incorrect post_action'); |
||
| 316 | } |
||
| 317 | |||
| 420 |
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.