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.

Collection::__construct()   B
last analyzed

Complexity

Conditions 9
Paths 8

Size

Total Lines 24
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 10
nc 8
nop 0
dl 0
loc 24
rs 8.0555
c 0
b 0
f 0
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\Parser\Template;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\Patterns\Structural\Provider\AbstractProvider;
19
20
/**
21
 * Class Collection
22
 * @package O2System\Parser\TemplateEngines
23
 */
24
class Collection extends AbstractProvider
25
{
26
    /**
27
     * Collection::$supportedAdapters
28
     *
29
     * @var array
30
     */
31
    public $supportedAdapters = [
32
33
    ];
34
35
    // ------------------------------------------------------------------------
36
37
    public function __construct()
38
    {
39
        if ($handle = opendir(__DIR__ . DIRECTORY_SEPARATOR . 'Adapters')) {
40
41
            while (false !== ($file = readdir($handle))) {
42
43
                if ($file != "." && $file != "..") {
44
                    array_push($this->supportedAdapters, pathinfo($file, PATHINFO_FILENAME));
45
                }
46
            }
47
48
            closedir($handle);
49
        }
50
51
        if ($handle = opendir(__DIR__ . DIRECTORY_SEPARATOR . 'Engines')) {
52
53
            while (false !== ($file = readdir($handle))) {
54
55
                if ($file != "." && $file != "..") {
56
                    array_push($this->supportedAdapters, pathinfo($file, PATHINFO_FILENAME));
57
                }
58
            }
59
60
            closedir($handle);
61
        }
62
    }
63
64
    // ------------------------------------------------------------------------
65
66
    /**
67
     * Collection::load
68
     *
69
     * @param string $engine
70
     * @param array  $config
71
     *
72
     * @return bool
73
     */
74
    public function load($engine, array $config = [])
75
    {
76
        if (class_exists($adapter = '\O2System\Parser\Template\Adapters\\' . $engine)) {
77
78
            $this->register((new $adapter())->setConfig($config), $adapter);
79
80
            return $this->__isset($adapter);
81
        }
82
83
        return false;
84
    }
85
86
    // ------------------------------------------------------------------------
87
88
    /**
89
     * Collection::parse
90
     *
91
     * @param string $string
92
     * @param array  $vars
93
     *
94
     * @return string
95
     */
96
    public function parse($string, array $vars = [])
97
    {
98
        $output = $string;
99
100
        if(is_file($string)) {
101
            $output = file_get_contents($string);
102
        }
103
104
        if($this->count()) {
105
            foreach($this->registry as $adapter) {
106
                if($adapter instanceof Abstracts\AbstractAdapter) {
107
                    if($adapter->isSupported()) {
108
                        $adapter->initialize();
109
                        $adapter->loadString($output);
110
                        $output = $adapter->parse($vars);
111
                    }
112
                }
113
            }
114
        }
115
116
        return $output;
117
    }
118
}