Completed
Push — develop ( 8cb156...27be84 )
by
unknown
17:07
created

JobSelectFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 3
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Applications\Factory\Form;
12
13
use Applications\Form\Element\JobSelect;
14
use Interop\Container\ContainerInterface;
15
use Zend\ServiceManager\FactoryInterface;
16
use Zend\ServiceManager\ServiceLocatorInterface; 
17
18
/**
19
 * Factory for a job select element
20
 * 
21
 * @author Mathias Gelhausen <[email protected]>
22
 * @since 0.29.2
23
 */
24 View Code Duplication
class JobSelectFactory implements FactoryInterface
0 ignored issues
show
Duplication introduced by
This class 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...
25
{
26
    
27
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
28
    {
29
        /* @var \Zend\Http\PhpEnvironment\Request $request */
30
        $request = $container->get('Request');
31
        $query   = $request->getQuery();
32
        $jobId   = $query->get('job');
33
        $select = new JobSelect();
34
35
        if ($jobId) {
36
            /* @var \Jobs\Repository\Job $repository */
37
            $repositories = $container->get('repositories');
38
            $repository   = $repositories->get('Jobs');
39
            $job          = $repository->find($jobId);
40
            $select->setSelectedJob($job);
41
        }
42
43
        return $select;
44
    }
45
    
46
    public function createService(ServiceLocatorInterface $serviceLocator)
47
    {
48
        /* @var \Zend\ServiceManager\AbstractPluginManager $serviceLocator */
49
        return $this($serviceLocator->getServiceLocator(), JobSelect::class);
50
    }
51
}
52