Conditions | 1 |
Paths | 1 |
Total Lines | 82 |
Code Lines | 55 |
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 |
||
46 | function it_converts_an_array_to_grid_definition(EventDispatcherInterface $eventDispatcher) |
||
47 | { |
||
48 | $grid = Grid::fromCodeAndDriverConfiguration( |
||
49 | 'sylius_admin_tax_category', |
||
50 | 'doctrine/orm', |
||
51 | ['resource' => 'sylius.tax_category'] |
||
52 | ); |
||
53 | |||
54 | $grid->setSorting(['code' => 'desc']); |
||
55 | |||
56 | $grid->setLimits([9, 18]); |
||
57 | |||
58 | $codeField = Field::fromNameAndType('code', 'string'); |
||
59 | $codeField->setLabel('System Code'); |
||
60 | $codeField->setPath('method.code'); |
||
61 | $codeField->setOptions(['template' => 'bar.html.twig']); |
||
62 | $codeField->setSortable('code'); |
||
63 | |||
64 | $grid->addField($codeField); |
||
65 | |||
66 | $viewAction = Action::fromNameAndType('view', 'link'); |
||
67 | $viewAction->setLabel('Display Tax Category'); |
||
68 | $viewAction->setOptions(['foo' => 'bar']); |
||
69 | $defaultActionGroup = ActionGroup::named('default'); |
||
70 | $defaultActionGroup->addAction($viewAction); |
||
71 | |||
72 | $grid->addActionGroup($defaultActionGroup); |
||
73 | |||
74 | $filter = Filter::fromNameAndType('enabled', 'boolean'); |
||
75 | $filter->setOptions(['fields' => ['firstName', 'lastName']]); |
||
76 | $filter->setCriteria('true'); |
||
77 | $grid->addFilter($filter); |
||
78 | |||
79 | $eventDispatcher |
||
80 | ->dispatch('sylius.grid.admin_tax_category', Argument::type(GridDefinitionConverterEvent::class)) |
||
81 | ->shouldBeCalled() |
||
82 | ; |
||
83 | |||
84 | $definitionArray = [ |
||
85 | 'driver' => [ |
||
86 | 'name' => 'doctrine/orm', |
||
87 | 'options' => ['resource' => 'sylius.tax_category'], |
||
88 | ], |
||
89 | 'sorting' => [ |
||
90 | 'code' => 'desc', |
||
91 | ], |
||
92 | 'limits' => [9, 18], |
||
93 | 'fields' => [ |
||
94 | 'code' => [ |
||
95 | 'type' => 'string', |
||
96 | 'label' => 'System Code', |
||
97 | 'path' => 'method.code', |
||
98 | 'sortable' => 'code', |
||
99 | 'options' => [ |
||
100 | 'template' => 'bar.html.twig' |
||
101 | ], |
||
102 | ], |
||
103 | ], |
||
104 | 'filters' => [ |
||
105 | 'enabled' => [ |
||
106 | 'type' => 'boolean', |
||
107 | 'options' => [ |
||
108 | 'fields' => ['firstName', 'lastName'] |
||
109 | ], |
||
110 | 'default_value' => 'true', |
||
111 | ] |
||
112 | ], |
||
113 | 'actions' => [ |
||
114 | 'default' => [ |
||
115 | 'view' => [ |
||
116 | 'type' => 'link', |
||
117 | 'label' => 'Display Tax Category', |
||
118 | 'options' => [ |
||
119 | 'foo' => 'bar', |
||
120 | ], |
||
121 | ] |
||
122 | ] |
||
123 | ] |
||
124 | ]; |
||
125 | |||
126 | $this->convert('sylius_admin_tax_category', $definitionArray)->shouldBeSameGridAs($grid); |
||
127 | } |
||
128 | |||
138 |