| Conditions | 5 |
| Paths | 9 |
| Total Lines | 54 |
| 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 |
||
| 14 | public function indexAction() |
||
| 15 | { |
||
| 16 | $type = $this->dispatcher->getParam('type', 'string'); |
||
|
|
|||
| 17 | $typeModel = Type::getCachedBySlug($type); |
||
| 18 | if (!$typeModel) { |
||
| 19 | throw new Exception("Publication hasn't type = '$type''"); |
||
| 20 | } |
||
| 21 | |||
| 22 | $typeLimit = ($typeModel->getLimit()) ? $typeModel->getLimit() : 10; |
||
| 23 | $limit = $this->request->getQuery('limit', 'string', $typeLimit); |
||
| 24 | if ($limit != 'all') { |
||
| 25 | $paginatorLimit = (int)$limit; |
||
| 26 | } else { |
||
| 27 | $paginatorLimit = 9999; |
||
| 28 | } |
||
| 29 | $page = $this->request->getQuery('page', 'int', 1); |
||
| 30 | |||
| 31 | /*$publications = Publication::find(array( |
||
| 32 | "type_id = {$typeModel->getId()}", |
||
| 33 | "order" => "date DESC", |
||
| 34 | ));*/ |
||
| 35 | |||
| 36 | $publicationHelper = new PublicationHelper(); |
||
| 37 | $fields = $publicationHelper->translateFieldsSubQuery(); |
||
| 38 | |||
| 39 | $columns = ['p.*', 't_slug' => 't.slug']; |
||
| 40 | $columns = array_merge($columns, $fields); |
||
| 41 | |||
| 42 | $qb = $this->modelsManager->createBuilder() |
||
| 43 | ->columns($columns) |
||
| 44 | ->addFrom('Publication\Model\Publication', 'p') |
||
| 45 | ->leftJoin('Publication\Model\Type', null, 't') |
||
| 46 | ->andWhere('t.slug = :type:', ['type' => $type]) |
||
| 47 | ->andWhere('p.date <= NOW()') |
||
| 48 | ->orderBy('p.date DESC'); |
||
| 49 | |||
| 50 | $paginator = new \Phalcon\Paginator\Adapter\QueryBuilder([ |
||
| 51 | "builder" => $qb, |
||
| 52 | "limit" => $paginatorLimit, |
||
| 53 | "page" => $page |
||
| 54 | ]); |
||
| 55 | |||
| 56 | $this->view->paginate = $paginator->getPaginate(); |
||
| 57 | |||
| 58 | $this->helper->title()->append($typeModel->getHeadTitle()); |
||
| 59 | if ($page > 1) { |
||
| 60 | $this->helper->title()->append($this->helper->translate('Страница №') . ' ' . $page); |
||
| 61 | } |
||
| 62 | $this->view->title = $typeModel->getTitle(); |
||
| 63 | $this->view->format = $typeModel->getFormat(); |
||
| 64 | $this->view->type = $type; |
||
| 65 | |||
| 66 | $this->helper->menu->setActive($type); |
||
| 67 | } |
||
| 68 | |||
| 93 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: