Completed
Push — develop ( 5260e4...ed74ca )
by
unknown
12:11
created

InitializeJob   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 67
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 4 1
C get() 0 31 7
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013-2016 Cross Solution (http://cross-solution.de)
7
 * @author cbleek
8
 * @license   MIT
9
 */
10
11
namespace Jobs\Controller\Plugin;
12
13
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
14
use Core\Repository\RepositoryService;
15
use Auth\AuthenticationService;
16
use Zend\Mvc\Controller\Plugin\Params;
17
use Acl\Service\Acl;
18
19
/**
20
 * Class InitializeJob
21
 *
22
 * @package Jobs\Controller\Plugin
23
 */
24
class InitializeJob extends AbstractPlugin {
25
26
    /**
27
     * @var RepositoryService
28
     */
29
    protected $repositoryService;
30
31
    /**
32
     * @var AuthenticationService
33
     */
34
    protected $auth;
35
36
    /**
37
     * @var \Acl\Controller\Plugin\Acl
38
     */
39
    protected $acl;
40
41
    public function __construct(RepositoryService $repositoryService,AuthenticationService $auth, Acl $acl) {
42
        $this->repositoryService=$repositoryService;
43
        $this->auth=$auth;
44
        $this->acl=$acl;
0 ignored issues
show
Documentation Bug introduced by
It seems like $acl of type object<Acl\Service\Acl> is incompatible with the declared type object<Acl\Controller\Plugin\Acl> of property $acl.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
    }
46
47
    public function __invoke()
48
    {
49
        return $this;
50
    }
51
52
    /**
53
     * @param Params $params
54
     * @param bool   $allowDraft
55
     *
56
     * @return \Jobs\Entity\Job|object
57
     * @throws \Doctrine\ODM\MongoDB\LockException
58
     */
59
    public function get(Params $params,$allowDraft = false)
60
    {
61
        /* @var \Jobs\Repository\Job $jobRepository */
62
        $jobRepository  = $this->repositoryService->get('Jobs/Job');
63
        // @TODO three different method to obtain the job-id ?, simplify this
64
        $id_fromRoute   = $params('id', 0);
0 ignored issues
show
Coding Style introduced by
$id_fromRoute does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
65
        $id_fromQuery   = $params->fromQuery('id', 0);
0 ignored issues
show
Coding Style introduced by
$id_fromQuery does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
66
        $id_fromSubForm = $params->fromPost('job', 0);
0 ignored issues
show
Coding Style introduced by
$id_fromSubForm does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
67
68
        $id = empty($id_fromRoute)? (empty($id_fromQuery)?$id_fromSubForm:$id_fromQuery) : $id_fromRoute;
0 ignored issues
show
Coding Style introduced by
$id_fromRoute does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
69
70
        if (empty($id) && $allowDraft) {
71
            $this->acl->__invoke('Jobs/Manage', 'new');
72
            $user = $this->auth->getUser();
73
            /** @var \Jobs\Entity\Job $job */
74
            $job = $jobRepository->findDraft($user);
75
            if (empty($job)) {
76
                $job = $jobRepository->create();
77
                $job->setIsDraft(true);
78
                $job->setUser($user);
79
                $this->repositoryService->store($job);
80
            }
81
            return $job;
82
        }
83
84
        $job = $jobRepository->find($id);
85
        if (!$job) {
86
            throw new \RuntimeException('No job found with id "' . $id . '"');
87
        }
88
        return $job;
89
    }
90
}