| Conditions | 1 |
| Paths | 1 |
| Total Lines | 69 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 28 | public function definitionProvider() |
||
| 29 | { |
||
| 30 | /* test case 1 */ |
||
| 31 | $simpleDefinitionGroup = DefinitionGroup::create('Simple\\Definition\\Group'); |
||
| 32 | $simpleDefinitionGroup->event('SomethingHappened') |
||
| 33 | ->field('what', 'string', 'Example Event') |
||
| 34 | ->field('yolo', 'bool', 'true'); |
||
| 35 | |||
| 36 | /* test case 2 */ |
||
| 37 | $multipleEventsDefinitionGroup = DefinitionGroup::create('Multiple\\Events\\DefinitionGroup'); |
||
| 38 | $multipleEventsDefinitionGroup->event('FirstEvent') |
||
| 39 | ->field('firstField', 'string', 'FIRST'); |
||
| 40 | $multipleEventsDefinitionGroup->event('SecondEvent') |
||
| 41 | ->field('secondField', 'string', 'SECOND'); |
||
| 42 | |||
| 43 | /* test case 3 */ |
||
| 44 | $definitionGroupWithDefaults = DefinitionGroup::create('Group\\With\\Defaults'); |
||
| 45 | $definitionGroupWithDefaults->fieldDefault('description', 'string', 'This is a description.'); |
||
| 46 | $definitionGroupWithDefaults->event('EventWithDescription') |
||
| 47 | ->field('description'); |
||
| 48 | |||
| 49 | /* test case 4 */ |
||
| 50 | $groupWithFieldSerialization = DefinitionGroup::create('Group\\With\\FieldDeserialization'); |
||
| 51 | $groupWithFieldSerialization->fieldSerializer('items', <<<EOF |
||
| 52 | array_map(function (\$item) { |
||
| 53 | return \$item['property']; |
||
| 54 | }, {param}) |
||
| 55 | EOF |
||
| 56 | ); |
||
| 57 | $groupWithFieldSerialization->fieldDeserializer('items', <<<EOF |
||
| 58 | array_map(function (\$property) { |
||
| 59 | return ['property' => \$property]; |
||
| 60 | }, {param}) |
||
| 61 | EOF |
||
| 62 | ); |
||
| 63 | $groupWithFieldSerialization->event('WithFieldSerializers') |
||
| 64 | ->field('items', 'array'); |
||
| 65 | |||
| 66 | /* test case 5 */ |
||
| 67 | $groupWithVersionEvent = DefinitionGroup::create('With\Versioned\Event'); |
||
| 68 | $groupWithVersionEvent->event('VersionTwo') |
||
| 69 | ->atVersion(2); |
||
| 70 | |||
| 71 | $definitionGroupWithCommand = DefinitionGroup::create('With\Commands'); |
||
| 72 | $definitionGroupWithCommand->command('DoSomething') |
||
| 73 | ->field('reason', 'string', 'Because reasons.'); |
||
| 74 | |||
| 75 | /* test case 6 */ |
||
| 76 | $groupWithFieldSerializationFromEvent = DefinitionGroup::create('With\\EventFieldSerialization'); |
||
| 77 | $groupWithFieldSerializationFromEvent->event('EventName') |
||
| 78 | ->field('title', 'string', 'Title') |
||
| 79 | ->fieldSerializer('title', <<<EOF |
||
| 80 | strtoupper({param}) |
||
| 81 | EOF |
||
| 82 | )->fieldDeserializer('title', <<<EOF |
||
| 83 | strtolower({param}) |
||
| 84 | EOF |
||
| 85 | ); |
||
| 86 | |||
| 87 | return [ |
||
| 88 | [$simpleDefinitionGroup, 'simpleDefinitionGroup'], |
||
| 89 | [$multipleEventsDefinitionGroup, 'multipleEventsDefinitionGroup'], |
||
| 90 | [$definitionGroupWithDefaults, 'definitionGroupWithDefaults'], |
||
| 91 | [$groupWithFieldSerialization, 'groupWithFieldSerialization'], |
||
| 92 | [$groupWithVersionEvent, 'groupWithVersionEvent'], |
||
| 93 | [$definitionGroupWithCommand, 'definitionGroupWithCommand'], |
||
| 94 | [$groupWithFieldSerializationFromEvent, 'groupWithFieldSerializationFromEvent'], |
||
| 95 | ]; |
||
| 96 | } |
||
| 97 | } |