Completed
Push — develop ( 83818f...f24506 )
by
unknown
07:25
created

JobboardController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 92
Duplicated Lines 9.78 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 9
loc 92
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A attachDefaultListeners() 9 9 1
A indexAction() 0 48 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
    public function attachDefaultListeners()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
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
        $job = $this->serviceLocator->get('repositories')->get('Jobs')->find('561b86e3d3b93f356d732bcf');
88
        $events = $this->serviceLocator->get('Jobs/Events');
89
        $jobEvent       = $this->serviceLocator->get('Jobs/Event');
90
        $jobEvent->setJobEntity($job);
91
        $jobEvent->addPortal('stackoverflow');
92
93
        $events->trigger(JobEvent::EVENT_JOB_ACCEPTED, $jobEvent);
94
        $this->getResponse()->setContent('voila!');
95
96
        return $this->response;
97
98
        $result = $this->pagination([
0 ignored issues
show
Unused Code introduced by
$result = $this->paginat...jobs', 'Jobs/Board'))); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
99
                'params' => ['Jobs_Board', [
100
                    'q',
101
                    'count' => $this->options['count'],
102
                    'page' => 1,
103
                    'l',
104
                    'd' => 10]
105
                ],
106
                'form' => ['as' => 'filterForm', 'Jobs/JobboardSearch'],
107
                'paginator' => ['as' => 'jobs', 'Jobs/Board']
108
            ]);
109
110
        $params['by'] = "guest";
111
112
        $organizationImageCache = $this->serviceLocator->get('Organizations\ImageFileCache\Manager');
113
114
        $result['organizationImageCache'] = $organizationImageCache;
115
116
        return $result;
117
    }
118
}
119