Passed
Pull Request — master (#1)
by Radovan
02:29
created
src/DI/Config/Adapters/EnvironmentAdapter.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	protected function getEntityType(Entity $entity): string
69 69
 	{
70 70
 		$type = substr((string)$entity->value, 2);
71
-		return match ($type) {
71
+		return match($type) {
72 72
 			Environment::INTEGER, Environment::INT, Environment::BOOLEAN, Environment::BOOL, Environment::FLOAT, 'array' => $type,
73 73
 			default => Environment::STRING
74 74
 		};
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		$data = (array)($data['parameters']['env'] ?? []);
97 97
 		array_walk_recursive(
98 98
 			$data,
99
-			static function (mixed &$val): void {
99
+			static function(mixed &$val): void {
100 100
 				if ($val instanceof Statement && $entity = $val->getEntity()) {
101 101
 					$arguments = [
102 102
 						'hidden' => true,
Please login to merge, or discard this patch.
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -17,119 +17,119 @@
 block discarded – undo
17 17
 
18 18
 class EnvironmentAdapter implements Adapter
19 19
 {
20
-	/**
21
-	 * Reads configuration from PHP file.
22
-	 * @return array<string, array<string, array<string, mixed>>>
23
-	 */
24
-	public function load(string $file): array
25
-	{
26
-		/** @var array<string, mixed> $data */
27
-		$data = (array)Neon::decode(FileSystem::read($file));
28
-		return $this->process($data);
29
-	}
20
+    /**
21
+     * Reads configuration from PHP file.
22
+     * @return array<string, array<string, array<string, mixed>>>
23
+     */
24
+    public function load(string $file): array
25
+    {
26
+        /** @var array<string, mixed> $data */
27
+        $data = (array)Neon::decode(FileSystem::read($file));
28
+        return $this->process($data);
29
+    }
30 30
 
31
-	/**
32
-	 * @param array<string,mixed> $data
33
-	 * @return array<string, array<string, array<string, mixed>>>
34
-	 */
35
-	protected function process(array $data): array
36
-	{
37
-		$envs = [];
31
+    /**
32
+     * @param array<string,mixed> $data
33
+     * @return array<string, array<string, array<string, mixed>>>
34
+     */
35
+    protected function process(array $data): array
36
+    {
37
+        $envs = [];
38 38
 
39
-		foreach ($data as $name => $entity) {
40
-			if (!$entity instanceof Entity) {
41
-				throw new InvalidConfigurationException(
42
-					"Invalid argument type ({$name}). Expected Entity, got " . gettype($entity)
43
-				);
44
-			}
39
+        foreach ($data as $name => $entity) {
40
+            if (!$entity instanceof Entity) {
41
+                throw new InvalidConfigurationException(
42
+                    "Invalid argument type ({$name}). Expected Entity, got " . gettype($entity)
43
+                );
44
+            }
45 45
 
46
-			$name = strtoupper($name);
47
-			$var = strtolower($name);
48
-			$type = $this->getEntityType($entity);
49
-			$attributes = $this->getAttributes($entity->attributes);
46
+            $name = strtoupper($name);
47
+            $var = strtolower($name);
48
+            $type = $this->getEntityType($entity);
49
+            $attributes = $this->getAttributes($entity->attributes);
50 50
 
51
-			if ($entity->attributes['hidden'] ?? $entity->attributes[1] ?? false) {
52
-				$envs[$var] = new Statement("Mallgroup\Environment::$type", $this->modifyStatementAttributes($name, $type, $attributes));
53
-			} elseif ($type === 'array') {
54
-				$envs[$var] = Environment::array($name, $attributes['separator'] ?: '|', $attributes['cast']);
55
-			} else {
56
-				$envs[$var] = (new Environment($name, $attributes['default'] ?? ''))->get($type);
57
-			}
58
-		}
59
-		return ['parameters' => ['env' => $envs]];
60
-	}
51
+            if ($entity->attributes['hidden'] ?? $entity->attributes[1] ?? false) {
52
+                $envs[$var] = new Statement("Mallgroup\Environment::$type", $this->modifyStatementAttributes($name, $type, $attributes));
53
+            } elseif ($type === 'array') {
54
+                $envs[$var] = Environment::array($name, $attributes['separator'] ?: '|', $attributes['cast']);
55
+            } else {
56
+                $envs[$var] = (new Environment($name, $attributes['default'] ?? ''))->get($type);
57
+            }
58
+        }
59
+        return ['parameters' => ['env' => $envs]];
60
+    }
61 61
 
62
-	/**
63
-	 * @param string $name
64
-	 * @param string $type
65
-	 * @param array<"cast"|"default"|"separator", string> $arguments
66
-	 * @return array<"cast"|"default"|"separator"|"name", string>
67
-	 */
68
-	protected function modifyStatementAttributes(string $name, string $type, array $arguments): array {
69
-		$arguments['name'] = $name;
70
-		if ($type === 'array') {
71
-			unset($arguments['default']);
72
-		} else {
73
-			unset($arguments['separator']);
74
-		}
75
-		return $arguments;
76
-	}
62
+    /**
63
+     * @param string $name
64
+     * @param string $type
65
+     * @param array<"cast"|"default"|"separator", string> $arguments
66
+     * @return array<"cast"|"default"|"separator"|"name", string>
67
+     */
68
+    protected function modifyStatementAttributes(string $name, string $type, array $arguments): array {
69
+        $arguments['name'] = $name;
70
+        if ($type === 'array') {
71
+            unset($arguments['default']);
72
+        } else {
73
+            unset($arguments['separator']);
74
+        }
75
+        return $arguments;
76
+    }
77 77
 
78
-	protected function getEntityType(Entity $entity): string
79
-	{
80
-		$type = substr((string)$entity->value, 2);
81
-		return match ($type) {
82
-			Environment::INTEGER, Environment::INT, Environment::BOOLEAN, Environment::BOOL, Environment::FLOAT, 'array' => $type,
83
-			default => Environment::STRING
84
-		};
85
-	}
78
+    protected function getEntityType(Entity $entity): string
79
+    {
80
+        $type = substr((string)$entity->value, 2);
81
+        return match ($type) {
82
+            Environment::INTEGER, Environment::INT, Environment::BOOLEAN, Environment::BOOL, Environment::FLOAT, 'array' => $type,
83
+            default => Environment::STRING
84
+        };
85
+    }
86 86
 
87
-	/**
88
-	 * @param array<int|string, mixed> $arguments
89
-	 * @return array<"cast"|"default"|"separator", string>
90
-	 */
91
-	protected function getAttributes(array $arguments): array
92
-	{
93
-		return array_filter([
94
-			'separator' => (string)($arguments['separator'] ?? $arguments[0] ?? '|'),
95
-			'cast' => (string)($arguments['cast'] ?? $arguments[2] ?? Environment::STRING),
96
-			'default' => (string)($arguments['default'] ?? $arguments[0] ?? ''),
97
-		], static fn($item) => $item !== '');
98
-	}
87
+    /**
88
+     * @param array<int|string, mixed> $arguments
89
+     * @return array<"cast"|"default"|"separator", string>
90
+     */
91
+    protected function getAttributes(array $arguments): array
92
+    {
93
+        return array_filter([
94
+            'separator' => (string)($arguments['separator'] ?? $arguments[0] ?? '|'),
95
+            'cast' => (string)($arguments['cast'] ?? $arguments[2] ?? Environment::STRING),
96
+            'default' => (string)($arguments['default'] ?? $arguments[0] ?? ''),
97
+        ], static fn($item) => $item !== '');
98
+    }
99 99
 
100
-	/**
101
-	 * Generates configuration in PHP format.
102
-	 * @param mixed[] $data
103
-	 */
104
-	public function dump(array $data): string
105
-	{
106
-		$data = (array)($data['parameters']['env'] ?? []);
107
-		array_walk_recursive(
108
-			$data,
109
-			static function (mixed &$val): void {
110
-				if ($val instanceof Statement && $entity = $val->getEntity()) {
111
-					$arguments = [
112
-						'hidden' => true,
113
-					];
114
-					/** @var array<"cast"|"default"|"separator", string> $args */
115
-					$args = $val->arguments;
100
+    /**
101
+     * Generates configuration in PHP format.
102
+     * @param mixed[] $data
103
+     */
104
+    public function dump(array $data): string
105
+    {
106
+        $data = (array)($data['parameters']['env'] ?? []);
107
+        array_walk_recursive(
108
+            $data,
109
+            static function (mixed &$val): void {
110
+                if ($val instanceof Statement && $entity = $val->getEntity()) {
111
+                    $arguments = [
112
+                        'hidden' => true,
113
+                    ];
114
+                    /** @var array<"cast"|"default"|"separator", string> $args */
115
+                    $args = $val->arguments;
116 116
 
117
-					if (is_array($entity) && $entity[0] === Environment::class) {
118
-						$type = (string)($entity[1] ?? 'string');
117
+                    if (is_array($entity) && $entity[0] === Environment::class) {
118
+                        $type = (string)($entity[1] ?? 'string');
119 119
 
120
-						if ($type === 'array') {
121
-							$arguments['separator'] = $args['separator'];
122
-							$arguments['cast'] = $args['cast'];
123
-						} else {
124
-							$arguments['default'] = $args['default'];
125
-						}
126
-						$entity = '::' . $type;
127
-					}
120
+                        if ($type === 'array') {
121
+                            $arguments['separator'] = $args['separator'];
122
+                            $arguments['cast'] = $args['cast'];
123
+                        } else {
124
+                            $arguments['default'] = $args['default'];
125
+                        }
126
+                        $entity = '::' . $type;
127
+                    }
128 128
 
129
-					$val = new Entity($entity, $arguments);
130
-				}
131
-			},
132
-		);
133
-		return "# generated by Nette\n\n" . Neon::encode($data, Neon::BLOCK);
134
-	}
129
+                    $val = new Entity($entity, $arguments);
130
+                }
131
+            },
132
+        );
133
+        return "# generated by Nette\n\n" . Neon::encode($data, Neon::BLOCK);
134
+    }
135 135
 }
Please login to merge, or discard this patch.
src/Bootstrap/Configurator.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -10,24 +10,24 @@
 block discarded – undo
10 10
 
11 11
 class Configurator extends Bootstrap\Configurator
12 12
 {
13
-	protected function createLoader(): Loader
14
-	{
15
-		$loader = parent::createLoader();
16
-		$loader->addAdapter('env', EnvironmentAdapter::class);
17
-		return $loader;
18
-	}
13
+    protected function createLoader(): Loader
14
+    {
15
+        $loader = parent::createLoader();
16
+        $loader->addAdapter('env', EnvironmentAdapter::class);
17
+        return $loader;
18
+    }
19 19
 
20 20
 
21
-	/**
22
-	 * @return array<mixed>
23
-	 */
24
-	protected function getDefaultParameters(): array
25
-	{
26
-		$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
21
+    /**
22
+     * @return array<mixed>
23
+     */
24
+    protected function getDefaultParameters(): array
25
+    {
26
+        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
27 27
 
28
-		$parameters = parent::getDefaultParameters();
29
-		$parameters['appDir'] = dirname($trace[2]['file']);
28
+        $parameters = parent::getDefaultParameters();
29
+        $parameters['appDir'] = dirname($trace[2]['file']);
30 30
 
31
-		return $parameters;
32
-	}
31
+        return $parameters;
32
+    }
33 33
 }
Please login to merge, or discard this patch.