Completed
Pull Request — master (#8)
by Thomas Mauro
04:50
created

MarkdownFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 63.64%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 42
ccs 7
cts 11
cp 0.6364
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createService() 0 4 1
A __invoke() 0 14 2
1
<?php
2
3
namespace MaglMarkdown\Service;
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 MarkdownFactory
14
 *
15
 * @package MaglMarkdown\Service
16
 */
17
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...
18
{
19
20
    /**
21
     * Create service
22
     *
23
     * @param ServiceLocatorInterface $serviceLocator
24
     * @return Markdown
25
     */
26
    public function createService(ServiceLocatorInterface $serviceLocator)
27
    {
28
        return $this($serviceLocator, Markdown::class);
29
    }
30
31
    /**
32
     * Create an object
33
     *
34
     * @param  ContainerInterface $container
35
     * @param  string             $requestedName
36
     * @param  null|array         $options
37
     * @return Markdown
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 1
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
45
    {
46 1
        $em = null;
47 1
        $markdownAdapter = $container->get('MaglMarkdown\MarkdownAdapter');
48
49
        // get / inject eventmanager only if cache is enabled
50 1
        $config = $container->get('config');
51 1
        $cacheEnabled = $config['magl_markdown']['cache_enabled'];
52 1
        if ($cacheEnabled) {
53
            $em = $container->get('Application')->getEventManager();
54
        }
55
56 1
        return new Markdown($markdownAdapter, $em);
57
    }
58
}
59