Completed
Pull Request — develop (#252)
by
unknown
07:41
created

MultimanageController::rejectApprovalAction()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 41
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
c 2
b 2
f 0
dl 0
loc 41
rs 8.5806
cc 4
eloc 29
nc 5
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/** Applications controller */
11
namespace Applications\Controller;
12
13
use Zend\Mvc\Controller\AbstractActionController;
14
use Zend\View\Model\JsonModel;
15
use Applications\Entity\StatusInterface as Status;
16
17
/**
18
 * Handles multiple actions on applications
19
 */
20
class MultimanageController extends AbstractActionController
21
{
22
23
    /**
24
     * attaches further Listeners for generating / processing the output
25
     * @return $this
26
     */
27 View Code Duplication
    public function attachDefaultListeners()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
28
    {
29
        parent::attachDefaultListeners();
30
        $serviceLocator  = $this->serviceLocator;
31
        $defaultServices = $serviceLocator->get('DefaultListeners');
32
        $events          = $this->getEventManager();
33
        $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...
34
        return $this;
35
    }
36
37
    /**
38
     * some Action on a set of applications,
39
     * as there are invite, decline, postpone, confirm
40
     *
41
     * @return \Zend\View\Model\JsonModel
42
     */
43
    public function multimodalAction()
44
    {
45
        return new JsonModel(
46
            array(
47
            'ok' => true,
48
            'action' => 'multimodal'
49
            )
50
        );
51
    }
52
53
    /**
54
     *
55
     * @TODO consolidate with Manage::status - a lot of shared code
56
     * @return \Zend\View\Model\JsonModel
57
     */
58
    public function rejectApplicationAction()
59
    {
60
        $translator        = $this->serviceLocator->get('translator');
61
        $viewHelperManager = $this->serviceLocator->get('viewHelperManager');
62
        $actionUrl         = $viewHelperManager->get('url')
63
                            ->__invoke('lang/applications/applications-list', array('action' => 'rejectApproval'));
64
        $repository        = $this->serviceLocator->get('repositories')->get('Applications/Application');
65
        $settings          = $this->settings();
0 ignored issues
show
Documentation Bug introduced by
The method settings does not exist on object<Applications\Cont...\MultimanageController>? 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...
66
        $mailService       = $this->serviceLocator->get('Core/MailService');
67
68
        // re-inject the Application-ids to the formular
69
        $elements = $this->params()->fromPost('elements', array());
70
        $hidden = '';
71
        $displayNames = array();
72
        foreach ($elements as $element) {
73
            $hidden .= '<input type="hidden" name="elements[]" value="' . $element . '">';
74
            $application = $repository->find($element);
75
            $isAllowed = $this->acl()->test($application, 'change');
0 ignored issues
show
Documentation Bug introduced by
The method acl does not exist on object<Applications\Cont...\MultimanageController>? 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...
76
            if ($isAllowed) {
77
                $contact = $application->contact;
78
                $displayNames[] = $contact->displayName;
79
            }
80
        }
81
82
        $mailService->get('Applications/StatusChange');
83
84
        $mailText = $settings->mailRejectionText ? $settings->mailRejectionText : '';
85
        $mailSubject = $translator->translate('Your application dated %s');
86
87
        // @TODO transfer into form class
88
        return new JsonModel(
89
            array(
90
            'ok' => true,
91
            'header' => $translator->translate('reject the applicants'),
92
            'content' => '<form action="' . $actionUrl . '">' .
93
            $hidden .
94
            '<input class=" form-control " name="mail-subject" value="'
95
                . $mailSubject . '"><br /><br />' .
96
            '<textarea class=" form-control " id="mail-content" name="mail-content">'
97
                . $mailText . '</textarea></form>'
98
            )
99
        );
100
    }
101
102
    /**
103
     *
104
     * @return \Zend\View\Model\JsonModel
105
     */
106
    public function rejectApprovalAction()
107
    {
108
        $translator        = $this->serviceLocator->get('translator');
109
        $repositoryService = $this->serviceLocator->get('repositories');
110
        $repository        = $repositoryService->get('Applications/Application');
111
        $mailService       = $this->serviceLocator->get('Core/MailService');
112
        $elements          = $this->params()->fromPost('elements', array());
113
        foreach ($elements as $element) {
114
            $mail = $mailService->get('Applications/StatusChange');
115
            /* @var \Applications\Entity\Application $application */
116
            $application = $repository->find($element);
117
            $mail->setApplication($application);
118
            $mail->setBody($this->params()->fromPost('mail-content'));
119
            $mailSubject = sprintf(
120
                $translator->translate($this->params()->fromPost('mail-subject')),
121
                strftime('%x', $application->dateCreated->getTimestamp())
0 ignored issues
show
Documentation introduced by
The property $dateCreated is declared protected in Core\Entity\AbstractIden...ficationDateAwareEntity. 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...
122
            );
123
            $mail->setSubject($mailSubject);
124
125
            if ($from = $application->job->contactEmail) {
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 contactEmail 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...
126
                $mail->setFrom($from, $application->job->company);
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 company 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...
127
            }
128
            if ($this->settings()->mailBCC) {
0 ignored issues
show
Documentation Bug introduced by
The method settings does not exist on object<Applications\Cont...\MultimanageController>? 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...
129
                $user = $this->auth()->getUser();
0 ignored issues
show
Documentation Bug introduced by
The method auth does not exist on object<Applications\Cont...\MultimanageController>? 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...
130
                $mail->addBcc($user->info->email, $user->info->displayName);
131
            }
132
            $mailService->send($mail);
133
134
            // update the Application-History
135
            $application->changeStatus(
136
                Status::REJECTED,
137
                sprintf(
138
                           /*@translate */ 'Mail was sent to %s',
139
                                           $application->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...
140
                )
141
            );
142
            $repositoryService->store($application);
143
            unset($mail);
144
        }
145
        return new JsonModel(array('ok' => true, ));
146
    }
147
    
148
    /**
149
     * Move given applications to Talent Pool
150
     *
151
     * @since 0.26
152
     */
153
    public function moveAction()
154
    {
155
        $ids = (array)$this->params()->fromPost('ids');
156
        $moved = 0;
157
        
158
        if ($ids) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $ids of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
159
            $serviceManager = $this->serviceLocator;
160
            $repositories = $serviceManager->get('repositories');
161
            $applicationRepository = $repositories->get('Applications/Application');
162
            $cvRepository = $repositories->get('Cv/Cv');
163
            $user = $this->auth()->getUser();
0 ignored issues
show
Documentation Bug introduced by
The method auth does not exist on object<Applications\Cont...\MultimanageController>? 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...
164
            
165
            foreach ($ids as $id) {
166
                $application = $applicationRepository->find($id);
167
                
168
                if (!$application) {
169
                    continue;
170
                }
171
                
172
                if (!$this->acl($application, 'move', 'test')) {
0 ignored issues
show
Documentation Bug introduced by
The method acl does not exist on object<Applications\Cont...\MultimanageController>? 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...
173
                    continue;
174
                }
175
                
176
                $cv = $cvRepository->createFromApplication($application, $user);
177
                $repositories->store($cv);
178
                $repositories->remove($application);
179
                $moved++;
180
            }
181
        }
182
        
183
        $this->notification()->success(
0 ignored issues
show
Documentation Bug introduced by
The method notification does not exist on object<Applications\Cont...\MultimanageController>? 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...
184
            sprintf(
185
                /*@translate */ '%d Application(s) has been successfully moved to Talent Pool',
186
                $moved
187
        ));
188
        
189
        return $this->redirect()->toRoute('lang/applications');
190
    }
191
}
192