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 ( 79e180...3094b9 )
by Miles
09:00
created

FileTrait::loadContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4286
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of the m1\vars library
5
 *
6
 * (c) m1 <[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
 * @package     m1/vars
12
 * @version     0.2.0
13
 * @author      Miles Croxford <[email protected]>
14
 * @copyright   Copyright (c) Miles Croxford <[email protected]>
15
 * @license     http://github.com/m1/vars/blob/master/LICENSE
16
 * @link        http://github.com/m1/vars/blob/master/README.MD Documentation
17
 */
18
19
namespace M1\Vars\Traits;
20
21
/**
22
 * File trait gives common operation functions needed for files in Vars
23
 *
24
 * @since 0.1.0
25
 */
26
trait FileTrait
27
{
28
    /**
29
     * The file used in the trait
30
     *
31
     * @var string
32
     */
33
    private $file;
34
35
    /**
36
     * The parent Vars instance
37
     *
38
     * @var \M1\Vars\Vars
39
     */
40
    private $vars;
41
42
    /**
43
     * Validates the file passed to see if it is a file and is readable
44
     *
45
     * @throws \RuntimeException If the file passed is not a file
46
     * @throws \RuntimeException If the file passed is not readable
47
     */
48 61
    private function validate()
49
    {
50 61
        $file = $this->file;
51
52 61
        if (!is_file($file)) {
53 1
            throw new \RuntimeException(sprintf("'%s' is not a file", $file));
54
        }
55
56 60
        if (!is_readable($file)) {
57
            // @codeCoverageIgnoreStart
58
            throw new \RuntimeException(sprintf("'%s' is not a readable file", $file));
59
            // @codeCoverageIgnoreEnd
60
        }
61 60
    }
62
63
    /**
64
     * Gets the supported loader for the passed file
65
     *
66
     * @see \M1\Vars\Vars::getLoaders() \M1\Vars\Vars::getLoaders()
67
     *
68
     * @param string $data The passed file
69
     *
70
     * @return mixed Returns the loader class or false if no loader calls was found
71
     */
72 60
    private function getSupportedLoader($data)
73
    {
74 60
        $loaders = $this->vars->loader->getLoaders();
75
76 60
        foreach ($loaders as $loader) {
77 60
            $class_loader = new \ReflectionClass($loader);
78 60
            $class_loader = $class_loader->newInstanceArgs(array($data));
79
80 60
            if ($class_loader->supports()) {
81 59
                return $class_loader;
82
            }
83 56
        }
84 1
        return false;
85
    }
86
87
    /**
88
     * Loads raw content from the file
89
     *
90
     * @param string $data The passed file
91
     *
92
     * @throws \InvalidArugmentException If the file passed is not supported by the current loaders
93
     *
94
     * @return mixed The content from the file via the loader
95
     */
96 60
    private function loadContent($data)
97
    {
98 60
        $loader = $this->getSupportedLoader($data);
99
100 60
        if (!$loader) {
101 1
            throw new \InvalidArgumentException(sprintf("'%s' is not supported by the current loaders", $this->file));
102
        }
103
104 59
        $loader->load();
105 53
        return $loader->getContent();
106
    }
107
108
    /**
109
     * Returns the passed file
110
     *
111
     * @return string The passed file
112
     */
113 10
    public function getFile()
114
    {
115 10
        return $this->file;
116
    }
117
}
118