Completed
Push — master ( 9bb285...104bd6 )
by Alexander
03:14
created

PageController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 4
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAction() 0 15 3
A listAction() 0 8 1
1
<?php
2
3
namespace Api\Controller;
4
5
/**
6
 * Class PageController.
7
 * Class is responsible for handling Page entity via REST API.
8
 *
9
 * @package Api\Controller
10
 */
11
class PageController extends \Api\Controller\RestController
12
{
13
    /**
14
     * Action responsible to display info about single page entity.
15
     *
16
     * @return \Phalcon\Http\ResponseInterface
17
     * @throws \Api\Exception\NotImplementedException
18
     */
19
    public function getAction()
20
    {
21
        //get entity from storage
22
        $pageId = (int) $this->request->getQuery('pageId');
23
        $page = \Page\Model\Page::findFirst($pageId);
24
        if (!$pageId || !$page) {
25
            return $this->render(new \Api\Model\Payload(null, sprintf('Page with id: %s was not found.', $pageId)));
0 ignored issues
show
Documentation introduced by
sprintf('Page with id: %...s not found.', $pageId) is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
26
        }
27
28
        //filter required data for display
29
        $filter = new \Api\Filter\Page();
30
        $payload = new \Api\Model\Payload($filter->filter($page));
31
32
        return $this->render($payload);
33
    }
34
35
    /**
36
     * Action responsible to display a list of pages with required data.
37
     *
38
     * @return \Phalcon\Http\ResponseInterface
39
     * @throws \Api\Exception\NotImplementedException
40
     */
41
    public function listAction()
42
    {
43
        $pages = \Page\Model\Page::find();
44
        $filter = new \Api\Filter\PagesList();
45
        $payload = new \Api\Model\Payload($filter->filter($pages));
46
47
        return $this->render($payload);
48
    }
49
}
50