Completed
Push — master ( eade68...4a1b69 )
by Adam
06:41
created

NeonFileLoader::load()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 13.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
ccs 8
cts 16
cp 0.5
rs 6.7272
cc 7
eloc 16
nc 8
nop 1
crap 13.125
1
<?php
2
/**
3
 * NeonFileLoader.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:Flysystem!
9
 * @subpackage     Loaders
10
 * @since          1.0.0
11
 *
12
 * @date           12.04.16
13
 */
14
15
namespace IPub\Flysystem\Loaders;
16
17
use Nette;
18
use Nette\Neon;
19
use Nette\Utils;
20
21
use IPub;
22
use IPub\Flysystem;
23
use IPub\Flysystem\Exceptions;
24
25
/**
26
 * Neon configuration files loader for Flysystem configuration
27
 *
28
 * @package        iPublikuj:Flysystem!
29
 * @subpackage     Loaders
30
 *
31
 * @author         Adam Kadlec <[email protected]>
32
 */
33
class NeonFileLoader extends Nette\Object
34 1
{
35
	/**
36
	 * @param $resource
37
	 *
38
	 * @return array
39
	 */
40 1
	public function load($resource)
41
	{
42 1
		if (!stream_is_local($resource)) {
43
			throw new Exceptions\InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
44
		}
45
46 1
		if (!file_exists($resource)) {
47
			throw new Exceptions\NotFoundResourceException(sprintf('File "%s" not found.', $resource));
48
		}
49
50
		try {
51 1
			$configuration = Neon\Neon::decode(file_get_contents($resource));
52
53 1
		} catch (Utils\NeonException $ex) {
0 ignored issues
show
Bug introduced by
The class Nette\Utils\NeonException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
54
			throw new Exceptions\InvalidResourceException(sprintf('Error parsing Neon: %s', $ex->getMessage()), 0, $ex);
55
56
		} catch (Nette\Neon\Exception $ex) {
57
			throw new Exceptions\InvalidResourceException(sprintf('Error parsing Neon: %s', $ex->getMessage()), 0, $ex);
58
		}
59
60 1
		if (empty($configuration)) {
61
			$configuration = [];
62
		}
63
64 1
		if (!is_array($configuration)) {
65
			throw new Exceptions\InvalidResourceException(sprintf('The file "%s" must contain a Neon array.', $resource));
66
		}
67
68 1
		return $configuration;
69
	}
70
}
71