Passed
Push — 1.0.x ( 8353d5...3a2c37 )
by Julien
21:28
created

FindFirstAction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 59
ccs 0
cts 16
cp 0
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findFirstWithAction() 0 10 2
A findFirstAction() 0 10 2
A getWithAction() 0 3 1
A getAction() 0 3 1
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\Traits\Actions\Rest;
13
14
use Phalcon\Filter\Exception;
15
use Phalcon\Http\ResponseInterface;
16
use Zemit\Mvc\Controller\Traits\Abstracts\AbstractExpose;
17
use Zemit\Mvc\Controller\Traits\Abstracts\AbstractQuery;
18
use Zemit\Mvc\Controller\Traits\Abstracts\AbstractInjectable;
19
use Zemit\Mvc\Controller\Traits\Abstracts\AbstractRestResponse;
20
21
trait FindFirstAction
22
{
23
    use AbstractExpose;
24
    use AbstractQuery;
25
    use AbstractInjectable;
26
    use AbstractRestResponse;
27
    
28
    /**
29
     * Retrieving a single record
30
     * @link findFirstAction()
31
     * @deprecated use {@link findFirstAction()}
32
     * @throws \Exception
33
     */
34
    public function getAction(): ResponseInterface
35
    {
36
        return $this->findFirstAction();
37
    }
38
    
39
    /**
40
     * Retrieving a single record
41
     * @link findFirstWithAction()
42
     * @deprecated use {@link findFirstWithAction()}
43
     * @throws \Exception
44
     */
45
    public function getWithAction(): ResponseInterface
46
    {
47
        return $this->findFirstWithAction();
48
    }
49
    
50
    /**
51
     * Retrieving a single record
52
     * @throws \Exception
53
     */
54
    public function findFirstAction(): ResponseInterface
55
    {
56
        $result = $this->findFirst();
57
        
58
        if (!$result) {
59
            return $this->setRestErrorResponse(404);
60
        }
61
        
62
        $this->view->setVar('data', $this->expose($result));
63
        return $this->setRestResponse(true);
64
    }
65
    
66
    /**
67
     * Retrieving a single record
68
     * @throws \Exception
69
     */
70
    public function findFirstWithAction(): ResponseInterface
71
    {
72
        $result = $this->findFirstWith();
73
        
74
        if (!$result) {
75
            return $this->setRestErrorResponse(404);
76
        }
77
        
78
        $this->view->setVar('data', $this->expose($result));
79
        return $this->setRestResponse(true);
80
    }
81
}
82