Passed
Push — develop ( 45600c...ff69f6 )
by Paul
03:16
created

DependencyInjector::inject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 10
nc 1
nop 2
1
<?php
2
3
namespace PhpUnitGen\Container;
4
5
use League\Flysystem\FilesystemInterface;
6
use PhpParser\Parser;
7
use PhpParser\ParserFactory;
8
use PhpUnitGen\Configuration\ConfigInterface;
9
use PhpUnitGen\Parser\DirectoryParser;
10
use PhpUnitGen\Parser\ParserInterface\DirectoryParserInterface;
11
use PhpUnitGen\Parser\ParserInterface\PhpFileParserInterface;
12
use PhpUnitGen\Parser\PhpFileParser;
13
use Psr\Container\ContainerInterface;
14
15
/**
16
 * Class DependencyInjector.
17
 *
18
 * @author     Paul Thébaud <[email protected]>.
19
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
20
 * @license    https://opensource.org/licenses/MIT The MIT license.
21
 * @link       https://github.com/paul-thebaud/phpunit-generator
22
 * @since      Class available since Release 2.0.0.
23
 */
24
class DependencyInjector implements DependencyInjectorInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function inject(ConfigInterface $config, ContainerInterface $container): ContainerInterface
30
    {
31
        /** @var Container $container */
32
        $container->setInstance(ConfigInterface::class, $config);
33
34
        $container->setInstance(Parser::class, (new ParserFactory())->create(ParserFactory::PREFER_PHP7));
35
36
        $container->setResolver(PhpFileParserInterface::class, function (ContainerInterface $container) {
37
            return new PhpFileParser($container->get(Parser::class));
38
        });
39
40
        $container->setResolver(DirectoryParserInterface::class, function (ContainerInterface $container) {
41
            return new DirectoryParser(
42
                $container->get(ConfigInterface::class),
43
                $container->get(FilesystemInterface::class),
44
                $container->get(PhpFileParserInterface::class)
45
            );
46
        });
47
48
        return $container;
49
    }
50
}
51