Completed
Push — master ( 670b18...db08df )
by Matthias
10s
created

MarkdownFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
crap 2
1
<?php
2
3
namespace MaglMarkdown\View\Helper;
4
5
use Interop\Container\ContainerInterface;
6
use Interop\Container\Exception\ContainerException;
7
use Zend\ServiceManager\AbstractPluginManager;
8
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
9
use Zend\ServiceManager\Exception\ServiceNotFoundException;
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
13
/**
14
 * Class MarkdownFactory
15
 *
16
 * @package MaglMarkdown\View\Helper
17
 */
18
class MarkdownFactory implements FactoryInterface
19
{
20
21
    /**
22
     * Create service
23
     *
24
     * @param ServiceLocatorInterface $serviceLocator
25
     * @return Markdown
26
     */
27 1
    public function createService(ServiceLocatorInterface $serviceLocator)
28
    {
29 1
        if ($serviceLocator instanceof AbstractPluginManager) {
30 1
            $serviceLocator = $serviceLocator->getServiceLocator() ?: $serviceLocator;
31 1
        }
32
33 1
        return $this->create($serviceLocator);
34
    }
35
36
    /**
37
     * Create an object
38
     *
39
     * @param  ContainerInterface $container
40
     * @param  string             $requestedName
41
     * @param  null|array         $options
42
     * @return Markdown
43
     * @throws \Interop\Container\Exception\NotFoundException
44
     * @throws ServiceNotFoundException if unable to resolve the service.
45
     * @throws ServiceNotCreatedException if an exception is raised when
46
     *     creating a service.
47
     * @throws ContainerException if any other error occurs
48
     */
49
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
50
    {
51
        return $this->create($container);
52
    }
53
54
    /**
55
     * @param ServiceLocatorInterface|ContainerInterface $container
56
     * @return Markdown
57
     */
58 1 View Code Duplication
    protected function create($container)
0 ignored issues
show
Duplication introduced by
This method 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...
59
    {
60 1
        if (!$container instanceof ServiceLocatorInterface && !$container instanceof ContainerInterface) {
61
            throw new \InvalidArgumentException('Invalid container to create service');
62
        }
63
64 1
        return new Markdown($container->get('MaglMarkdown\MarkdownService'));
65
    }
66
}
67