MarkdownFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 16.33 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 3
dl 8
loc 49
ccs 7
cts 10
cp 0.7
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 1
A create() 8 8 3
A createService() 0 8 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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