DotPost::run()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 1
crap 3
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\ArgumentHelper;
7
use Desmond\exceptions\ArgumentException;
8
9
class DotPost extends DesmondFunction
10
{
11
    use TypeHelper;
12
    use ArgumentHelper;
13
14 334
    public function id()
15
    {
16 334
        return '.post';
17
    }
18
19 6
    public function run(array $args)
0 ignored issues
show
Coding Style introduced by
run uses the super-global variable $_POST 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...
20
    {
21 6
        if (!isset($args[0])) {
22 1
            return self::fromPhpType($_POST);
23
        }
24 5
        $this->expectArguments(
25 5
            '.post',
26 5
            [0 => ['Symbol', 'String']],
27 5
            $args
28
        );
29 4
        $index = $args[0]->value();
30 4
        if (!isset($_POST[$index])) {
31 1
            throw new ArgumentException('".post": Index "' . $index . '" not found.');
32
        }
33 3
        return self::fromPhpType($_POST[$index]);
34
    }
35
}
36