Passed
Pull Request — master (#3)
by Miloš
13:15
created

NeonFileLoader   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 57.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 0
loc 40
ccs 11
cts 19
cp 0.5789
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C load() 0 30 7
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
34 1
{
35 1
    use Nette\SmartObject;
36
37
	/**
38
	 * @param $resource
39
	 *
40 1
	 * @return array
41
	 */
42
	public function load($resource)
43
	{
44 1
		if (!stream_is_local($resource)) {
45
			throw new Exceptions\InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
46
		}
47
48 1
		if (!file_exists($resource)) {
49
			throw new Exceptions\NotFoundResourceException(sprintf('File "%s" not found.', $resource));
50
		}
51
52
		try {
53 1
			$configuration = Neon\Neon::decode(file_get_contents($resource));
54
55 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...
56
			throw new Exceptions\InvalidResourceException(sprintf('Error parsing Neon: %s', $ex->getMessage()), 0, $ex);
57
58
		} catch (Nette\Neon\Exception $ex) {
59
			throw new Exceptions\InvalidResourceException(sprintf('Error parsing Neon: %s', $ex->getMessage()), 0, $ex);
60
		}
61
62 1
		if (empty($configuration)) {
63
			$configuration = [];
64
		}
65
66 1
		if (!is_array($configuration)) {
67
			throw new Exceptions\InvalidResourceException(sprintf('The file "%s" must contain a Neon array.', $resource));
68
		}
69
70 1
		return $configuration;
71
	}
72
}
73