Completed
Push — feature/require-check ( 54e32a...842352 )
by Matthias
17:30 queued 08:06
created

createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

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