Completed
Push — master ( 1e878c...90662d )
by Kevin
07:14 queued 03:43
created

EnvironmentConfigurationReader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 3
1
<?php
2
3
namespace Magium\Util\Configuration;
4
5
class EnvironmentConfigurationReader
6
{
7
8
    public function configure(ConfigurableObjectInterface $config)
0 ignored issues
show
Coding Style introduced by
configure uses the super-global variable $_ENV 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...
9
    {
10
        $variablePrefix = 'MAGIUM_' . str_replace('\\', '_', strtoupper(get_class($config))) . '_';
11
12
        foreach ($_ENV as $key => $value) {
13
            if (strpos($key, $variablePrefix) === 0) {
14
                $property = substr($key, strlen($variablePrefix));
15
                $config->set($property, $value);
16
            }
17
        }
18
    }
19
20
}