Intraface_Doctrine_Intranet   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
ccs 11
cts 12
cp 0.9167
wmc 5
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A singleton() 0 10 3
A getId() 0 4 1
1
<?php
2
class Intraface_Doctrine_Intranet
3
{
4
    private $id;
5
6 47
    public function __construct($id)
7
    {
8 47
        $this->id = $id;
9 47
    }
10
11 47
    public static function singleton($id = null)
0 ignored issues
show
Coding Style introduced by
singleton uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
12
    {
13 47
        if ($id != null) {
14 4
            $GLOBALS['intraface_doctrine_intranet_id'] = intval($id);
15 4
        }
16 47
        if (empty($GLOBALS['intraface_doctrine_intranet_id'])) {
17
            throw new Exception('An intranet id was not set!');
18
        }
19 47
        return new Intraface_Doctrine_Intranet($GLOBALS['intraface_doctrine_intranet_id']);
20
    }
21
22 47
    public function getId()
23
    {
24 47
        return $this->id;
25
    }
26
}
27