Completed
Pull Request — master (#4)
by Timothy
04:00
created

AbstractCheckCommandFactory::createService()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 26
Code Lines 16

Duplication

Lines 14
Ratio 53.85 %

Code Coverage

Tests 19
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 14
loc 26
ccs 19
cts 19
cp 1
rs 8.439
cc 5
eloc 16
nc 3
nop 1
crap 5
1
<?php
2
3
namespace Abacaphiliac\DoctrineORMDiagnosticsModule;
4
5
use DoctrineModule\Component\Console\Input\RequestInput;
6
use DoctrineModule\Component\Console\Output\PropertyOutput;
7
use Symfony\Component\Console\Application;
8
use Symfony\Component\Console\Command\Command;
9
use Zend\Console\Request;
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
13
abstract class AbstractCheckCommandFactory implements FactoryInterface
14
{
15
    /**
16
     * Create service
17
     *
18
     * @param ServiceLocatorInterface $serviceLocator
19
     * @return CheckCommand
20
     * @throws \UnexpectedValueException
21
     * @throws \Zend\Console\Exception\RuntimeException
22
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
23
     */
24 10
    public function createService(ServiceLocatorInterface $serviceLocator)
25 1
    {
26 10
        $cli = $serviceLocator->get('doctrine.cli');
27 10 View Code Duplication
        if (!$cli instanceof Application) {
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...
28 1
            throw new \UnexpectedValueException(sprintf(
29 1
                'Expected type [%s]. Actual type [%s].',
30 1
                Application::class,
31 1
                is_object($cli) ? get_class($cli) : gettype($cli)
32 1
            ));
33
        }
34
35 9
        $command = $serviceLocator->get($this->getCommandServiceName());
36 9 View Code Duplication
        if (!$command instanceof Command) {
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...
37 1
            throw new \UnexpectedValueException(sprintf(
38 1
                'Expected type [%s]. Actual type [%s].',
39 1
                Command::class,
40 1
                is_object($command) ? get_class($command) : gettype($command)
41 1
            ));
42
        }
43
        
44 8
        $input = new RequestInput(new Request(array()));
45
        
46 8
        $output = new PropertyOutput();
47
        
48 8
        return new CheckCommand($command, $input, $output);
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    abstract public function getCommandServiceName();
55
}
56