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

ReorderAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 1
b 0
f 0
dl 0
loc 27
ccs 0
cts 12
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A reorderAction() 0 18 2
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 Exception;
15
use Phalcon\Filter\Filter;
16
use Phalcon\Http\ResponseInterface;
17
use Zemit\Mvc\Controller\AbstractTrait\AbstractInjectable;
18
use Zemit\Mvc\Controller\Rest\Response;
19
20
trait ReorderAction
21
{
22
    use AbstractInjectable;
23
    use Response;
24
    
25
    /**
26
     * Re-ordering a position
27
     * @throws Exception
28
     */
29
    public function reorderAction(string|int $id = null, int $position = null): ResponseInterface
30
    {
31
        $entity = $this->getSingle($id);
0 ignored issues
show
Bug introduced by
It seems like getSingle() 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

31
        /** @scrutinizer ignore-call */ 
32
        $entity = $this->getSingle($id);
Loading history...
32
        
33
        if (!$entity) {
34
            return $this->setRestErrorResponse(404);
35
        }
36
        
37
        $position ??= $this->getParam('position', [Filter::FILTER_INT]);
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

37
        $position ??= $this->/** @scrutinizer ignore-call */ getParam('position', [Filter::FILTER_INT]);
Loading history...
38
        
39
        $reorder = $entity->reorder($position);
40
        $this->view->setVars([
0 ignored issues
show
Bug introduced by
The property view does not exist on Zemit\Mvc\Controller\Rest\Actions\ReorderAction. Did you mean view;?
Loading history...
41
            'reorder' => $reorder,
42
            'single' => $this->expose($entity),
0 ignored issues
show
Bug introduced by
It seems like expose() 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

42
            'single' => $this->/** @scrutinizer ignore-call */ expose($entity),
Loading history...
43
            'messages' => $entity->getMessages(),
44
        ]);
45
        
46
        return $this->setRestResponse($reorder);
47
    }
48
}
49