Completed
Push — master ( e0759a...dc0dc9 )
by Sergi Tur
04:57
created

Paths::getRealPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Acacha\AdminLTETemplateLaravel\Console\Traits;
4
5
/**
6
 * Class Paths.
7
 *
8
 * @package Acacha\AdminLTETemplateLaravel\Console\Traits
9
 */
10
trait Paths
11
{
12
    /**
13
     * Get the real path of a link or regular path if file is not a link.
14
     *
15
     * @param $file
16
     *
17
     * @return string
18
     */
19
    private function getRealPath($file)
20
    {
21
        if (is_link($file)) {
22
            return realpath($file);
23
        }
24
25
        return $file;
26
    }
27
28
    /**
29
     * Get user home path.
30
     *
31
     * @return string
32
     */
33
    public function getUserHomePath()
0 ignored issues
show
Coding Style introduced by
getUserHomePath 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...
34
    {
35
        if (isset($_SERVER['HOME'])) {
36
            return $_SERVER['HOME'];
37
        }
38
39
        if (PHP_OS == 'WINNT') {
40
            return getenv('USERPROFILE');
41
        } else {
42
            return getenv('HOME');
43
        }
44
    }
45
}