Passed
Push — master ( a71910...a2423b )
by Adam
02:04
created

NeonFileLoader   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 43
ccs 8
cts 16
cp 0.5
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        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:Flysystem!
9
 * @subpackage     Loaders
10
 * @since          1.0.0
11
 *
12
 * @date           12.04.16
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\Flysystem\Loaders;
18
19
use Nette;
20
use Nette\Neon;
21
use Nette\Utils;
22
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 1
class NeonFileLoader
34
{
35
	/**
36
	 * Implement nette smart magic
37
	 */
38 1
	use Nette\SmartObject;
39
40
	/**
41
	 * @param $resource
42
	 *
43
	 * @return array
44
	 */
45
	public function load($resource) : array
46
	{
47 1
		if (!stream_is_local($resource)) {
48
			throw new Exceptions\InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
49
		}
50
51 1
		if (!file_exists($resource)) {
52
			throw new Exceptions\NotFoundResourceException(sprintf('File "%s" not found.', $resource));
53
		}
54
55
		try {
56 1
			$configuration = Neon\Neon::decode(file_get_contents($resource));
57
58
		} 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...
59
			throw new Exceptions\InvalidResourceException(sprintf('Error parsing Neon: %s', $ex->getMessage()), 0, $ex);
60
61
		} catch (Nette\Neon\Exception $ex) {
0 ignored issues
show
Bug introduced by
The class Nette\Neon\Exception 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...
62
			throw new Exceptions\InvalidResourceException(sprintf('Error parsing Neon: %s', $ex->getMessage()), 0, $ex);
63
		}
64
65 1
		if (empty($configuration)) {
66
			$configuration = [];
67
		}
68
69 1
		if (!is_array($configuration)) {
70
			throw new Exceptions\InvalidResourceException(sprintf('The file "%s" must contain a Neon array.', $resource));
71
		}
72
73 1
		return $configuration;
74
	}
75
}
76