Completed
Push — develop ( 1b34c6...481302 )
by Paul
02:47
created

ContainerFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 21 1
1
<?php
2
3
namespace PhpUnitGen\Container;
4
5
use PhpParser\Parser;
6
use PhpParser\ParserFactory;
7
use PhpUnitGen\Configuration\ConfigurationInterface\ConfigInterface;
8
use PhpUnitGen\Configuration\ConfigurationInterface\ConsoleConfigInterface;
9
use PhpUnitGen\Container\ContainerInterface\ContainerFactoryInterface;
10
use PhpUnitGen\Container\ContainerInterface\ContainerInterface;
11
use Slim\Views\PhpRenderer;
0 ignored issues
show
Bug introduced by
The type Slim\Views\PhpRenderer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
/**
14
 * Class ContainerFactory.
15
 *
16
 * @author     Paul Thébaud <[email protected]>.
17
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
18
 * @license    https://opensource.org/licenses/MIT The MIT license.
19
 * @link       https://github.com/paul-thebaud/phpunit-generator
20
 * @since      Class available since Release 2.0.0.
21
 */
22
class ContainerFactory implements ContainerFactoryInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function invoke(
28
        ConfigInterface $config,
29
        string $resolvablePath = __DIR__ . '/../../config/autoresolvable.config.php'
30
    ): ContainerInterface {
31
        $container = new Container();
32
33
        // Configuration
34
        $container->setInstance(ConfigInterface::class, $config);
35
        $container->setInstance(ConsoleConfigInterface::class, $config);
36
        // Php parser
37
        $container->setInstance(Parser::class, (new ParserFactory())->create(ParserFactory::PREFER_PHP7));
38
        // Php renderer
39
        $renderer = new PhpRenderer($config->getTemplatesPath());
40
        $renderer->addAttribute('config', $config);
41
        $container->setInstance(PhpRenderer::class, $renderer);
42
43
        // Automatically created dependencies and aliases
44
        $autoResolvable = require $resolvablePath;
45
        $container->addAutoResolvableArray($autoResolvable);
46
47
        return $container;
48
    }
49
}
50