MichelfPHPMarkdownAdapterFactory::create()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 1
crap 3.072
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 MichelfPHPMarkdownAdapterFactory
14
 *
15
 * @package MaglMarkdown\Adapter
16
 */
17 View Code Duplication
class MichelfPHPMarkdownAdapterFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\FactoryInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
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 MichelfPHPMarkdownAdapter
25
     */
26 1
    public function createService(ServiceLocatorInterface $serviceLocator)
27
    {
28 1
        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 MichelfPHPMarkdownAdapter
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
     * @param ServiceLocatorInterface|ContainerInterface $container
51
     * @return MichelfPHPMarkdownAdapter
52
     */
53 1
    protected function create($container)
54
    {
55 1
        if (!$container instanceof ServiceLocatorInterface && !$container instanceof ContainerInterface) {
56
            throw new \InvalidArgumentException('Invalid container to create service');
57
        }
58
59 1
        $config = $container->get('config');
60
61 1
        return new MichelfPHPMarkdownAdapter($config['magl_markdown']['adapter_config']['michelf_markdown']);
62
    }
63
}
64