DotPost   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A id() 0 4 1
A run() 0 16 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