DotGet::id()   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
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace Desmond\functions\core;
3
use Desmond\functions\DesmondFunction;
4
use Desmond\data_types\HashType;
5
use Desmond\TypeHelper;
6
use Desmond\exceptions\ArgumentException;
7
8
class DotGet extends DesmondFunction
9
{
10
    use TypeHelper;
11
12 334
    public function id()
13
    {
14 334
        return '.get';
15
    }
16
17 5
    public function run(array $args)
0 ignored issues
show
Coding Style introduced by
run uses the super-global variable $_GET 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...
18
    {
19 5
        if (!isset($args[0])) {
20 1
            return self::fromPhpType($_GET);
21
        }
22 4
        $index = $args[0]->value();
23 4
        if (!isset($_GET[$index])) {
24 1
            throw new ArgumentException('".get": Index "' . $index . '" not found.');
25
        }
26 3
        return self::fromPhpType($_GET[$index]);
27
    }
28
}
29