Directories   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 31
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseDirectory() 0 4 1
A getRepositoryDirectory() 0 4 1
A getPharDirectory() 0 4 1
1
<?php
2
3
namespace Cpliakas\ManifestPublisher\Traits;
4
5
use Cpliakas\ManifestPublisher\Repository;
6
7
trait Directories
8
{
9
    /**
10
     * @return string
11
     */
12
    public function getBaseDirectory()
0 ignored issues
show
Coding Style introduced by
getBaseDirectory 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...
13
    {
14
        return $_SERVER['HOME'] . '/.ManifestPublisher';
15
    }
16
17
    /**
18
     * @param Repository $repository
19
     *
20
     * @return string
21
     */
22
    public function getRepositoryDirectory(Repository $repository)
23
    {
24
        return $this->getBaseDirectory() . '/repos/' . $repository;
25
    }
26
27
    /**
28
     * @param Repository $repository
29
     * @param string     $version
30
     *
31
     * @return string
32
     */
33
    public function getPharDirectory(Repository $repository, $version)
34
    {
35
        return $this->getBaseDirectory() . '/phars/' . $repository . '/' . $version;
36
    }
37
}
38