SessionBuilder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A postConfigure() 0 10 1
A createSession() 0 6 1
1
<?php
2
/*
3
 * This file is part of the PommProject/ModelManager package.
4
 *
5
 * (c) 2014 - 2015 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\ModelManager;
11
12
use PommProject\Foundation\Client\ClientHolder;
13
use PommProject\Foundation\Session as FoundationSession;
14
use PommProject\Foundation\Session\Connection;
15
use PommProject\Foundation\Session\Session;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, PommProject\ModelManager\Session.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
use PommProject\Foundation\SessionBuilder as FoundationSessionBuilder;
17
use PommProject\ModelManager\Model\ModelPooler;
18
use PommProject\ModelManager\ModelLayer\ModelLayerPooler;
19
use PommProject\ModelManager\Session as ModelManagerSession;
20
21
/**
22
 * SessionBuilder
23
 *
24
 * Session builder for the ModelManager package.
25
 *
26
 * @package   ModelManager
27
 * @copyright 2014 - 2015 Grégoire HUBERT
28
 * @author    Grégoire HUBERT
29
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
30
 * @see       FoundationSessionBuilder
31
 */
32
class SessionBuilder extends FoundationSessionBuilder
33
{
34
    /**
35
     * postConfigure
36
     *
37
     * Register ModelManager's poolers.
38
     *
39
     * @access protected
40
     * @param  Session          $session
41
     * @return SessionBuilder
42
     */
43
    protected function postConfigure(Session $session)
44
    {
45
        parent::postConfigure($session);
46
        $session
47
            ->registerClientPooler(new ModelPooler)
48
            ->registerClientPooler(new ModelLayerPooler)
49
            ;
50
51
        return $this;
52
    }
53
54
55
    /**
56
     * createSession
57
     *
58
     * @param Connection   $connection
59
     * @param ClientHolder $client_holder
60
     * @param null|string  $stamp
61
     * @return  ModelManagerSession
62
     * @see     VanillaSessionBuilder
63
     */
64
    protected function createSession(Connection $connection, ClientHolder $client_holder, $stamp)
65
    {
66
        $this->configuration->setDefaultValue('class:session', '\PommProject\ModelManager\Session');
67
68
        return parent::createSession($connection, $client_holder, $stamp);
69
    }
70
}
71