ModelLayerPooler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPoolerType() 0 4 1
A createClient() 0 13 3
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\ModelLayer;
11
12
use PommProject\Foundation\Client\ClientPooler;
13
use PommProject\Foundation\Client\ClientPoolerInterface;
14
use PommProject\ModelManager\Exception\ModelLayerException;
15
16
/**
17
 * ModelLayerPooler
18
 *
19
 * Pooler for ModelLayer session client.
20
 *
21
 * @package   ModelManager
22
 * @copyright 2014 - 2015 Grégoire HUBERT
23
 * @author    Grégoire HUBERT
24
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
25
 * @see       ClientPooler
26
 */
27
class ModelLayerPooler extends ClientPooler
28
{
29
    /**
30
     * getPoolerType
31
     *
32
     * @see ClientPoolerInterface
33
     */
34
    public function getPoolerType()
35
    {
36
        return 'model_layer';
37
    }
38
39
    /**
40
     * createClient
41
     *
42
     * @see    ClientPooler
43
     * @return ModelLayer
44
     * @throws ModelLayerException
45
     */
46
    protected function createClient($identifier)
47
    {
48
        try {
49
            $reflection = new \ReflectionClass($identifier);
50
            if (!$reflection->isSubclassOf('\PommProject\ModelManager\ModelLayer\ModelLayer')) {
51
                throw new ModelLayerException(sprintf("Class '%s' is not a subclass of ModelLayer.", $identifier));
52
            }
53
        } catch (\ReflectionException $e) {
54
            throw new ModelLayerException(sprintf("Error while loading class '%s' (%s).", $identifier, $e->getMessage()));
55
        }
56
57
        return new $identifier();
58
    }
59
}
60