Completed
Push — master ( 8cb11f...08a911 )
by Alejandro
08:01
created

ActionAbstractFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
namespace Acelaya\Website\Action\Factory;
3
4
use Acelaya\Website\Action\AbstractAction;
5
use Interop\Container\ContainerInterface;
6
use Interop\Container\Exception\ContainerException;
7
use Zend\Expressive\Template\TemplateRendererInterface;
8
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
9
use Zend\ServiceManager\Exception\ServiceNotFoundException;
10
use Zend\ServiceManager\Factory\AbstractFactoryInterface;
11
12
class ActionAbstractFactory implements AbstractFactoryInterface
13
{
14
    /**
15
     * Can the factory create an instance for the service?
16
     *
17
     * @param  ContainerInterface $container
18
     * @param  string $requestedName
19
     * @return bool
20
     */
21 1
    public function canCreate(ContainerInterface $container, $requestedName)
22
    {
23 1
        return is_subclass_of($requestedName, AbstractAction::class);
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Acelaya\Website\Action\AbstractAction::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
24
    }
25
26
    /**
27
     * Create an object
28
     *
29
     * @param  ContainerInterface $container
30
     * @param  string $requestedName
31
     * @param  null|array $options
32
     * @return object
33
     * @throws ServiceNotFoundException if unable to resolve the service.
34
     * @throws ServiceNotCreatedException if an exception is raised when
35
     *     creating a service.
36
     * @throws ContainerException if any other error occurs
37
     */
38 1
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
39
    {
40
        /** @var TemplateRendererInterface $renderer */
41 1
        $renderer = $container->get('renderer');
42 1
        return new $requestedName($renderer);
43
    }
44
}
45