Completed
Push — develop ( d50679...312a9e )
by
unknown
08:47
created

ApplyController::processAction()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 42
Code Lines 29

Duplication

Lines 17
Ratio 40.48 %
Metric Value
dl 17
loc 42
rs 8.439
cc 6
eloc 29
nc 16
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 controllers */
11
namespace Applications\Controller;
12
13
use Applications\Entity\Contact;
14
use Zend\Mvc\Controller\AbstractActionController;
15
use Zend\Mvc\MvcEvent;
16
use Applications\Entity\Application;
17
use Zend\View\Model\ViewModel;
18
use Auth\Entity\AnonymousUser;
19
use Zend\View\Model\JsonModel;
20
use Core\Form\Container;
21
use Core\Form\SummaryForm;
22
use Core\Entity\PermissionsInterface;
23
use Applications\Entity\Status;
24
use Applications\Entity\StatusInterface;
25
26
/**
27
 * there are basically two ways to use this controller,
28
 * (1) either you have a form, and want to accumulate inputs, or you want to create a form on an existing or new application
29
 * (2) or want to do some action on a concrete form.
30
 *
31
 * for both you need the applyId, which is NOT the application-id, the applyId is an alias for the Job, it can be some human-readable text or an external ID.
32
 * the application to an applyId is found by the combination of the user and the job, that is represented by the applyId.
33
 * this approach ensures, that applications stick to the related job.
34
 *
35
 * nonetheless, there is an exception, for the posts for updating the application, the application-id is needed.
36
 *
37
 * if you use the do as query-parameter, you have to customize the do-Action for the special purpose that is assigned to the do parameter in the query
38
 *
39
 * @method \Auth\Controller\Plugin\Auth auth()
40
 * @author Mathias Gelhausen <[email protected]>
41
 */
42
class ApplyController extends AbstractActionController
43
{
44
    
45
    protected $container;
46
    
47
    public function attachDefaultListeners()
48
    {
49
        parent::attachDefaultListeners();
50
        $events = $this->getEventManager();
51
        $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'preDispatch'), 10);
52
        $serviceLocator  = $this->getServiceLocator();
53
        $defaultServices = $serviceLocator->get('DefaultListeners');
54
        $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...
55
        return $this;
56
    }
57
    
58
    public function preDispatch(MvcEvent $e)
59
    {
60
        /* @var $application \Applications\Entity\Application */
61
        if ($this->params()->fromQuery('do')) {
62
            $e->getRouteMatch()->setParam('action', 'do');
63
            return;
64
        }
65
66
        /* @var $request    \Zend\Http\Request */
67
        /* @var $repository \Applications\Repository\Application */
68
        /* @var $container  \Applications\Form\Apply */
69
        $request      = $this->getRequest();
70
        $services     = $this->getServiceLocator();
71
        $repositories = $services->get('repositories');
72
        $repository   = $repositories->get('Applications/Application');
73
        $container    = $services->get('forms')->get('Applications/Apply');
74
        
75
        if ($request->isPost()) {
76
            $appId = $this->params()->fromPost('applicationId');
77
            if (!$appId) {
78
                throw new \RuntimeException('Missing application id.');
79
            }
80
            $routeMatch = $e->getRouteMatch();
81
82
            if ('recruiter-preview' == $appId) {
83
                $routeMatch->setParam('action', 'process-preview');
84
                return;
85
            }
86
87
            $application = $repository->find($appId);
88
            if (!$application) {
89
                throw new \RuntimeException('Invalid application id.');
90
            }
91
92
            $action     = 'process';
93
94
            $routeMatch->setParam('action', $action);
95
            
96
        } else {
97
            $user  = $this->auth()->getUser();
98
            $appId = $this->params('applyId');
99
            if (!$appId) {
100
                throw new \RuntimeException('Missing apply id');
101
            }
102
103
            /* @var \Jobs\Entity\Job $job */
104
            $job = $repositories->get('Jobs/Job')->findOneByApplyId($appId);
105
106
            if (!$job) {
107
                $e->getRouteMatch()->setParam('action', 'job-not-found');
108
                return;
109
            }
110
111
            switch($job->getStatus()){
112
                case \Jobs\Entity\Status::ACTIVE:
113
                    break;
114
                default:
115
                    $e->getRouteMatch()->setParam('action', 'job-not-found');
116
                    return;
117
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
118
            }
119
120
            if ($user === $job->getUser()) {
121
                $application = new \Applications\Entity\Application();
122
                $application->setContact(new Contact());
123
                $application->setJob($job);
124
                $application->setId('recruiter-preview');
125
            } else {
126
                $subscriberUri = $this->params()->fromQuery('subscriber');
127
                $application   = $repository->findDraft($user, $appId);
128
129
                if ($application) {
130
                    /* @var $form \Auth\Form\UserInfo */
131
                    $form = $container->getForm('contact.contact');
132
                    $form->setDisplayMode('summary');
133
134
                    if ($subscriberUri) {
135
                        $subscriber = $application->getSubscriber();
136
                        if (!$subscriber || $subscriber->uri != $subscriberUri) {
137
                            $subscriber = $repositories->get('Applications/Subscriber')->findbyUri($subscriberUri, /*create*/ true);
138
                            $application->setSubscriber($subscriber);
139
                            $subscriber->getname();
140
                        }
141
                    }
142
143
                } else {
144
                    if (!$job) {
145
                        $e->getRouteMatch()->setParam('action', 'job-not-found');
146
                        return;
147
                    }
148
                    if ($job->getUriApply()) {
149
                        return $this->redirect($job->getUriApply());
0 ignored issues
show
Unused Code introduced by
The call to ApplyController::redirect() has too many arguments starting with $job->getUriApply().

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...
150
                    }
151
152
                    /* @var $application \Applications\Entity\Application */
153
                    $application = $repository->create();
154
                    $application->setIsDraft(true)
155
                                ->setContact($user->getInfo())
156
                                ->setUser($user)
157
                                ->setJob($job);
158
159
                    if ($subscriberUri) {
160
                        $subscriber = $repositories->get('Applications/Subscriber')->findbyUri($subscriberUri, /*create*/ true);
161
                        $application->setSubscriber($subscriber);
162
                    }
163
164
                    $repositories->store($application);
165
                    /*
166
                     * If we had copy an user image, we need to refresh its data
167
                     * to populate the length property.
168
                     */
169
                    if ($image = $application->contact->image) {
0 ignored issues
show
Documentation introduced by
The property $contact is declared protected in Applications\Entity\Application. 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...
Documentation introduced by
The property $image is declared protected in Applications\Entity\Contact. 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...
170
                        $repositories->refresh($image);
171
                    }
172
                }
173
            }
174
        }
175
        
176
        $container->setEntity($application);
177
        $this->configureContainer($container);
178
        $this->container = $container;
179
    }
180
    
181
    public function jobNotFoundAction()
182
    {
183
        $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...
184
        $model = new ViewModel(
185
            [ 'content' => /*@translate*/ 'Invalid apply id']
186
        );
187
        $model->setTemplate('applications/error/not-found');
188
        return $model;
189
    }
190
    
191
    public function indexAction()
192
    {
193
        $form        = $this->container;
194
        $application = $form->getEntity();
195
        
196
        $this->container->setParam('applicationId', $application->id);
197
198
        $model = new ViewModel(
199
            array(
200
            'form' => $form,
201
            'isApplicationValid' => $this->checkApplication($application),
202
            'application' => $application,
203
            )
204
        );
205
        $model->setTemplate('applications/apply/index');
206
        return $model;
207
208
    }
209
210
    public function processPreviewAction()
211
    {
212
        return new JsonModel(array('valid' => false, 'errors' => array()));
213
    }
214
    
215
    public function processAction()
0 ignored issues
show
Coding Style introduced by
processAction uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
processAction uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
216
    {
217
        $formName  = $this->params()->fromQuery('form');
218
        $form      = $this->container->getForm($formName);
219
        $postData  = $form->getOption('use_post_array') ? $_POST : array();
220
        $filesData = $form->getOption('use_files_array') ? $_FILES : array();
221
        $data      = array_merge($postData, $filesData);
222
223
        $form->setData($data);
224
        
225 View Code Duplication
        if (!$form->isValid()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
226
            return new JsonModel(
227
                array(
228
                'valid' => false,
229
                'errors' => $form->getMessages(),
230
                )
231
            );
232
        }
233
        $application = $this->container->getEntity();
234
        $this->getServiceLocator()->get('repositories')->store($application);
235
        
236
        if ('file-uri' === $this->params()->fromPost('return')) {
237
            $basepath = $this->getServiceLocator()->get('ViewHelperManager')->get('basepath');
238
            $content = $basepath($form->getHydrator()->getLastUploadedFile()->getUri());
239 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
240
            if ($form instanceof SummaryForm) {
241
                $form->setRenderMode(SummaryForm::RENDER_SUMMARY);
242
                $viewHelper = 'summaryform';
243
            } else {
244
                $viewHelper = 'form';
245
            }
246
            $content = $this->getServiceLocator()->get('ViewHelperManager')->get($viewHelper)->__invoke($form);
247
        }
248
        
249
        return new JsonModel(
250
            array(
251
            'valid' => $form->isValid(),
252
            'content' => $content,
253
            'isApplicationValid' => $this->checkApplication($application)
254
            )
255
        );
256
    }
257
    
258
    public function doAction()
259
    {
260
        $services     = $this->getServiceLocator();
261
        $config       = $services->get('Config');
262
        $repositories = $services->get('repositories');
263
        $repository   = $repositories->get('Applications/Application');
264
        $application  = $repository->findDraft(
265
            $this->auth()->getUser(),
266
            $this->params('applyId')
267
        );
268
        
269
        if (!$application) {
270
            throw new \Exception('No application draft found.');
271
        }
272
        
273
        if ('abort' == $this->params()->fromQuery('do')) {
274
            $repositories->remove($application);
275
            return $this->redirect()->toRoute('lang/apply', array('applyId' => $this->params('applyId')));
276
        }
277
        
278
        if (!$this->checkApplication($application)) {
279
            $this->notification()->error(/*@translate*/ 'There are missing required informations. Your application cannot be send.');
0 ignored issues
show
Documentation Bug introduced by
The method notification does not exist on object<Applications\Controller\ApplyController>? 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...
280
            return $this->redirect()->toRoute('lang/apply', array('applyId' => $this->params('applyId')));
281
        }
282
283
        if ('sendmail' == $this->params()->fromQuery('do')) {
284
            $jobEntity         = $application->job;
285
            ;
286
            $mailData = array(
287
                'application' => $application,
288
                'to'          => $jobEntity->contactEmail
289
            );
290 View Code Duplication
            if (array_key_exists('mails', $config) && array_key_exists('from', $config['mails']) && array_key_exists('email', $config['mails']['from'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
291
                $mailData['from'] = $config['mails']['from']['email'];
292
            }
293
            $this->mailer('Applications/CarbonCopy', $mailData, true);
0 ignored issues
show
Documentation Bug introduced by
The method mailer does not exist on object<Applications\Controller\ApplyController>? 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...
294
            $repositories->remove($application);
295
            //$this->notification()->success(/*@translate*/ 'Application has been send.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
296
            $model = new ViewModel(
297
                array(
298
                'success' => true,
299
                'job' => $jobEntity,
300
                )
301
            );
302
            $model->setTemplate('applications/apply/success');
303
            return $model;
304
        }
305
306
        $application->setIsDraft(false)
307
                    ->setStatus(new Status())
308
                    ->getPermissions()
309
                        ->revoke($this->auth()->getUser(), PermissionsInterface::PERMISSION_CHANGE)
310
                        ->inherit($application->getJob()->getPermissions());
311
312
        $this->sendRecruiterMails($application);
313
        $this->sendUserMails($application);
314
315
        $model = new ViewModel(
316
            array(
317
            'success' => true,
318
            'application' => $application,
319
            )
320
        );
321
        $model->setTemplate('applications/apply/index');
322
323
        return $model;
324
    }
325
    
326
    
327
    
328
    protected function checkApplication($application)
329
    {
330
        return $this->getServiceLocator()->get('validatormanager')->get('Applications/Application')
331
                    ->isValid($application);
332
    }
333
    
334
    protected function sendRecruiterMails($application)
335
    {
336
        $job = $application->getJob();
337
        $recruiter = $this->getServiceLocator()
338
                          ->get('repositories')
339
                          ->get('Auth/User')->findOneByEmail($job->contactEmail);
340
        
341 View Code Duplication
        if (!$recruiter) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
342
            $recruiter = $job->user;
343
            $admin     = false;
344
        } else {
345
            $admin     = $job->user;
346
        }
347
        
348
        $settings = $recruiter->getSettings('Applications');
349
        if ($settings->getMailAccess()) {
350
            $this->mailer('Applications/NewApplication', array('job' => $job, 'user' => $recruiter, 'admin' => $admin), /*send*/ true);
0 ignored issues
show
Documentation Bug introduced by
The method mailer does not exist on object<Applications\Controller\ApplyController>? 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...
351
        }
352 View Code Duplication
        if ($settings->getAutoConfirmMail()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
353
            $ackBody = $settings->getMailConfirmationText();
354
            if (empty($ackBody)) {
355
                $ackBody = $job->user->getSettings('Applications')->getMailConfirmationText();
356
            }
357
            if (!empty($ackBody)) {
358
                /* Acknowledge mail to applier */
359
                $ackMail = $this->mailer(
0 ignored issues
show
Documentation Bug introduced by
The method mailer does not exist on object<Applications\Controller\ApplyController>? 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...
360
                    'Applications/Confirmation',
361
                    array('application' => $application,
362
                        'body' => $ackBody,
363
                    )
364
                );
365
                // Must be called after initializers in creation
366
                $ackMail->setSubject(/*@translate*/ 'Application confirmation');
367
                $ackMail->setFrom($recruiter->getInfo()->getEmail());
368
                $this->mailer($ackMail);
0 ignored issues
show
Documentation Bug introduced by
The method mailer does not exist on object<Applications\Controller\ApplyController>? 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...
369
                $application->changeStatus(StatusInterface::CONFIRMED, sprintf('Mail was sent to %s', $application->contact->email));
370
            }
371
        }
372
        
373
    }
374
    
375
    protected function sendUserMails($application)
376
    {
377
        if ($application->getAttributes()->getSendCarbonCopy()) {
378
            $this->mailer(
0 ignored issues
show
Documentation Bug introduced by
The method mailer does not exist on object<Applications\Controller\ApplyController>? 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...
379
                'Applications/CarbonCopy',
380
                array(
381
                    'application' => $application,
382
                ), /*send*/
383
                true
384
            );
385
        }
386
    }
387
388
    /**
389
     * Configures the apply form container.
390
     *
391
     * Currently only disables elements.
392
     *
393
     * @param Container $container
394
     */
395
    protected function configureContainer(Container $container)
396
    {
397
        /* @var $application Application */
398
        $application = $container->getEntity();
399
        $job         = $application->getJob();
400
401
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
402
         * @TODO: Implement disable elements logic in entities, etc.
403
         *
404
405
406
        $config = $job->getApplyFormElementsConfig();
407
        if ($config) {
408
            $container->disableElements($config);
409
            return;
410
        }
411
412
        $config = $job->getOrganization()->getApplyFormElementsConfig();
413
        if ($config) {
414
            $container->disableElements($config);
415
            return;
416
        }
417
        */
418
419
        /** @var $settings \Applications\Entity\Settings */
420
        $settings = $job->getUser()->getSettings('Applications');
421
        $formSettings = $settings->getApplyFormSettings();
422
423
        if ($formSettings && $formSettings->isActive()) {
424
            $container->disableElements($formSettings->getDisableElements());
425
            return;
426
        }
427
428
        $config = $this->getServiceLocator()->get('Config');
429
        $config = isset($config['form_elements_config']['Applications/Apply']['disable_elements'])
430
                ? $config['form_elements_config']['Applications/Apply']['disable_elements']
431
                : null;
432
        if ($config) {
433
            $container->disableElements($config);
434
        }
435
    }
436
}
437