Completed
Push — develop ( f24506...7bdff2 )
by
unknown
07:25
created

JobboardController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/** ActionController of Jobs */
11
namespace Jobs\Controller;
12
13
use Core\Form\SearchForm;
14
use Jobs\Form\ListFilter;
15
use Jobs\Listener\Events\JobEvent;
16
use Zend\Mvc\Controller\AbstractActionController;
17
use Zend\Session\Container as Session;
18
use Jobs\Repository;
19
use Zend\View\Model\ViewModel;
20
21
/**
22
 * @method \Auth\Controller\Plugin\Auth auth()
23
 * @method \Core\Controller\Plugin\CreatePaginatorService paginatorService()
24
 *
25
 * Controller for jobboard actions
26
 */
27
class JobboardController extends AbstractActionController
28
{
29
    /**
30
     * @var Repository\Job $jobRepository
31
     */
32
    private $jobRepository;
33
34
    /**
35
     * @var array
36
     */
37
    private $options = [
38
        'count' => 10
39
    ];
40
41
    /**
42
     * Construct the jobboard controller
43
     *
44
     * @param Repository\Job $jobRepository
45
     */
46
    public function __construct(Repository\Job $jobRepository, $options)
47
    {
48
        $this->jobRepository = $jobRepository;
49
        $this->options = $options;
50
    }
51
    /**
52
     * attaches further Listeners for generating / processing the output
53
     * @return $this
54
     */
55
    public function attachDefaultListeners()
56
    {
57
        parent::attachDefaultListeners();
58
        $serviceLocator = $this->serviceLocator;
59
        $defaultServices = $serviceLocator->get('DefaultListeners');
60
        $events          = $this->getEventManager();
61
        $events->attach($defaultServices);
0 ignored issues
show
Documentation introduced by
$defaultServices is of type object|array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
        return $this;
63
    }
64
65
    /**
66
     * List jobs
67
     *
68
     * @return ViewModel
0 ignored issues
show
Documentation introduced by
Should the return type not be array<string,object|array>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
69
     */
70
    public function indexAction()
71
    {
72
        /* @todo: move this into a listener.
73
         *
74
         * The following lines allow to override get param[q] with the
75
         * param from route. This feature is needed for a landing-page feature, where
76
         * human readable urls like http://yawik.org/demo/de/jobs/sales.html
77
         *
78
         * move the Logic into a Listener, which can be activated, if needed
79
         */
80
        $request = $this->getRequest();
81
        $getParams = $request->getQuery();
82
        $routeParams = $this->params()->fromRoute();
83
        if (isset($routeParams['q']) && !isset($getParams['q'])){
84
            $getParams['q']=$routeParams['q'];
85
        }
86
87
        $result = $this->pagination([
0 ignored issues
show
Documentation Bug introduced by
The method pagination does not exist on object<Jobs\Controller\JobboardController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
88
                'params' => ['Jobs_Board', [
89
                    'q',
90
                    'count' => $this->options['count'],
91
                    'page' => 1,
92
                    'l',
93
                    'd' => 10]
94
                ],
95
                'form' => ['as' => 'filterForm', 'Jobs/JobboardSearch'],
96
                'paginator' => ['as' => 'jobs', 'Jobs/Board']
97
            ]);
98
99
        $params['by'] = "guest";
0 ignored issues
show
Coding Style Comprehensibility introduced by
$params was never initialized. Although not strictly required by PHP, it is generally a good practice to add $params = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
100
101
        $organizationImageCache = $this->serviceLocator->get('Organizations\ImageFileCache\Manager');
102
103
        $result['organizationImageCache'] = $organizationImageCache;
104
105
        return $result;
106
    }
107
}
108