| Conditions | 14 |
| Paths | 169 |
| Total Lines | 75 |
| Code Lines | 45 |
| 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 |
||
| 116 | public function buildPager() |
||
| 117 | { |
||
| 118 | if ($this->bound) { |
||
| 119 | return; |
||
| 120 | } |
||
| 121 | |||
| 122 | foreach ($this->getFilters() as $name => $filter) { |
||
| 123 | list($type, $options) = $filter->getRenderSettings(); |
||
| 124 | |||
| 125 | $this->formBuilder->add($filter->getFormName(), $type, $options); |
||
| 126 | } |
||
| 127 | |||
| 128 | $hiddenType = HiddenType::class; |
||
| 129 | |||
| 130 | $this->formBuilder->add('_sort_by', $hiddenType); |
||
| 131 | $this->formBuilder->get('_sort_by')->addViewTransformer(new CallbackTransformer( |
||
| 132 | function ($value) { |
||
| 133 | return $value; |
||
| 134 | }, |
||
| 135 | function ($value) { |
||
| 136 | return $value instanceof FieldDescriptionInterface ? $value->getName() : $value; |
||
| 137 | } |
||
| 138 | )); |
||
| 139 | |||
| 140 | $this->formBuilder->add('_sort_order', $hiddenType); |
||
| 141 | $this->formBuilder->add('_page', $hiddenType); |
||
| 142 | $this->formBuilder->add('_per_page', $hiddenType); |
||
| 143 | |||
| 144 | $this->form = $this->formBuilder->getForm(); |
||
| 145 | $this->form->submit($this->values); |
||
| 146 | |||
| 147 | $data = $this->form->getData(); |
||
| 148 | |||
| 149 | foreach ($this->getFilters() as $name => $filter) { |
||
| 150 | $this->values[$name] = isset($this->values[$name]) ? $this->values[$name] : null; |
||
| 151 | $filter->apply($this->query, $data[$filter->getFormName()]); |
||
| 152 | } |
||
| 153 | |||
| 154 | if (isset($this->values['_sort_by'])) { |
||
| 155 | if (!$this->values['_sort_by'] instanceof FieldDescriptionInterface) { |
||
| 156 | throw new UnexpectedTypeException($this->values['_sort_by'], FieldDescriptionInterface::class); |
||
| 157 | } |
||
| 158 | |||
| 159 | if ($this->values['_sort_by']->isSortable()) { |
||
| 160 | $this->query->setSortBy($this->values['_sort_by']->getSortParentAssociationMapping(), $this->values['_sort_by']->getSortFieldMapping()); |
||
| 161 | $this->query->setSortOrder(isset($this->values['_sort_order']) ? $this->values['_sort_order'] : null); |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | $maxPerPage = 25; |
||
| 166 | if (isset($this->values['_per_page'])) { |
||
| 167 | if (isset($this->values['_per_page']['value'])) { |
||
| 168 | $maxPerPage = $this->values['_per_page']['value']; |
||
| 169 | } else { |
||
| 170 | $maxPerPage = $this->values['_per_page']; |
||
| 171 | } |
||
| 172 | } |
||
| 173 | $this->pager->setMaxPerPage($maxPerPage); |
||
| 174 | |||
| 175 | $page = 1; |
||
| 176 | if (isset($this->values['_page'])) { |
||
| 177 | if (isset($this->values['_page']['value'])) { |
||
| 178 | $page = $this->values['_page']['value']; |
||
| 179 | } else { |
||
| 180 | $page = $this->values['_page']; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | $this->pager->setPage($page); |
||
| 185 | |||
| 186 | $this->pager->setQuery($this->query); |
||
| 187 | $this->pager->init(); |
||
| 188 | |||
| 189 | $this->bound = true; |
||
| 190 | } |
||
| 191 | |||
| 314 |