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