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.
Completed
Push — master ( b3f20b...f5717e )
by James
03:07
created

InclusionDirective::compileFiles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of WebHelper Parser.
5
 *
6
 * (c) James <[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 WebHelper\Parser\Directive;
13
14
use Webmozart\Glob\Iterator\GlobIterator;
15
use WebHelper\Parser\Parser;
16
use WebHelper\Parser\Server\ServerInterface;
17
18
/**
19
 * Describes an inclusion directive instance.
20
 *
21
 * An inclusion directive points to a filesystem pathname.
22
 *
23
 * This pathname can be a file to load at the point of the active config, or
24
 * a list of files in a filesystem directory, using wildcards.
25
 *
26
 * Pathname can be absolute, or relative to a filesystem path defined by another Directive, or
27
 * to the path of the actual configuration file, or to the prefix.
28
 *
29
 * Technically, an inclusion directive is a simple directive that acts as a block directive.
30
 *
31
 * @author James <[email protected]>
32
 */
33
class InclusionDirective extends BlockDirective implements DirectiveInterface
34
{
35
    /** @var \WebHelper\Parser\Parser the parser instance */
36
    private $parser;
37
38
    /** @var array file list pointed with that directive */
39
    private $files = [];
40
41
    /**
42
     * Specific constructor for inclusion directives.
43
     *
44
     * @param string                   $name   the name of the key/context
45
     * @param string                   $value  the value of the key/context
46
     * @param \WebHelper\Parser\Parser $parser the parser instance
47
     */
48 4
    public function __construct($name, $value, Parser $parser)
49
    {
50 4
        parent::__construct($name, $value);
51 4
        $this->parser = $parser;
52 4
        $this->setFiles();
53 4
        $this->compileFiles();
54 4
    }
55
56
    /**
57
     * Gets the detected files of the directive.
58
     *
59
     * @return array detected files
60
     */
61 3
    public function getFiles()
62
    {
63 3
        return $this->files;
64
    }
65
66
    /**
67
     * Detects and memoizes the included files.
68
     */
69 4
    public function setFiles()
70
    {
71 4
        $this->files = [];
72 4
        $path = $this->getValue();
73
74 4
        if (!preg_match('#^/#', $path)) {
75 2
            $path = $this->parser->getServer()->getPrefix().'/'.$path;
76 2
        }
77
78 4
        $iterator = new GlobIterator($path);
79 4
        foreach ($iterator as $path) {
80 4
            $this->files[] = $path;
81 4
        }
82
83 4
        return $this;
84
    }
85
86
    /**
87
     * Fills the block directives by compiling the memoized files.
88
     */
89 4
    public function compileFiles()
90
    {
91 4
        foreach ($this->files as $file) {
92 4
            $activeConfig = $this->parser->setConfigFile($file)->getActiveConfig();
93 4
            $this->add($activeConfig);
94 4
        }
95
96 4
        return $this;
97
    }
98
99
    /**
100
     * Dumps the directive respecting a server syntax.
101
     *
102
     * @param ServerInterface $server a server instance
103
     * @param int             $spaces the indentation spaces
104
     *
105
     * @return string the dumped directive
106
     */
107 1 View Code Duplication
    public function dump(ServerInterface $server, $spaces = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
    {
109 1
        $value = $this->getValue() ? ' '.$this->getValue() : '';
110
111 1
        return str_repeat(' ', $spaces).sprintf(
112 1
            $server->getDumperSimpleDirective(),
113 1
            $this->getName(),
114
            $value
115 1
        ).PHP_EOL;
116
    }
117
}
118