PageController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
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);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $page is correct as \Page\Model\Page::findFirst($pageId) (which targets Phalcon\Mvc\Model::findFirst()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $pages is correct as \Page\Model\Page::find() (which targets Phalcon\Mvc\Model::find()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
44
        $filter = new \Api\Filter\PagesList();
45
        $payload = new \Api\Model\Payload($filter->filter($pages));
46
47
        return $this->render($payload);
48
    }
49
}
50