Completed
Push — develop ( e649e8...88dc2a )
by
unknown
15:53 queued 08:30
created

ManageController::socialProfileAction()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.439
cc 6
eloc 18
nc 4
nop 0
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\Listener\Events\ApplicationEvent;
14
use Zend\Http\Request;
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->getServiceLocator();
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
    public function indexAction()
66
    {
67
        $services              = $this->getServiceLocator();
68
        /* @var \Jobs\Repository\Job $jobRepository */
69
        $jobRepository         = $services->get('repositories')->get('Jobs/Job');
70
        /* @var \Applications\Repository\Application $applicationRepository */
71
        $applicationRepository = $services->get('repositories')->get('Applications/Application');
72
        $services_form         = $services->get('forms');
0 ignored issues
show
Coding Style introduced by
$services_form 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...
73
        /* @var \Applications\Form\FilterApplication $form */
74
        $form                  = $services_form->get('Applications/Filter');
0 ignored issues
show
Coding Style introduced by
$services_form 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...
75
        $params                = $this->getRequest()->getQuery();
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 getQuery() 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...
76
        /* @var \Zend\Form\Element\Select $statusElement */
77
        $statusElement         = $form->get('status');
78
79
        $states                = $applicationRepository->getStates()->toArray();
80
        $states                = array_merge(array(/*@translate*/ 'all'), $states);
81
        
82
        $statesForSelections = array();
83
        foreach ($states as $state) {
84
            $statesForSelections[$state] = $state;
85
        }
86
        $statusElement->setValueOptions($statesForSelections);
87
        
88
        $job = $params->job ? $jobRepository->find($params->job)  : null;
89
        $paginator = $this->paginator('Applications');
0 ignored issues
show
Documentation Bug introduced by
The method paginator 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...
90
91
        if ($job) {
92
            $params['job_title'] = '[' . $job->getApplyId() . '] ' . $job->getTitle();
93
        }
94
95
        $form->bind($params);
96
                
97
        return array(
98
            'form' => $form,
99
            'applications' => $paginator,
100
            'byJobs' => 'jobs' == $params->get('by', 'me'),
101
            'sort' => $params->get('sort', 'none'),
102
            'search' => $params->get('search', ''),
103
            'job' => $job,
104
            'applicationStates' => $states,
105
            'applicationState' => $params->get('status', '')
106
        );
107
    }
108
109
    /**
110
     * Detail view of an application
111
     *
112
     * @return array|JsonModel|ViewModel
113
     */
114
    public function detailAction()
115
    {
116
        if ('refresh-rating' == $this->params()->fromQuery('do')) {
117
            return $this->refreshRatingAction();
118
        }
119
        
120
        $nav = $this->getServiceLocator()->get('Core/Navigation');
121
        $page = $nav->findByRoute('lang/applications');
122
        $page->setActive();
123
124
        /* @var \Applications\Repository\Application$repository */
125
        $repository = $this->getServiceLocator()->get('repositories')->get('Applications/Application');
126
        /* @var Application $application */
127
        $application = $repository->find($this->params('id'));
128
        
129
        if (!$application) {
130
            $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...
131
            $model = new ViewModel(
132
                array(
133
                'content' => /*@translate*/ 'Invalid apply id'
134
                )
135
            );
136
            $model->setTemplate('applications/error/not-found');
137
            return $model;
138
        }
139
        
140
        $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...
141
        
142
        $applicationIsUnread = false;
143
        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...
144
            $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...
145
            $applicationIsUnread = true;
146
            $application->changeStatus(
147
                $application->getStatus(),
148
                sprintf(/*@translate*/ 'Application was read by %s',
149
                                       $this->auth()->getUser()->getInfo()->getDisplayName()));
150
        }
151
152
153
        
154
        $format=$this->params()->fromQuery('format');
155
156
        if ($application->isDraft()) {
157
            $list = false;
158
        } else {
159
            $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...
160
            $list->setCurrent($application->id);
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in Core\Entity\AbstractIdentifiableEntity. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
161
        }
162
163
        $return = array(
164
            'application'=> $application,
165
            'list' => $list,
166
            'isUnread' => $applicationIsUnread,
167
            'format' => 'html'
168
        );
169
        switch ($format) {
170
            case 'json':
171
                /*@deprecated - must be refactored */
172
                        $viewModel = new JsonModel();
173
                        $viewModel->setVariables(
174
                            /*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...
175
                            'application' => */$this->getServiceLocator()
176
                                              ->get('builders')
177
                                              ->get('JsonApplication')
178
                                              ->unbuild($application)
179
                        );
180
                        $viewModel->setVariable('isUnread', $applicationIsUnread);
181
                        $return = $viewModel;
182
                break;
183
            case 'pdf':
184
                $pdf = $this->getServiceLocator()->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...
185
                $return['format'] = $format;
186
                break;
187
            default:
188
                $contentCollector = $this->getPluginManager()->get('Core/ContentCollector');
189
                $contentCollector->setTemplate('applications/manage/details/action-buttons');
190
                $actionButtons = $contentCollector->trigger('application.detail.actionbuttons', $application);
191
                
192
                $return = new ViewModel($return);
193
                $return->addChild($actionButtons, 'externActionButtons');
194
                break;
195
        }
196
        
197
        return $return;
198
    }
199
    
200
    /**
201
     * Refreshes the rating of an application
202
     *
203
     * @throws \DomainException
204
     * @return \Zend\View\Model\ViewModel
205
     */
206
    public function refreshRatingAction()
207
    {
208
        $model = new ViewModel();
209
        $model->setTemplate('applications/manage/_rating');
210
        
211
        $application = $this->getServiceLocator()->get('repositories')->get('Applications/Application')
212
                        ->find($this->params('id', 0));
213
        
214
        if (!$application) {
215
            throw new \DomainException('Invalid application id.');
216
        }
217
        
218
        $model->setVariable('application', $application);
219
        return $model;
220
    }
221
    
222
    /**
223
     * Attaches a social profile to an application
224
     * @throws \InvalidArgumentException
225
     *
226
     * @return array
227
     */
228
    public function socialProfileAction()
229
    {
230
        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...
231
            $repositories = $this->getServiceLocator()->get('repositories');
232
            $repo = $repositories->get('Applications/Application');
233
            $profile = $repo->findProfile($this->params()->fromQuery('spId'));
234
            if (!$profile) {
235
                throw new \InvalidArgumentException('Could not find profile.');
236
            }
237
        } 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...
238
                   && ($network = $this->params()->fromQuery('network'))
239
                   && ($data    = $this->params()->fromPost('data'))
240
        ) {
241
            $profileClass = '\\Auth\\Entity\\SocialProfiles\\' . $network;
242
            $profile      = new $profileClass();
243
            $profile->setData(\Zend\Json\Json::decode($data, \Zend\Json\Json::TYPE_ARRAY));
244
        } else {
245
            throw new \RuntimeException(
246
                'Missing arguments. Either provide "spId" as Get or "network" and "data" as Post.'
247
            );
248
        }
249
        
250
        return array(
251
            'profile' => $profile
252
        );
253
    }
254
255
    /**
256
     * Changes the status of an application
257
     *
258
     * @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...
259
     */
260
    public function statusAction()
261
    {
262
        $applicationId = $this->params('id');
263
        /* @var \Applications\Repository\Application $repository */
264
        $repository    = $this->getServiceLocator()->get('repositories')->get('Applications/Application');
265
        /* @var Application $application */
266
        $application   = $repository->find($applicationId);
267
268
        /* @var Request $request */
269
        $request = $this->getRequest();
270
271
        if (!$application) {
272
            throw new \InvalidArgumentException('Could not find application.');
273
        }
274
        
275
        $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...
276
        
277
        $jsonFormat    = 'json' == $this->params()->fromQuery('format');
278
        $status        = $this->params('status', Status::CONFIRMED);
279
        $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...
280
        
281
        if (in_array($status, array(Status::INCOMING))) {
282
            $application->changeStatus($status);
283
            if ($request->isXmlHttpRequest()) {
284
                $response = $this->getResponse();
285
                $response->setContent('ok');
286
                return $response;
287
            }
288
            if ($jsonFormat) {
289
                return array(
290
                    'status' => 'success',
291
                );
292
            }
293
            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...
294
        }
295
296
        $events = $this->getServiceLocator()->get('Applications/Events');
297
298
        /* @var ApplicationEvent $event */
299
        $event = $events->getEvent(ApplicationEvent::EVENT_APPLICATION_STATUS_CHANGE,
300
                                   $this,
301
                                   [
302
                                       'application' => $application,
303
                                       'status' => $status,
304
                                       'user' => $this->auth()->getUser(),
305
                                   ]
306
        );
307
308
        $event->setIsPostRequest($request->isPost());
309
        $event->setPostData($request->getPost());
310
        $events->trigger($event);
311
312
        $params = $event->getFormData();
313
314
315
        if ($request->isPost()) {
316
317
            if ($jsonFormat) {
318
                return array(
319
                    'status' => 'success',
320
                );
321
            }
322
            $this->notification()->success($event->getNotification());
323
            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...
324
        }
325
326
        if ($jsonFormat) {
327
            return $params;
328
        }
329
330
        /* @var \Applications\Form\Mail $form */
331
        $form = $this->getServiceLocator()->get('FormElementManager')->get('Applications/Mail');
332
        $form->populateValues($params);
333
334
335
336
        $reciptient = $params['to'];
337
338
        return [
339
            'recipient' => $reciptient,
340
            'form' => $form
341
        ];
342
    }
343
    
344
    /**
345
     * Forwards an application via Email
346
     *
347
     * @throws \InvalidArgumentException
348
     * @return \Zend\View\Model\JsonModel
349
     */
350
    public function forwardAction()
351
    {
352
        $services     = $this->getServiceLocator();
353
        $emailAddress = $this->params()->fromQuery('email');
354
        /* @var \Applications\Entity\Application $application */
355
        $application  = $services->get('repositories')->get('Applications/Application')
356
                                 ->find($this->params('id'));
357
        
358
        $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...
359
        
360
        $translator   = $services->get('translator');
361
         
362
        if (!$emailAddress) {
363
            throw new \InvalidArgumentException('An email address must be supplied.');
364
        }
365
        
366
        $params = array(
367
            'ok' => true,
368
            'text' => sprintf($translator->translate('Forwarded application to %s'), $emailAddress)
369
        );
370
        
371
        try {
372
            $userName    = $this->auth('info')->displayName;
0 ignored issues
show
Bug introduced by
The property displayName does not seem to exist in Auth\Controller\Plugin\Auth.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
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...
373
            $fromAddress = $application->getJob()->getContactEmail();
374
            $mailOptions = array(
375
                'application' => $application,
376
                'to'          => $emailAddress,
377
                'from'        => array($fromAddress => $userName)
378
            );
379
            $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...
380
            $this->notification()->success($params['text']);
381
        } catch (\Exception $ex) {
382
            $params = array(
383
                'ok' => false,
384
                'text' => sprintf($translator->translate('Forward application to %s failed.'), $emailAddress)
385
            );
386
            $this->notification()->error($params['text']);
387
        }
388
        $application->changeStatus($application->getStatus(), $params['text']);
389
        return new JsonModel($params);
390
    }
391
392
    /**
393
     * Deletes an application
394
     *
395
     * @return array|\Zend\Http\Response
396
     */
397
    public function deleteAction()
398
    {
399
        $id          = $this->params('id');
400
        $services    = $this->getServiceLocator();
401
        $repositories= $services->get('repositories');
402
        $repository  = $repositories->get('Applications/Application');
403
        $application = $repository->find($id);
404
        
405
        if (!$application) {
406
            throw new \DomainException('Application not found.');
407
        }
408
409
        $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...
410
411
        $events   = $services->get('Applications/Events');
412
        $events->trigger(ApplicationEvent::EVENT_APPLICATION_PRE_DELETE, $this, [ 'application' => $application ]);
413
        
414
        $repositories->remove($application);
415
        
416
        if ('json' == $this->params()->fromQuery('format')) {
417
            return ['status' => 'success'];
418
        }
419
        
420
        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...
421
    }
422
}
423