Passed
Pull Request — master (#4)
by Vincent
09:30
created

PrimeBundle   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 47.06%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 47
rs 10
ccs 8
cts 17
cp 0.4706
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 3
A shutdown() 0 15 3
A build() 0 4 1
1
<?php
2
3
namespace Bdf\PrimeBundle;
4
5
use Bdf\Prime\Locatorizable;
6
use Bdf\Prime\MongoDB\Collection\MongoCollectionLocator;
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\MongoDB\Collec...\MongoCollectionLocator 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...
7
use Bdf\Prime\MongoDB\Mongo;
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\MongoDB\Mongo 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...
8
use Bdf\Prime\ServiceLocator;
9
use Bdf\PrimeBundle\DependencyInjection\Compiler\IgnorePrimeAnnotationsPass;
10
use Bdf\PrimeBundle\DependencyInjection\Compiler\PrimeConnectionFactoryPass;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\HttpKernel\Bundle\Bundle;
13
14
/**
15
 * PrimeBundle
16
 *
17
 * @author Seb
18
 */
19
class PrimeBundle extends Bundle
20
{
21
    /**
22
     * {@inheritDoc}
23
     */
24 9
    public function boot()
25
    {
26 9
        if ($this->container->getParameter('prime.locatorizable')) {
27 9
            Locatorizable::configure(function() {
28 2
                return $this->container->get('prime');
29
            });
30
31 9
            if (class_exists(Mongo::class)) {
32
                Mongo::configure(function () {
33
                    return $this->container->get(MongoCollectionLocator::class);
34
                });
35
            }
36
        }
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 7
    public function build(ContainerBuilder $container)
43
    {
44 7
        $container->addCompilerPass(new PrimeConnectionFactoryPass());
45 7
        $container->addCompilerPass(new IgnorePrimeAnnotationsPass());
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51
    public function shutdown()
52
    {
53
        if (!$this->container->initialized('prime')) {
54
            return;
55
        }
56
57
        /** @var ServiceLocator $prime */
58
        $prime = $this->container->get('prime');
59
60
        // Clear circle references
61
        $prime->clearRepositories();
62
63
        // Close all loaded connections
64
        foreach ($prime->connections() as $connection) {
65
            $connection->close();
66
        }
67
    }
68
}
69