Passed
Push — master ( 59eb56...63534b )
by Mathias
09:13
created

__invoke()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 52
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.7898

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 52
ccs 5
cts 9
cp 0.5556
rs 9.488
c 0
b 0
f 0
cc 3
nc 1
nop 3
crap 3.7898

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
10
namespace Jobs\Factory\Controller;
11
12
use Interop\Container\ContainerInterface;
13
use Jobs\Controller\ApiJobListByOrganizationController;
14
use Jobs\Entity\StatusInterface;
15
16
use Zend\ServiceManager\Factory\FactoryInterface;
17
use Zend\InputFilter\InputFilter;
18
19
class ApiJobListByOrganizationControllerFactory implements FactoryInterface
20
{
21
    /**
22
     * Create an object
23
     *
24
     * @param  ContainerInterface $container
25
     * @param  string             $requestedName
26
     * @param  null|array         $options
27
     *
28
     * @return object
29
     */
30 1
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
31
    {
32
        /** @var \Jobs\Repository\Job $jobRepository */
33 1
        $jobRepository = $container->get('repositories')->get('Jobs/Job');
34
35
        /** @var \Jobs\Model\ApiJobDehydrator $apiJobDehydrator */
36 1
        $apiJobDehydrator = $container->get('Jobs\Model\ApiJobDehydrator');
37
38 1
        $filterStatus = function ($value) {
39
            static $validValues = [
40
                StatusInterface::ACTIVE,
41
                StatusInterface::CREATED,
42
                StatusInterface::PUBLISH,
43
                StatusInterface::EXPIRED,
44
                StatusInterface::REJECTED,
45
                StatusInterface::INACTIVE
46
            ];
47
48
            if ('all' == $value) {
49
                return true;
50
            }
51
52
            return in_array($value, $validValues) ? $value : StatusInterface::ACTIVE;
53 1
        };
54
55
        $inputFilter = new InputFilter();
56
        $inputFilter->add(
57
            [
58
                'name' => 'callback',
59
                'filters'  => [
60
                    ['name' => 'StringTrim'],
61
                    ['name' => 'Alpha'],
62
                ],
63
            ]
64
        );
65
        $inputFilter->add(
66
            [
67
                'name' => 'status',
68
                'filters' => [
69
                    [
70
                        'name' => 'Callback',
71
                        'options' => [
72
                            'callback' => $filterStatus
73
                        ],
74
                    ],
75
                ],
76
            ]
77
        );
78
79
        $controller = new ApiJobListByOrganizationController($jobRepository, $apiJobDehydrator, $inputFilter);
80
81
        return $controller;
82
    }
83
}
84