MarkdownFactory::create()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 1
crap 3.1406
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
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...
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;
0 ignored issues
show
Deprecated Code introduced by
The method Zend\ServiceManager\Serv...er::getServiceLocator() has been deprecated with message: since 3.0.0. Factories using 3.0 should use the container instance passed to the factory instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
31
        }
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