Completed
Branch develop (9c1dc5)
by Timothy
07:15
created

AnimeClient.php ➔ loadToml()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 4
nop 1
dl 0
loc 26
rs 8.5806
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * Hummingbird Anime Client
4
 *
5
 * An API client for Hummingbird to manage anime and manga watch lists
6
 *
7
 * PHP version 7
8
 *
9
 * @package     HummingbirdAnimeClient
10
 * @author      Timothy J. Warren <[email protected]>
11
 * @copyright   2015 - 2016  Timothy J. Warren
12
 * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
13
 * @version     3.1
14
 * @link        https://github.com/timw4mail/HummingBirdAnimeClient
15
 */
16
17
namespace Aviat\AnimeClient;
18
19
use Yosymfony\Toml\Toml;
20
21
define('SRC_DIR', realpath(__DIR__));
22
23
const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth';
24
const DEFAULT_CONTROLLER_NAMESPACE = 'Aviat\AnimeClient\Controller';
25
const DEFAULT_CONTROLLER = 'Aviat\AnimeClient\Controller\Anime';
26
const DEFAULT_CONTROLLER_METHOD = 'index';
27
const NOT_FOUND_METHOD = 'notFound';
28
const ERROR_MESSAGE_METHOD = 'errorPage';
29
const SRC_DIR = SRC_DIR;
30
31
/**
32
 * Load configuration options from .toml files
33
 *
34
 * @param string $path - Path to load config
35
 * @return array
36
 */
37
function loadToml(string $path): array
38
{
39
	$output = [];
40
	$files = glob("{$path}/*.toml");
41
42
	foreach ($files as $file)
43
	{
44
		$key = str_replace('.toml', '', basename($file));
45
		$toml = file_get_contents($file);
46
		$config = Toml::Parse($toml);
47
48
		if ($key === 'config')
49
		{
50
			foreach($config as $name => $value)
51
			{
52
				$output[$name] = $value;
53
			}
54
55
			continue;
56
		}
57
58
		$output[$key] = $config;
59
	}
60
61
	return $output;
62
}