Intraface_Doctrine_Intranet::getId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 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