Passed
Push — master ( 59eb56...63534b )
by Mathias
09:13
created

ApiJobListByOrganizationController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 8
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Jobs\Controller;
4
5
use Jobs\Entity\StatusInterface;
6
7
use Jobs\Model\ApiJobDehydrator;
8
use Jobs\Repository;
9
use Zend\Http\PhpEnvironment\Response;
10
use Zend\InputFilter\InputFilter;
11
use Zend\Mvc\Controller\AbstractActionController;
12
use Zend\View\Model\JsonModel;
13
14
class ApiJobListByOrganizationController extends AbstractActionController
15
{
16
    /**
17
     * @var Repository\Job
18
     */
19
    private $jobRepository;
20
21
    /**
22
     * @var ApiJobDehydrator
23
     */
24
    private $apiJobDehydrator;
25
26
    /**
27
     * @var InputFilter
28
     */
29
    private $filter;
30
31
32 1
    public function __construct(
33
        Repository\Job $jobRepository,
34
        ApiJobDehydrator $apiJobDehydrator,
35
        InputFilter $filter
36
    ) {
37 1
        $this->jobRepository = $jobRepository;
38 1
        $this->apiJobDehydrator = $apiJobDehydrator;
39 1
        $this->filter = $filter;
40 1
    }
41
42
    public function indexAction()
43
    {
44
        $organizationId = $this->params()->fromRoute('organizationId', 0);
45
        $callback = $this->filter->setData($_GET)->getValue('callback');
46
47
        $status = $this->filter->getValue('status');
48
        var_dump($status);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($status) looks like debug code. Are you sure you do not want to remove it?
Loading history...
49
        if (true === $status) { $status = null; }
50
        elseif (!$status) { $status = StatusInterface::ACTIVE; }
51
        var_dump($status);
52
        try {
53
            $jobs = $this->jobRepository->findByOrganization($organizationId, $status);
54
        } catch (\Exception $e) {
55
            /** @var Response $response */
56
            $response = $this->getResponse();
57
            $response->setStatusCode(Response::STATUS_CODE_404);
58
            return $response;
59
        }
60
        $jsonModel=new JsonModel();
61
        $jsonModel->setVariables($this->apiJobDehydrator->dehydrateList($jobs));
62
        $jsonModel->setJsonpCallback($callback);
0 ignored issues
show
Bug introduced by
It seems like $callback can also be of type array; however, parameter $callback of Zend\View\Model\JsonModel::setJsonpCallback() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

62
        $jsonModel->setJsonpCallback(/** @scrutinizer ignore-type */ $callback);
Loading history...
63
64
        return $jsonModel;
65
    }
66
}
67