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