Passed
Push — master ( 5b5c00...4c0c12 )
by Julien
04:52
created

IndexAction::restForwarding()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 22
ccs 0
cts 15
cp 0
rs 8.8333
cc 7
nc 5
nop 0
crap 56
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Mvc\Controller\Rest\Actions;
13
14
use Phalcon\Dispatcher\Exception;
15
use Phalcon\Filter\Filter;
16
use Phalcon\Http\ResponseInterface;
17
use Zemit\Mvc\Controller\AbstractTrait\AbstractInjectable;
18
19
trait IndexAction
20
{
21
    use AbstractInjectable;
22
    
23
    /**
24
     * @throws Exception
25
     */
26
    public function indexAction(): ResponseInterface
27
    {
28
        $this->restForwarding();
29
        $ret = $this->dispatcher->getReturnedValue();
0 ignored issues
show
Bug introduced by
The property dispatcher does not exist on Zemit\Mvc\Controller\Rest\Actions\IndexAction. Did you mean dispatcher;?
Loading history...
30
        return $ret instanceof ResponseInterface ? $ret : $this->setRestResponse($ret);
0 ignored issues
show
Bug introduced by
It seems like setRestResponse() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        return $ret instanceof ResponseInterface ? $ret : $this->/** @scrutinizer ignore-call */ setRestResponse($ret);
Loading history...
31
    }
32
    
33
    /**
34
     * @throws Exception
35
     */
36
    protected function restForwarding(): bool
37
    {
38
        $id = $this->getParam('id', [Filter::FILTER_ALNUM]);
0 ignored issues
show
Bug introduced by
It seems like getParam() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        /** @scrutinizer ignore-call */ 
39
        $id = $this->getParam('id', [Filter::FILTER_ALNUM]);
Loading history...
39
        if ($this->request->isPost() || $this->request->isPut() || $this->request->isPatch()) {
0 ignored issues
show
Bug introduced by
The property request does not exist on Zemit\Mvc\Controller\Rest\Actions\IndexAction. Did you mean request;?
Loading history...
40
            $this->dispatcher->forward(['action' => 'save']);
0 ignored issues
show
Bug introduced by
The property dispatcher does not exist on Zemit\Mvc\Controller\Rest\Actions\IndexAction. Did you mean dispatcher;?
Loading history...
41
            return true;
42
        }
43
        else if ($this->request->isDelete()) {
44
            $this->dispatcher->forward(['action' => 'delete']);
45
            return true;
46
        }
47
        else if ($this->request->isGet()) {
48
            if (is_null($id)) {
49
                $this->dispatcher->forward(['action' => 'getList']);
50
                return true;
51
            }
52
            else {
53
                $this->dispatcher->forward(['action' => 'get']);
54
                return true;
55
            }
56
        }
57
        return false;
58
    }
59
}
60