GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TestCase   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 99
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 2
A tearDown() 0 4 1
A getRootDir() 0 4 1
A setRootDir() 0 6 1
A createGenerator() 0 4 1
A getTestsRoot() 0 4 1
A deleteDir() 0 17 4
1
<?php
2
namespace Naneau\FileGen\Test\Generator;
3
4
use Naneau\FileGen\Directory;
5
use Naneau\FileGen\File;
6
use Naneau\FileGen\Generator;
7
8
use \RecursiveDirectoryIterator;
9
use \RecursiveIteratorIterator;
10
use \FilesystemIterator;
11
12
/**
13
 * Base class for tests, sets up virtual file system
14
 */
15
class TestCase extends \PHPUnit\Framework\TestCase
16
{
17
    /**
18
     * Root dir for tests
19
     *
20
     * @var string
21
     */
22
    private $rootDir;
23
24
    /**
25
     * Set Up test
26
     *
27
     * @return void
28
     **/
29
    public function setUp()
30
    {
31
        $dir = sys_get_temp_dir() . '/naneau-file-gen-tests';
32
33
        if (file_exists($dir)) {
34
            self::deleteDir($dir);
35
        }
36
        mkdir($dir);
37
38
        $this->setRootDir($dir);
39
    }
40
41
    public function tearDown()
42
    {
43
        self::deleteDir($this->getRootDir());
44
    }
45
46
    /**
47
     * Get the creation root
48
     *
49
     * @return string
50
     */
51
    public function getRootDir()
52
    {
53
        return $this->rootDir;
54
    }
55
56
    /**
57
     * Set the creation root
58
     *
59
     * @param  string   $rootDir
60
     * @return TestCase
61
     */
62
    public function setRootDir($rootDir)
63
    {
64
        $this->rootDir = $rootDir;
65
66
        return $this;
67
    }
68
69
    /**
70
     * Create a new generator
71
     *
72
     * @param  array[string]string $parameters
0 ignored issues
show
Documentation introduced by
The doc-type array[string]string could not be parsed: Expected "]" at position 2, but found "string". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
73
     * @return Generator
74
     **/
75
    protected function createGenerator(array $parameters = array())
76
    {
77
        return new Generator($this->getRootDir(), $parameters);
78
    }
79
80
    /**
81
     * Get the tests directory root path
82
     *
83
     * @return string
84
     **/
85
    protected function getTestsRoot()
86
    {
87
        return realpath(__DIR__ . '/../../../../');
88
    }
89
90
    /**
91
     * Delete a directory
92
     *
93
     * @param  string $dir
94
     * @return void
95
     **/
96
    private static function deleteDir($dir)
97
    {
98
        $iterator = new RecursiveIteratorIterator(
99
            new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS),
100
            RecursiveIteratorIterator::CHILD_FIRST
101
        );
102
103
        foreach ($iterator as $file) {
104
            if ($file->isFile() || $file->isLink()) {
105
                unlink($file);
106
            } else {
107
                rmdir($file);
108
            }
109
        }
110
111
        rmdir($dir);
112
    }
113
}
114