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

DeleteAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A deleteAction() 0 16 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 Phalcon\Http\ResponseInterface;
15
use Zemit\Mvc\Controller\AbstractTrait\AbstractInjectable;
16
use Zemit\Mvc\Controller\Rest\Response;
17
18
trait DeleteAction
19
{
20
    use AbstractInjectable;
21
    use Response;
22
    
23
    /**
24
     * Deleting a record
25
     */
26
    public function deleteAction(string|int $id = null): ResponseInterface
27
    {
28
        $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

28
        /** @scrutinizer ignore-call */ 
29
        $entity = $this->getSingle($id);
Loading history...
29
        
30
        if (!$entity) {
31
            return $this->setRestErrorResponse(404);
32
        }
33
        
34
        $delete = $entity->delete();
35
        $this->view->setVars([
0 ignored issues
show
Bug introduced by
The property view does not exist on Zemit\Mvc\Controller\Rest\Actions\DeleteAction. Did you mean view;?
Loading history...
36
            'delete' => $delete,
37
            '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

37
            'single' => $this->/** @scrutinizer ignore-call */ expose($entity),
Loading history...
38
            'messages' => $entity->getMessages(),
39
        ]);
40
        
41
        return $this->setRestResponse($delete);
42
    }
43
}
44