| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 127 | 
| Code Lines | 88 | 
| 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  | 
            ||
| 42 | function it_converts_an_array_to_grid_definition(EventDispatcherInterface $eventDispatcher): void  | 
            ||
| 43 |     { | 
            ||
| 44 | $grid = Grid::fromCodeAndDriverConfiguration(  | 
            ||
| 45 | 'sylius_admin_tax_category',  | 
            ||
| 46 | 'doctrine/orm',  | 
            ||
| 47 | ['resource' => 'sylius.tax_category']  | 
            ||
| 48 | );  | 
            ||
| 49 | |||
| 50 | $grid->setSorting(['code' => 'desc']);  | 
            ||
| 51 | |||
| 52 | $grid->setLimits([9, 18]);  | 
            ||
| 53 | |||
| 54 |         $codeField = Field::fromNameAndType('code', 'string'); | 
            ||
| 55 |         $codeField->setLabel('System Code'); | 
            ||
| 56 |         $codeField->setPath('method.code'); | 
            ||
| 57 | $codeField->setOptions(['template' => 'bar.html.twig']);  | 
            ||
| 58 |         $codeField->setSortable('code'); | 
            ||
| 59 | |||
| 60 | $grid->addField($codeField);  | 
            ||
| 61 | |||
| 62 |         $enabledField = Field::fromNameAndType('enabled', 'boolean'); | 
            ||
| 63 |         $enabledField->setLabel('Enabled'); | 
            ||
| 64 |         $enabledField->setPath('method.enabled'); | 
            ||
| 65 |         $enabledField->setSortable('enabled'); | 
            ||
| 66 | |||
| 67 | $grid->addField($enabledField);  | 
            ||
| 68 | |||
| 69 |         $statusField = Field::fromNameAndType('status', 'string'); | 
            ||
| 70 |         $statusField->setLabel('Status'); | 
            ||
| 71 |         $statusField->setSortable('status'); | 
            ||
| 72 | |||
| 73 | $grid->addField($statusField);  | 
            ||
| 74 | |||
| 75 |         $nameField = Field::fromNameAndType('name', 'string'); | 
            ||
| 76 |         $nameField->setLabel('Name'); | 
            ||
| 77 |         $nameField->setSortable('name'); | 
            ||
| 78 | |||
| 79 | $grid->addField($nameField);  | 
            ||
| 80 | |||
| 81 |         $titleField = Field::fromNameAndType('title', 'string'); | 
            ||
| 82 |         $titleField->setLabel('Title'); | 
            ||
| 83 | |||
| 84 | $grid->addField($titleField);  | 
            ||
| 85 | |||
| 86 |         $viewAction = Action::fromNameAndType('view', 'link'); | 
            ||
| 87 |         $viewAction->setLabel('Display Tax Category'); | 
            ||
| 88 | $viewAction->setOptions(['foo' => 'bar']);  | 
            ||
| 89 |         $defaultActionGroup = ActionGroup::named('default'); | 
            ||
| 90 | $defaultActionGroup->addAction($viewAction);  | 
            ||
| 91 | |||
| 92 | $grid->addActionGroup($defaultActionGroup);  | 
            ||
| 93 | |||
| 94 |         $filter = Filter::fromNameAndType('enabled', 'boolean'); | 
            ||
| 95 | $filter->setOptions(['fields' => ['firstName', 'lastName']]);  | 
            ||
| 96 |         $filter->setCriteria('true'); | 
            ||
| 97 | $grid->addFilter($filter);  | 
            ||
| 98 | |||
| 99 | $eventDispatcher  | 
            ||
| 100 |             ->dispatch('sylius.grid.admin_tax_category', Argument::type(GridDefinitionConverterEvent::class)) | 
            ||
| 101 | ->shouldBeCalled()  | 
            ||
| 102 | ;  | 
            ||
| 103 | |||
| 104 | $definitionArray = [  | 
            ||
| 105 | 'driver' => [  | 
            ||
| 106 | 'name' => 'doctrine/orm',  | 
            ||
| 107 | 'options' => ['resource' => 'sylius.tax_category'],  | 
            ||
| 108 | ],  | 
            ||
| 109 | 'sorting' => [  | 
            ||
| 110 | 'code' => 'desc',  | 
            ||
| 111 | ],  | 
            ||
| 112 | 'limits' => [9, 18],  | 
            ||
| 113 | 'fields' => [  | 
            ||
| 114 | 'code' => [  | 
            ||
| 115 | 'type' => 'string',  | 
            ||
| 116 | 'label' => 'System Code',  | 
            ||
| 117 | 'path' => 'method.code',  | 
            ||
| 118 | 'sortable' => 'code',  | 
            ||
| 119 | 'options' => [  | 
            ||
| 120 | 'template' => 'bar.html.twig',  | 
            ||
| 121 | ],  | 
            ||
| 122 | ],  | 
            ||
| 123 | 'enabled' => [  | 
            ||
| 124 | 'type' => 'boolean',  | 
            ||
| 125 | 'label' => 'Enabled',  | 
            ||
| 126 | 'path' => 'method.enabled',  | 
            ||
| 127 | 'sortable' => true,  | 
            ||
| 128 | ],  | 
            ||
| 129 | 'status' => [  | 
            ||
| 130 | 'type' => 'string',  | 
            ||
| 131 | 'label' => 'Status',  | 
            ||
| 132 | 'sortable' => true,  | 
            ||
| 133 | ],  | 
            ||
| 134 | 'name' => [  | 
            ||
| 135 | 'type' => 'string',  | 
            ||
| 136 | 'label' => 'Name',  | 
            ||
| 137 | 'sortable' => null,  | 
            ||
| 138 | ],  | 
            ||
| 139 | 'title' => [  | 
            ||
| 140 | 'type' => 'string',  | 
            ||
| 141 | 'label' => 'Title',  | 
            ||
| 142 | 'sortable' => false,  | 
            ||
| 143 | ],  | 
            ||
| 144 | ],  | 
            ||
| 145 | 'filters' => [  | 
            ||
| 146 | 'enabled' => [  | 
            ||
| 147 | 'type' => 'boolean',  | 
            ||
| 148 | 'options' => [  | 
            ||
| 149 | 'fields' => ['firstName', 'lastName'],  | 
            ||
| 150 | ],  | 
            ||
| 151 | 'default_value' => 'true',  | 
            ||
| 152 | ],  | 
            ||
| 153 | ],  | 
            ||
| 154 | 'actions' => [  | 
            ||
| 155 | 'default' => [  | 
            ||
| 156 | 'view' => [  | 
            ||
| 157 | 'type' => 'link',  | 
            ||
| 158 | 'label' => 'Display Tax Category',  | 
            ||
| 159 | 'options' => [  | 
            ||
| 160 | 'foo' => 'bar',  | 
            ||
| 161 | ],  | 
            ||
| 162 | ],  | 
            ||
| 163 | ],  | 
            ||
| 164 | ],  | 
            ||
| 165 | ];  | 
            ||
| 166 | |||
| 167 |         $this->convert('sylius_admin_tax_category', $definitionArray)->shouldBeLike($grid); | 
            ||
| 168 | }  | 
            ||
| 169 | }  | 
            ||
| 170 |