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

AbstractCheckCommandFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 32.56 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 0
cbo 5
dl 14
loc 43
ccs 19
cts 19
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
getCommandServiceName() 0 1 ?
B createService() 14 26 5

How to fix   Duplicated Code   

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:

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