Completed
Push — develop ( 8cb156...27be84 )
by
unknown
17:07
created

ManageController::statusAction()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 83
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 83
rs 5.8854
c 0
b 0
f 0
cc 8
eloc 45
nc 8
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
/** Applications controller */
11
namespace Applications\Controller;
12
13
use Applications\Form\ApplicationsFilter;
14
use Applications\Listener\Events\ApplicationEvent;
15
use Zend\Mvc\Controller\AbstractActionController;
16
use Zend\View\Model\ViewModel;
17
use Zend\View\Model\JsonModel;
18
use Applications\Entity\StatusInterface as Status;
19
use Applications\Entity\Application;
20
21
/**
22
 * @method \Core\Controller\Plugin\Notification notification()
23
 * @method \Core\Controller\Plugin\Mailer mailer()
24
 * @method \Acl\Controller\Plugin\Acl acl()
25
 * @method \Auth\Controller\Plugin\Auth auth()
26
 *
27
 * Handles managing actions on applications
28
 */
29
class ManageController extends AbstractActionController
30
{
31
    /**
32
     * attaches further Listeners for generating / processing the output
33
     *
34
     * @return $this
35
     */
36 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...
37
    {
38
        parent::attachDefaultListeners();
39
        $serviceLocator  = $this->serviceLocator;
40
        $defaultServices = $serviceLocator->get('DefaultListeners');
41
        $events          = $this->getEventManager();
42
        $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...
43
        return $this;
44
    }
45
46
    /**
47
     * (non-PHPdoc)
48
     * @see \Zend\Mvc\Controller\AbstractActionController::onDispatch()
49
     */
50
    public function onDispatch(\Zend\Mvc\MvcEvent $e)
51
    {
52
        $routeMatch = $e->getRouteMatch();
53
        $action     = $this->params()->fromQuery('action');
54
        
55
        if ($routeMatch && $action) {
56
            $routeMatch->setParam('action', $action);
57
        }
58
59
        return parent::onDispatch($e);
60
    }
61
    
62
    /**
63
     * List applications
64
     */
65 View Code Duplication
    public function indexAction()
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...
66
    {
67
        return $this->pagination([
0 ignored issues
show
Documentation Bug introduced by
The method pagination does not exist on object<Applications\Controller\ManageController>? 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...
68
                'params' => ['Application_List', ['q', 'job', 'page' => 1, 'unread', 'status' => 'all']],
69
                'paginator' => ['Applications', 'as' => 'applications'],
70
                'form' => [
71
                    ApplicationsFilter::class,
72
                    'as' => 'form'
73
                ],
74
            ]);
75
    }
76
77
    /**
78
     * Detail view of an application
79
     *
80
     * @return array|JsonModel|ViewModel
81
     */
82
    public function detailAction()
83
    {
84
        if ('refresh-rating' == $this->params()->fromQuery('do')) {
85
            return $this->refreshRatingAction();
86
        }
87
        
88
        $nav = $this->serviceLocator->get('Core/Navigation');
89
        $page = $nav->findByRoute('lang/applications');
90
        $page->setActive();
91
92
        /* @var \Applications\Repository\Application$repository */
93
        $repository = $this->serviceLocator->get('repositories')->get('Applications/Application');
94
        /* @var Application $application */
95
        $application = $repository->find($this->params('id'));
96
        
97
        if (!$application) {
98
            $this->response->setStatusCode(410);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\ResponseInterface as the method setStatusCode() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Response, Zend\Http\Response, Zend\Http\Response\Stream.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
99
            $model = new ViewModel(
100
                array(
101
                'content' => /*@translate*/ 'Invalid apply id'
102
                )
103
            );
104
            $model->setTemplate('applications/error/not-found');
105
            return $model;
106
        }
107
        
108
        $this->acl($application, 'read');
0 ignored issues
show
Unused Code introduced by
The call to ManageController::acl() has too many arguments starting with $application.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
109
        
110
        $applicationIsUnread = false;
111
        if ($application->isUnreadBy($this->auth('id')) && $application->getStatus()) {
0 ignored issues
show
Unused Code introduced by
The call to ManageController::auth() has too many arguments starting with 'id'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Documentation introduced by
$this->auth('id') is of type object<Auth\Controller\Plugin\Auth>, but the function expects a object<Auth\Entity\UserInterface>|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...
112
            $application->addReadBy($this->auth('id'));
0 ignored issues
show
Unused Code introduced by
The call to ManageController::auth() has too many arguments starting with 'id'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Documentation introduced by
$this->auth('id') is of type object<Auth\Controller\Plugin\Auth>, but the function expects a object<Auth\Entity\UserInterface>|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...
113
            $applicationIsUnread = true;
114
            $application->changeStatus(
115
                $application->getStatus(),
116
                sprintf(/*@translate*/ 'Application was read by %s',
117
                                       $this->auth()->getUser()->getInfo()->getDisplayName()));
118
        }
119
120
121
        
122
        $format=$this->params()->fromQuery('format');
123
124
        if ($application->isDraft()) {
125
            $list = false;
126
        } else {
127
            $list = $this->paginationParams('Applications\Index', $repository);
0 ignored issues
show
Bug introduced by
The method paginationParams() does not exist on Applications\Controller\ManageController. Did you maybe mean params()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
128
            $list->setCurrent($application->getId());
129
        }
130
131
        $return = array(
132
            'application'=> $application,
133
            'list' => $list,
134
            'isUnread' => $applicationIsUnread,
135
            'format' => 'html'
136
        );
137
        switch ($format) {
138
            case 'json':
139
                /*@deprecated - must be refactored */
140
                        $viewModel = new JsonModel();
141
                        $viewModel->setVariables(
142
                            /*array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
143
                            'application' => */$this->serviceLocator
144
                                              ->get('builders')
145
                                              ->get('JsonApplication')
146
                                              ->unbuild($application)
147
                        );
148
                        $viewModel->setVariable('isUnread', $applicationIsUnread);
149
                        $return = $viewModel;
150
                break;
151
            case 'pdf':
152
                $pdf = $this->serviceLocator->get('Core/html2pdf');
0 ignored issues
show
Unused Code introduced by
$pdf is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
153
                $return['format'] = $format;
154
                break;
155
            default:
156
                $contentCollector = $this->getPluginManager()->get('Core/ContentCollector');
157
                $contentCollector->setTemplate('applications/manage/details/action-buttons');
0 ignored issues
show
Bug introduced by
The method setTemplate() does not seem to exist on object<Zend\Stdlib\DispatchableInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
158
                $actionButtons = $contentCollector->trigger('application.detail.actionbuttons', $application);
0 ignored issues
show
Bug introduced by
The method trigger() does not seem to exist on object<Zend\Stdlib\DispatchableInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
159
                
160
                $return = new ViewModel($return);
161
                $return->addChild($actionButtons, 'externActionButtons');
162
                
163
                $allowSubsequentAttachmentUpload = $this->serviceLocator->get('Applications/Options')
164
                    ->getAllowSubsequentAttachmentUpload();
165
                
166
                if ($allowSubsequentAttachmentUpload
167
                    && $this->acl($application, Application::PERMISSION_SUBSEQUENT_ATTACHMENT_UPLOAD, 'test')
0 ignored issues
show
Unused Code introduced by
The call to ManageController::acl() has too many arguments starting with $application.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
168
                ) {
169
                    $attachmentsForm = $this->serviceLocator->get('forms')
170
                        ->get('Applications/Attachments');
171
                    $attachmentsForm->bind($application->getAttachments());
172
                    
173
                    /* @var $request \Zend\Http\PhpEnvironment\Request */
174
                    $request = $this->getRequest();
175
                    
176
                    if ($request->isPost() && $attachmentsForm->get('return')->getValue() === $request->getPost('return')) {
177
                        $data = array_merge(
178
                            $attachmentsForm->getOption('use_post_array') ? $request->getPost()->toArray() : [],
179
                            $attachmentsForm->getOption('use_files_array') ? $request->getFiles()->toArray() : []
180
                        );
181
                        $attachmentsForm->setData($data);
182
                        
183
                        if (!$attachmentsForm->isValid()) {
184
                            return new JsonModel([
185
                                'valid' => false,
186
                                'errors' => $attachmentsForm->getMessages()
187
                            ]);
188
                        }
189
                        
190
                        $content = $attachmentsForm->getHydrator()
191
                            ->getLastUploadedFile()
192
                            ->getUri();
193
                        
194
                        return new JsonModel([
195
                            'valid' => $attachmentsForm->isValid(),
196
                            'content' => $content
197
                        ]);
198
                    }
199
                    
200
                    $return->setVariable('attachmentsForm', $attachmentsForm);
201
                }
202
                
203
                break;
204
        }
205
        
206
        return $return;
207
    }
208
    
209
    /**
210
     * Refreshes the rating of an application
211
     *
212
     * @throws \DomainException
213
     * @return \Zend\View\Model\ViewModel
214
     */
215
    public function refreshRatingAction()
216
    {
217
        $model = new ViewModel();
218
        $model->setTemplate('applications/manage/_rating');
219
        
220
        $application = $this->serviceLocator->get('repositories')->get('Applications/Application')
221
                        ->find($this->params('id', 0));
222
        
223
        if (!$application) {
224
            throw new \DomainException('Invalid application id.');
225
        }
226
        
227
        $model->setVariable('application', $application);
228
        return $model;
229
    }
230
    
231
    /**
232
     * Attaches a social profile to an application
233
     * @throws \InvalidArgumentException
234
     *
235
     * @return array
236
     */
237
    public function socialProfileAction()
238
    {
239
        if ($spId = $this->params()->fromQuery('spId')) {
0 ignored issues
show
Unused Code introduced by
$spId is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
240
            $repositories = $this->serviceLocator->get('repositories');
241
            $repo = $repositories->get('Applications/Application');
242
            $profile = $repo->findProfile($this->params()->fromQuery('spId'));
243
            if (!$profile) {
244
                throw new \InvalidArgumentException('Could not find profile.');
245
            }
246
        } elseif ($this->getRequest()->isPost()
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method isPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
247
                   && ($network = $this->params()->fromQuery('network'))
248
                   && ($data    = $this->params()->fromPost('data'))
249
        ) {
250
            $profileClass = '\\Auth\\Entity\\SocialProfiles\\' . $network;
251
            $profile      = new $profileClass();
252
            $profile->setData(\Zend\Json\Json::decode($data, \Zend\Json\Json::TYPE_ARRAY));
253
        } else {
254
            throw new \RuntimeException(
255
                'Missing arguments. Either provide "spId" as Get or "network" and "data" as Post.'
256
            );
257
        }
258
        
259
        return array(
260
            'profile' => $profile
261
        );
262
    }
263
264
    /**
265
     * Changes the status of an application
266
     *
267
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be \Zend\Stdlib\ResponseInterface|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...
268
     */
269
    public function statusAction()
270
    {
271
        $applicationId = $this->params('id');
272
        /* @var \Applications\Repository\Application $repository */
273
        $repository    = $this->serviceLocator->get('repositories')->get('Applications/Application');
274
        /* @var Application $application */
275
        $application   = $repository->find($applicationId);
276
277
        /* @var Request $request */
278
        $request = $this->getRequest();
279
280
        if (!$application) {
281
            throw new \InvalidArgumentException('Could not find application.');
282
        }
283
        
284
        $this->acl($application, 'change');
0 ignored issues
show
Unused Code introduced by
The call to ManageController::acl() has too many arguments starting with $application.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
285
        
286
        $jsonFormat    = 'json' == $this->params()->fromQuery('format');
287
        $status        = $this->params('status', Status::CONFIRMED);
288
        $settings = $this->settings();
0 ignored issues
show
Documentation Bug introduced by
The method settings does not exist on object<Applications\Controller\ManageController>? 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...
Unused Code introduced by
$settings is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
289
        
290
        if (in_array($status, array(Status::INCOMING))) {
291
            $application->changeStatus($status);
292
            if ($request->isXmlHttpRequest()) {
293
                $response = $this->getResponse();
294
                $response->setContent('ok');
295
                return $response;
296
            }
297
            if ($jsonFormat) {
298
                return array(
299
                    'status' => 'success',
300
                );
301
            }
302
            return $this->redirect()->toRoute('lang/applications/detail', array(), true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a array.

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...
303
        }
304
305
        $events = $this->serviceLocator->get('Applications/Events');
306
307
        /* @var ApplicationEvent $event */
308
        $event = $events->getEvent(ApplicationEvent::EVENT_APPLICATION_STATUS_CHANGE,
309
                                   $this,
310
                                   [
311
                                       'application' => $application,
312
                                       'status' => $status,
313
                                       'user' => $this->auth()->getUser(),
314
                                   ]
315
        );
316
317
        $event->setIsPostRequest($request->isPost());
318
        $event->setPostData($request->getPost());
319
        $events->trigger($event);
320
321
        $params = $event->getFormData();
322
323
324
        if ($request->isPost()) {
325
326
            if ($jsonFormat) {
327
                return array(
328
                    'status' => 'success',
329
                );
330
            }
331
            $this->notification()->success($event->getNotification());
332
            return $this->redirect()->toRoute('lang/applications/detail', array(), true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a array.

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...
333
        }
334
335
        if ($jsonFormat) {
336
            return $params;
337
        }
338
339
        /* @var \Applications\Form\Mail $form */
340
        $form = $this->serviceLocator->get('FormElementManager')->get('Applications/Mail');
341
        $form->populateValues($params);
342
343
344
345
        $reciptient = $params['to'];
346
347
        return [
348
            'recipient' => $reciptient,
349
            'form' => $form
350
        ];
351
    }
352
    
353
    /**
354
     * Forwards an application via Email
355
     *
356
     * @throws \InvalidArgumentException
357
     * @return \Zend\View\Model\JsonModel
358
     */
359
    public function forwardAction()
360
    {
361
        $services     = $this->serviceLocator;
362
        $emailAddress = $this->params()->fromQuery('email');
363
        /* @var \Applications\Entity\Application $application */
364
        $application  = $services->get('repositories')->get('Applications/Application')
365
                                 ->find($this->params('id'));
366
        
367
        $this->acl($application, 'forward');
0 ignored issues
show
Unused Code introduced by
The call to ManageController::acl() has too many arguments starting with $application.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
368
        
369
        $translator   = $services->get('translator');
370
         
371
        if (!$emailAddress) {
372
            throw new \InvalidArgumentException('An email address must be supplied.');
373
        }
374
        
375
        $params = array(
376
            'ok' => true,
377
            'text' => sprintf($translator->translate('Forwarded application to %s'), $emailAddress)
378
        );
379
        
380
        try {
381
            $userName    = $this->auth('info')->getDisplayName();
0 ignored issues
show
Unused Code introduced by
The call to ManageController::auth() has too many arguments starting with 'info'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Documentation Bug introduced by
The method getDisplayName does not exist on object<Auth\Controller\Plugin\Auth>? 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...
382
            $fromAddress = $application->getJob()->getContactEmail();
383
            $mailOptions = array(
384
                'application' => $application,
385
                'to'          => $emailAddress,
386
                'from'        => array($fromAddress => $userName)
387
            );
388
            $this->mailer('Applications/Forward', $mailOptions, true);
0 ignored issues
show
Unused Code introduced by
The call to ManageController::mailer() has too many arguments starting with 'Applications/Forward'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
389
            $this->notification()->success($params['text']);
390
        } catch (\Exception $ex) {
391
            $params = array(
392
                'ok' => false,
393
                'text' => sprintf($translator->translate('Forward application to %s failed.'), $emailAddress)
394
            );
395
            $this->notification()->error($params['text']);
396
        }
397
        $application->changeStatus($application->getStatus(), $params['text']);
0 ignored issues
show
Bug introduced by
It seems like $application->getStatus() can be null; however, changeStatus() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
398
        return new JsonModel($params);
399
    }
400
401
    /**
402
     * Deletes an application
403
     *
404
     * @return array|\Zend\Http\Response
405
     */
406
    public function deleteAction()
407
    {
408
        $id          = $this->params('id');
409
        $services    = $this->serviceLocator;
410
        $repositories= $services->get('repositories');
411
        $repository  = $repositories->get('Applications/Application');
412
        $application = $repository->find($id);
413
        
414
        if (!$application) {
415
            throw new \DomainException('Application not found.');
416
        }
417
418
        $this->acl($application, 'delete');
0 ignored issues
show
Unused Code introduced by
The call to ManageController::acl() has too many arguments starting with $application.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
419
420
        $events   = $services->get('Applications/Events');
421
        $events->trigger(ApplicationEvent::EVENT_APPLICATION_PRE_DELETE, $this, [ 'application' => $application ]);
422
        
423
        $repositories->remove($application);
424
        
425
        if ('json' == $this->params()->fromQuery('format')) {
426
            return ['status' => 'success'];
427
        }
428
        
429
        return $this->redirect()->toRoute('lang/applications', array(), true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a array.

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...
430
    }
431
432
    /**
433
     * Move an application to talent pool
434
     *
435
     * @return \Zend\Http\Response
436
     * @since 0.26
437
     */
438
    public function moveAction()
439
    {
440
        $id = $this->params('id');
441
        $serviceManager = $this->serviceLocator;
442
        $repositories = $serviceManager->get('repositories');
443
        $application = $repositories->get('Applications/Application')->find($id);
444
        
445
        if (!$application) {
446
            throw new \DomainException('Application not found.');
447
        }
448
449
        $this->acl($application, 'move');
0 ignored issues
show
Unused Code introduced by
The call to ManageController::acl() has too many arguments starting with $application.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
450
        
451
        $user = $this->auth()->getUser();
452
        $cv = $repositories->get('Cv/Cv')->createFromApplication($application, $user);
453
        
454
        $repositories->store($cv);
455
        $repositories->remove($application);
456
457
        $this->notification()->success(
458
            /*@translate*/ 'Application has been successfully moved to Talent Pool');
459
        
460
        return $this->redirect()->toRoute('lang/applications', array(), true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a array.

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...
461
    }
462
}
463