Completed
Push — master ( 670b18...db08df )
by Matthias
10s
created

GithubMarkdownAdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 53
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createService() 0 4 1
A __invoke() 0 4 1
A create() 0 15 3
1
<?php
2
3
namespace MaglMarkdown\Adapter;
4
5
use Interop\Container\ContainerInterface;
6
use Interop\Container\Exception\ContainerException;
7
use Zend\Http\Client as HttpClient;
8
use Zend\Http\Request;
9
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
10
use Zend\ServiceManager\Exception\ServiceNotFoundException;
11
use Zend\ServiceManager\FactoryInterface;
12
use Zend\ServiceManager\ServiceLocatorInterface;
13
14
/**
15
 * Class GithubMarkdownAdapterFactory
16
 *
17
 * @package MaglMarkdown\Adapter
18
 */
19
class GithubMarkdownAdapterFactory implements FactoryInterface
20
{
21
22
    /**
23
     * Create service
24
     *
25
     * @param ServiceLocatorInterface $serviceLocator
26
     * @return GithubMarkdownAdapter
27
     */
28 1
    public function createService(ServiceLocatorInterface $serviceLocator)
29
    {
30 1
        return $this->create($serviceLocator);
31
    }
32
33
    /**
34
     * Create an object
35
     *
36
     * @param  ContainerInterface $container
37
     * @param  string             $requestedName
38
     * @param  null|array         $options
39
     * @return GithubMarkdownAdapter
40
     * @throws \Interop\Container\Exception\NotFoundException
41
     * @throws \Zend\Http\Client\Exception\InvalidArgumentException
42
     * @throws ServiceNotFoundException if unable to resolve the service.
43
     * @throws ServiceNotCreatedException if an exception is raised when
44
     *     creating a service.
45
     * @throws ContainerException if any other error occurs
46
     */
47
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
48
    {
49
        return $this->create($container);
50
    }
51
52
    /**
53
     * @param ServiceLocatorInterface|ContainerInterface $container
54
     * @return GithubMarkdownAdapter
55
     */
56 1
    protected function create($container)
57
    {
58 1
        if (!$container instanceof ServiceLocatorInterface && !$container instanceof ContainerInterface) {
59
            throw new \InvalidArgumentException('Invalid container to create service');
60
        }
61
62 1
        $request = new Request();
63
64 1
        $client = new HttpClient();
65 1
        $client->setAdapter('Zend\Http\Client\Adapter\Curl');
66
67 1
        $options = $container->get('MaglMarkdown\Adapter\GithubMarkdownOptions');
68
69 1
        return new GithubMarkdownAdapter($client, $request, $options);
70
    }
71
}
72