Completed
Pull Request — master (#4)
by Timothy
08:48 queued 02:25
created

AbstractCheckCommandFactory::createService()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

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