Completed
Push — develop ( 312a9e...d5555a )
by
unknown
08:15
created

IndexController   C

Complexity

Total Complexity 44

Size/Duplication

Total Lines 323
Duplicated Lines 23.84 %

Coupling/Cohesion

Components 1
Dependencies 19

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 44
c 1
b 0
f 1
lcom 1
cbo 19
dl 77
loc 323
rs 5.5062

4 Methods

Rating   Name   Duplication   Size   Complexity  
A attachDefaultListeners() 0 9 1
F indexAction() 50 218 31
B dashboardAction() 24 24 3
C mailAction() 3 47 9

How to fix   Duplicated Code    Complexity   

Duplicated Code

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

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like IndexController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use IndexController, and based on these observations, apply Extract Interface, too.

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 Auth\Entity\Info;
14
use Applications\Entity\Application;
15
use Zend\Http\Request;
16
use Zend\Mvc\Controller\AbstractActionController;
17
use Zend\View\Model\ViewModel;
18
use Zend\View\Model\JsonModel;
19
use Applications\Entity\Status;
20
use Applications\Entity\StatusInterface;
21
22
/**
23
 * Main Action Controller for Applications module.
24
 *
25
 * @method \Core\Controller\Plugin\Notification notification()
26
 * @method \Core\Controller\Plugin\CreatePaginator paginator()
27
 * @method \Auth\Controller\Plugin\Auth auth()
28
 * @method \Acl\Controller\Plugin\Acl acl()
29
 */
30
class IndexController extends AbstractActionController
31
{
32
    /**
33
     * attaches further Listeners for generating / processing the output
34
     * @return $this
35
     */
36
    public function attachDefaultListeners()
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
    /**
48
     * Processes formular data of the application form
49
     *
50
     * @return \Zend\View\Model\ViewModel
51
     */
52
    public function indexAction()
53
    {
54
        $services = $this->getServiceLocator();
55
        /** @var Request $request */
56
        $request = $this->getRequest();
57
58
        $jobId = $this->params()->fromPost('jobId', 0);
59
        $applyId = (int) $this->params()->fromPost('applyId', 0);
60
        
61
        // subscriber comes from the form
62
        $subscriberUri = $this->params()->fromPost('subscriberUri', '');
63
        if (empty($subscriberUri)) {
64
            // subscriber comes with the request of the form
65
            // which implies that the backlink in the job-offer had such an link in the query
66
            $subscriberUri = $this->params()->fromQuery('subscriberUri', '');
67
        }
68
        if (empty($subscriberUri)) {
69
            // the subscriber comes from an external module, maybe after interpreting the backlink, or the referer
70
            $e = $this->getEvent();
71
            $subscriberResponseCollection = $this->getEventManager()->trigger('subscriber.getUri', $e);
72
            if (!$subscriberResponseCollection->isEmpty()) {
73
                $subscriberUri = $subscriberResponseCollection->last();
74
            }
75
        }
76
77
78
        $job = ($request->isPost() && !empty($jobId))
79
             ? $services->get('repositories')->get('Jobs/Job')->find($jobId)
80
             : $services->get('repositories')->get('Jobs/Job')->findOneBy(array("applyId"=>(0 == $applyId)?$this->params('jobId'):$applyId));
81
        
82
        
83 View Code Duplication
        if (!$job) {
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...
84
            $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...
85
            $model = new ViewModel(
86
                array(
87
                'content' => /*@translate*/ 'Invalid apply id'
88
                )
89
            );
90
            $model->setTemplate('auth/index/job-not-found.phtml');
91
            return $model;
92
        }
93
94
        /* @var $form \Zend\Form\Form */
95
        $form = $services->get('FormElementManager')->get('Application/Create');
96
        $form->setValidate();
97
        
98
        $viewModel = new ViewModel();
99
        $viewModel->setVariables(
100
            array(
101
            'job' => $job,
102
            'form' => $form,
103
            'isApplicationSaved' => false,
104
            'subscriberUri' => $subscriberUri,
105
            )
106
        );
107
        
108
        $applicationEntity = new Application();
109
        $applicationEntity->setJob($job);
110
111
        if ($this->auth()->isLoggedIn()) {
112
            // copy the contact info into the application
113
            $contact = new Info();
114
            $contact->fromArray(Info::toArray($this->auth()->get('info')));
0 ignored issues
show
Bug introduced by
The method toArray() does not seem to exist on object<Auth\Entity\Info>.

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...
Bug introduced by
The method fromArray() does not seem to exist on object<Auth\Entity\Info>.

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...
115
            $applicationEntity->setContact($contact);
116
        }
117
        
118
        $form->bind($applicationEntity);
119
        $form->get('jobId')->setValue($job->id);
120
        $form->get('subscriberUri')->setValue($subscriberUri);
121
       
122
        if ($request->isPost()) {
123
            if ($returnTo = $this->params()->fromPost('returnTo', false)) {
124
                $returnTo = \Zend\Uri\UriFactory::factory($returnTo);
125
            }
126
            $services = $this->getServiceLocator();
127
128
            $data = array_merge_recursive(
129
                $this->request->getPost()->toArray(),
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 getPost() 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...
130
                $this->request->getFiles()->toArray()
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 getFiles() 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...
131
            );
132
            
133
            if (!empty($subscriberUri) && $request->isPost()) {
134
                $subscriber = $services->get('repositories')->get('Applications/Subscriber')->findbyUriOrCreate($subscriberUri);
135
                $applicationEntity->subscriber = $subscriber;
0 ignored issues
show
Documentation introduced by
The property $subscriber is declared protected in Applications\Entity\Application. Since you implemented __set(), maybe consider adding a @property or @property-write 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...
136
            }
137
            
138
            $form->setData($data);
139
            
140
            if (!$form->isValid()) {
141
                if ($request->isXmlHttpRequest()) {
142
                    return new JsonModel(
143
                        array(
144
                        'ok' => false,
145
                        'messages' => $form->getMessages()
146
                        )
147
                    );
148
                }
149 View Code Duplication
                if ($returnTo) {
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...
150
                    $returnTo->setQuery($returnTo->getQueryAsArray() + array('status' => 'failure'));
151
                    return $this->redirect()->toUrl((string) $returnTo);
152
                }
153
                $this->notification()->error(/*@translate*/ 'There were errors in the form.');
154
155
            } else {
156
                $auth = $this->auth();
157
            
158
                if ($auth->isLoggedIn()) {
159
                    // in instance user is logged in,
160
                    // and no image is uploaded
161
                    // take his profile-image as copy
162
                    $applicationEntity->setUser($auth->getUser());
163
                    $imageData = $form->get('contact')->get('image')->getValue();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Form\ElementInterface as the method get() does only exist in the following implementations of said interface: Applications\Form\Apply, Applications\Form\Attributes, Applications\Form\Base, Applications\Form\BaseFieldset, Applications\Form\CarbonCopyFieldset, Applications\Form\CommentForm, Applications\Form\ContactContainer, Applications\Form\Facts, Applications\Form\FactsFieldset, Applications\Form\FilterApplication, Applications\Form\Mail, Applications\Form\SettingsFieldset, Auth\Form\ForgotPassword, Auth\Form\Group, Auth\Form\GroupFieldset, Auth\Form\GroupUsersCollection, Auth\Form\Login, Auth\Form\Register, Auth\Form\SocialProfiles, Auth\Form\SocialProfilesFieldset, Auth\Form\UserBase, Auth\Form\UserBaseFieldset, Auth\Form\UserInfo, Auth\Form\UserInfoContainer, Auth\Form\UserInfoFieldset, Auth\Form\UserPassword, Auth\Form\UserPasswordFieldset, Auth\Form\UserProfileContainer, Core\Form\BaseForm, Core\Form\ButtonsFieldset, Core\Form\Container, Core\Form\DefaultButtonsFieldset, Core\Form\Form, Core\Form\FormSubmitButtonsFieldset, Core\Form\ListFilterButtonsFieldset, Core\Form\LocalizationSettingsFieldset, Core\Form\PermissionsCollection, Core\Form\PermissionsFieldset, Core\Form\RatingFieldset, Core\Form\SummaryForm, Core\Form\SummaryFormButtonsFieldset, Core\Form\ViewPartialProviderAbstract, Cv\Form\Cv, Cv\Form\CvFieldset, Cv\Form\EducationFieldset, Cv\Form\EmploymentFieldset, Cv\Form\LanguageFieldset, Cv\Form\NativeLanguageFieldset, Cv\Form\SkillFieldset, Install\Form\Installation, Jobs\Form\AtsMode, Jobs\Form\AtsModeFieldset, Jobs\Form\Base, Jobs\Form\BaseFieldset, Jobs\Form\CompanyName, Jobs\Form\CompanyNameFieldset, Jobs\Form\Import, Jobs\Form\ImportFieldset, Jobs\Form\Job, Jobs\Form\JobDescription, Jobs\Form\JobDescriptionBenefits, Jobs\Form\JobDescriptionDescription, Jobs\Form\JobDescriptionFieldset, Jobs\Form\JobDescriptionQualifications, Jobs\Form\JobDescriptionRequirements, Jobs\Form\JobDescriptionTemplate, Jobs\Form\JobDescriptionTitle, Jobs\Form\ListFilter, Jobs\Form\ListFilterAdminFieldset, Jobs\Form\ListFilterBaseFieldset, Jobs\Form\ListFilterLocationFieldset, Jobs\Form\ListFilterPersonalFieldset, Jobs\Form\Multipost, Jobs\Form\MultipostButtonFieldset, Jobs\Form\MultipostFieldset, Jobs\Form\Preview, Jobs\Form\PreviewFieldset, Jobs\Form\TemplateLabelBenefits, Jobs\Form\TemplateLabelQualifications, Jobs\Form\TemplateLabelRequirements, Organizations\Form\EmployeeFieldset, Organizations\Form\Employees, Organizations\Form\EmployeesFieldset, Organizations\Form\Organizations, Organizations\Form\OrganizationsContactFieldset, Organizations\Form\OrganizationsContactForm, Organizations\Form\Organ...ionsDescriptionFieldset, Organizations\Form\OrganizationsDescriptionForm, Organizations\Form\OrganizationsFieldset, Organizations\Form\OrganizationsNameFieldset, Organizations\Form\OrganizationsNameForm, Settings\Form\AbstractSettingsForm, Settings\Form\DisableEle...bleFormSettingsFieldset, Settings\Form\FormAbstract, Settings\Form\Settings, Settings\Form\SettingsFieldset, Zend\Form\Element\Collection, Zend\Form\Fieldset, Zend\Form\Form, Zend\Form\InputFilterProviderFieldset.

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...
164
                    if (UPLOAD_ERR_NO_FILE == $imageData['error']) {
165
                        // has the user an image
166
                        $image = $auth->getUser()->info->image;
0 ignored issues
show
Bug introduced by
Accessing info on the interface Auth\Entity\UserInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
167
                        if ($image) {
168
                            $repositoryAttachment = $services->get('repositories')->get('Applications/Attachment');
169
170
                            // this should provide a real copy, not just a reference
171
                            $contactImage = $repositoryAttachment->copy($image);
172
                            $applicationEntity->contact->setImage($contactImage);
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...
173
                        } else {
174
                            $applicationEntity->contact->setImage(null); //explicitly remove 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...
175
                        }
176
                    }
177
                }
178
                
179
                if (!$request->isXmlHttpRequest()) {
180
                    $applicationEntity->setStatus(new Status());
181
                    $permissions = $applicationEntity->getPermissions();
182
                    $permissions->inherit($job->getPermissions());
183
184
                    /*
185
                     * New Application alert Mails to job recruiter
186
                     * This is temporary until Companies are implemented.
187
                     */
188
                    $recruiter = $services->get('repositories')->get('Auth/User')->findOneByEmail($job->contactEmail);
189 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...
190
                        $recruiter = $job->user;
0 ignored issues
show
Unused Code introduced by
$recruiter 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...
191
                        $admin     = false;
0 ignored issues
show
Unused Code introduced by
$admin 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...
192
                    } else {
193
                        $admin     = $job->user;
0 ignored issues
show
Unused Code introduced by
$admin 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...
194
                    }
195
                
196
                    $services->get('repositories')->store($applicationEntity);
197
                    /*
198
                     * New Application alert Mails to job recruiter
199
                     * This is temporary until Companies are implemented.
200
                     */
201
                    $recruiter = $services->get('repositories')->get('Auth/User')->findOneByEmail($job->contactEmail);
202 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...
203
                        $recruiter = $job->user;
204
                        $admin     = false;
205
                    } else {
206
                        $admin     = $job->user;
207
                    }
208
                
209
                    if ($recruiter->getSettings('Applications')->getMailAccess()) {
210
                        $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\IndexController>? 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...
211
                    }
212 View Code Duplication
                    if ($recruiter->getSettings('Applications')->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...
213
                        $ackBody = $recruiter->getSettings('Applications')->getMailConfirmationText();
214
                        if (empty($ackBody)) {
215
                            $ackBody = $job->user->getSettings('Applications')->getMailConfirmationText();
216
                        }
217
                        if (!empty($ackBody)) {
218
                            /* Acknowledge mail to the applicant */
219
                            $ackMail = $this->mailer(
0 ignored issues
show
Documentation Bug introduced by
The method mailer does not exist on object<Applications\Controller\IndexController>? 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...
220
                                'Applications/Confirmation',
221
                                array('application' => $applicationEntity,
222
                                                  'body' => $ackBody,
223
                                            )
224
                            );
225
                            // Must be called after initializers in creation
226
                            $ackMail->setSubject(/*@translate*/ 'Application confirmation');
227
                            $ackMail->setFrom($recruiter->getInfo()->getEmail());
228
                            $this->mailer($ackMail);
0 ignored issues
show
Documentation Bug introduced by
The method mailer does not exist on object<Applications\Controller\IndexController>? 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...
229
                            $applicationEntity->changeStatus(StatusInterface::CONFIRMED, sprintf('Mail was sent to %s', $applicationEntity->contact->email));
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 $email is declared protected in Auth\Entity\Info. 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...
230
                        }
231
                    }
232
233
                    // send carbon copy of the application
234
235
                    $paramsCC = $this->getRequest()->getPost('carboncopy', 0);
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 getPost() 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...
236
                    if (isset($paramsCC) && array_key_exists('carboncopy', $paramsCC)) {
237
                        $wantCarbonCopy = (int) $paramsCC['carboncopy'];
238
                        if ($wantCarbonCopy) {
239
                             $mail = $this->mailer(
0 ignored issues
show
Documentation Bug introduced by
The method mailer does not exist on object<Applications\Controller\IndexController>? 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
$mail 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
                                 'Applications/CarbonCopy',
241
                                 array(
242
                                    'application' => $applicationEntity,
243
                                    'to'          => $applicationEntity->contact->email,
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 $email is declared protected in Auth\Entity\Info. 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...
244
                                 ), /*send*/
245
                                 true
246
                             );
247
                        }
248
                    }
249
                }
250
251
                if ($request->isXmlHttpRequest()) {
252
                    return new JsonModel(
253
                        array(
254
                        'ok' => true,
255
                        'id' => $applicationEntity->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...
256
                        'jobId' => $applicationEntity->job->id,
0 ignored issues
show
Documentation introduced by
The property $job 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...
Bug introduced by
Accessing id on the interface Jobs\Entity\JobInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
257
                        )
258
                    );
259
                }
260 View Code Duplication
                if ($returnTo) {
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...
261
                    $returnTo->setQuery($returnTo->getQueryAsArray() + array('status' => 'success'));
262
                    return $this->redirect()->toUrl((string) $returnTo);
263
                }
264
                $this->notification()->success(/*@translate*/ 'your application was sent successfully');
265
                $viewModel->setVariable('isApplicationSaved', true);
266
            }
267
        }
268
        return $viewModel;
269
    }
270
    
271
    /**
272
     * Handles dashboard listings of applications
273
     *
274
     * @return array
275
     */
276 View Code Duplication
    public function dashboardAction()
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...
277
    {
278
        $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...
279
        $isRecruiter = $this->acl()->isRole('recruiter');
280
        if ($isRecruiter) {
281
            $params->set('by', 'me');
282
        }
283
284
         //default sorting
285
        if (!isset($params['sort'])) {
286
            $params['sort']="-date";
287
        }
288
        $params->count = 5;
289
        $params->pageRange=5;
290
291
        $this->paginationParams()->setParams('Applications\Index', $params);
0 ignored issues
show
Bug introduced by
The method paginationParams() does not exist on Applications\Controller\IndexController. 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...
292
293
        $paginator = $this->paginator('Applications/Application', $params);
0 ignored issues
show
Unused Code introduced by
The call to IndexController::paginator() has too many arguments starting with 'Applications/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...
294
     
295
        return array(
296
            'script' => 'applications/index/dashboard',
297
            'applications' => $paginator
298
        );
299
    }
300
301
    /**
302
     * sends a test-mail with all application-data to the applicant
303
     * @return JsonModel
304
     */
305
    public function mailAction()
306
    {
307
        $services          = $this->getServiceLocator();
308
        $config            = $services->get('Config');
309
        $applicationId     = $this->getRequest()
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...
310
                                  ->getQuery('id');
311
        $status            = $this->params('status');
312
        $repositories      = $services->get('repositories');
313
        $entityApplication = $repositories->get('Applications/Application')->find($applicationId);
314
        if (empty($entityApplication)) {
315
            $this->notification()->error(/*@translate*/ 'Application has been deleted.');
316
        } else {
317
            $jobEntity         = $entityApplication->job;
318
            $applicantEmail    = $entityApplication->contact->email;
319
            $organizationEmail = $jobEntity->contactEmail;
320
            $mailAddress        = null;
0 ignored issues
show
Unused Code introduced by
$mailAddress 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...
321
            switch ($status == 'test') {
322
                case 'company':
323
                    $mailAddress = $organizationEmail;
324
                    break;
325
                case 'test':
326
                default:
327
                    $mailAddress = $applicantEmail;
328
                    break;
329
            }
330
            if (!empty($mailAddress)) {
331
                $mailData = array(
332
                    'application' => $entityApplication,
333
                    'to'          => $mailAddress
334
                );
335 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...
336
                    $mailData['from'] = $config['mails']['from']['email'];
337
                }
338
339
                $mail = $this->mailer('Applications/CarbonCopy', $mailData, true);
0 ignored issues
show
Documentation Bug introduced by
The method mailer does not exist on object<Applications\Controller\IndexController>? 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
$mail 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...
340
                $this->notification()
341
                     ->success(/*@translate*/ 'Mail has been send');
342
                if ($status == 'company') {
343
                    $repositories->remove($entityApplication);
344
                    $this->notification()->info(/*@translate*/ 'Application data has been deleted');
345
                }
346
            } else {
347
                $this->notification()->error(/*@translate*/ 'No mail adress available');
348
            }
349
        }
350
        return new JsonModel(array());
351
    }
352
}
353