LoggerFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 22
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 15 3
1
<?php
2
3
/*
4
 * This file is part of the Conveyor package.
5
 *
6
 * (c) Jeroen Fiege <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webcreate\Conveyor\Factory;
13
14
use Monolog\Handler\StreamHandler;
15
use Monolog\Logger;
16
17
class LoggerFactory
18
{
19
    /**
20
     * @param  string $logDir
21
     * @return Logger
22
     */
23
    public static function get($logDir)
0 ignored issues
show
Coding Style introduced by
get uses the super-global variable $_SERVER 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...
24
    {
25
        if (0 === strpos($logDir, '~')) {
26
            $logDir = $_SERVER['HOME'] . substr($logDir, 1);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $logDir. This often makes code more readable.
Loading history...
27
        }
28
29
        if (false === file_exists($logDir)) {
30
            mkdir($logDir, 0777, true);
31
        }
32
33
        $logger = new Logger('app');
34
        $logger->pushHandler(new StreamHandler($logDir . '/app.log', Logger::DEBUG));
35
36
        return $logger;
37
    }
38
}
39