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

src/IPub/Flysystem/Loaders/NeonFileLoader.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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