Globals   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 18
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 2
A get() 0 4 2
A csrf() 0 4 1
1
<?php 
2
3
namespace Helmut\Forms\Requests;
4
5
use Helmut\Forms\Request;
6
7
class Globals implements Request {
8
    
9
    public function all()
0 ignored issues
show
Coding Style introduced by
all 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...
10
    {
11
        return isset($_POST) ? $_POST : [];
12
    }
13
14
    public function get($key)
0 ignored issues
show
Coding Style introduced by
get 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...
15
    {
16
        return isset($_POST[$key]) ? $_POST[$key] : null;
17
    }
18
19
    public function csrf()
20
    {
21
        return [];
22
    }
23
24
}