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.

FilePathCollectorTrait::setFileDirName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Spl\Traits\Collectors;
15
16
// ------------------------------------------------------------------------
17
18
/**
19
 * Class PathCollectorTrait
20
 *
21
 * @package O2System\Spl\Traits\Collectors
22
 */
23
trait FilePathCollectorTrait
24
{
25
    /**
26
     * Sub Path
27
     *
28
     * @type string|null
29
     */
30
    protected $fileDirName = null;
31
32
    // ------------------------------------------------------------------------
33
34
    /**
35
     * List of Paths
36
     *
37
     * @type array
38
     */
39
    protected $filePaths = [];
40
41
    public function setFileDirName($fileDirName)
42
    {
43
        $this->fileDirName = $fileDirName;
44
45
        return $this;
46
    }
47
48
    // ------------------------------------------------------------------------
49
50
    public function removeFilePath($filePath)
51
    {
52
        if (false !== ($key = array_search($filePath, $this->filePaths))) {
53
            unset($this->filePaths[ $key ]);
54
        }
55
56
        return $this;
57
    }
58
59
    // ------------------------------------------------------------------------
60
61
    public function getFilePaths($reverse = false)
62
    {
63
        return ($reverse === true ? array_reverse($this->filePaths) : $this->filePaths);
64
    }
65
66
    // ------------------------------------------------------------------------
67
68
    public function setFilePaths(array $filePaths)
69
    {
70
        $this->filePaths = [];
71
        $this->addFilePaths($filePaths);
72
73
        return $this;
74
    }
75
76
    // ------------------------------------------------------------------------
77
78
    public function addFilePaths(array $filePaths)
79
    {
80
        foreach ($filePaths as $filePath) {
81
            $this->addFilePath($filePath);
82
        }
83
84
        return $this;
85
    }
86
87
    // ------------------------------------------------------------------------
88
89
    public function addFilePath($filePath, $offset = null)
90
    {
91
        $filePath = rtrim(
92
                str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $filePath),
93
                DIRECTORY_SEPARATOR
94
            ) . DIRECTORY_SEPARATOR;
95
96
        if (isset($this->fileDirName)) {
97
            $filePath = str_replace(
98
                    $this->fileDirName . DIRECTORY_SEPARATOR,
99
                    '',
100
                    $filePath
101
                ) . $this->fileDirName . DIRECTORY_SEPARATOR;
102
        }
103
104
        return $this->pushFilePath($filePath, $offset);
105
    }
106
107
    // ------------------------------------------------------------------------
108
    
109
    public function pushFilePath($filePath, $offset = null)
110
    {
111
        if (is_dir($filePath) AND ! in_array($filePath, $this->filePaths)) {
112
            if (isset($offset)) {
113
                $this->filePaths[ $offset ] = $filePath;
114
            } else {
115
                $this->filePaths[] = $filePath;
116
            }
117
        }
118
119
        return $this;
120
    }
121
}