Skip to content

Commit 3b9fd2f

Browse files
committed
Code style fixes
- Fixed code style issues in LoggerHandlerFactory.php, LoggerConfiguration.php, LoggerProcessorFactory.php, ReflectionFactoryTrait.php, and ConfigurationValidator.php using PHP CS Fixer.
1 parent b946aa6 commit 3b9fd2f

File tree

5 files changed

+62
-50
lines changed

5 files changed

+62
-50
lines changed

src/Handler/LoggerHandlerFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace KaririCode\Logging\Handler;
66

7-
use InvalidArgumentException;
87
use KaririCode\Contract\Logging\LogHandler;
98
use KaririCode\Logging\Contract\Logging\LoggerConfigurableFactory;
109
use KaririCode\Logging\LoggerConfiguration;
@@ -17,7 +16,6 @@ class LoggerHandlerFactory implements LoggerConfigurableFactory
1716
private array $handlerMap = [];
1817
private LoggerConfiguration $config;
1918

20-
2119
public function initializeFromConfiguration(LoggerConfiguration $config): void
2220
{
2321
$this->handlerMap = $config->get('handlers', [
@@ -39,6 +37,7 @@ public function createHandlers(string $handlerName): array
3937
[$handlerName, $handlerOptions] = $this->extractMergedConfig($key, $value);
4038
$handlers[] = $this->createHandler($handlerName, $handlerOptions);
4139
}
40+
4241
return $handlers;
4342
}
4443

@@ -53,12 +52,14 @@ private function getHandlersConfig(string $channelName): array
5352
private function getChannelHandlersConfig(string $channelName): ?array
5453
{
5554
$channelConfigs = $this->config->get('channels', []);
55+
5656
return $channelConfigs[$channelName]['handlers'] ?? null;
5757
}
5858

5959
private function getOptionalHandlersConfig(string $channelName): ?array
6060
{
6161
$optionalHandlerConfigs = $this->config->get($channelName, []);
62+
6263
return $optionalHandlerConfigs['handlers'] ?? $this->getChannelHandlersConfig(
6364
$optionalHandlerConfigs['channel'] ?? 'file'
6465
);
@@ -75,6 +76,7 @@ private function createHandler(string $handlerName, array $handlerOptions): LogH
7576
private function getHandlerConfig(string $handlerName, array $handlerOptions): array
7677
{
7778
$defaultConfig = $this->handlerMap[$handlerName]['with'] ?? [];
79+
7880
return array_merge($defaultConfig, $handlerOptions);
7981
}
8082
}

src/LoggerConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private function getNestedValue(array $array, array $keys): mixed
7373
}
7474
$array = $array[$key];
7575
}
76+
7677
return $array;
7778
}
7879

src/Processor/LoggerProcessorFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private function createProcessor(string $processorName, array $processorOptions)
5555
private function getProcessorConfig(string $processorName, array $channelConfig): array
5656
{
5757
$defaultConfig = $this->processorMap[$processorName]['with'] ?? [];
58+
5859
return array_merge($defaultConfig, $channelConfig);
5960
}
6061
}

src/Util/ReflectionFactoryTrait.php

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
use KaririCode\Logging\Exception\InvalidConfigurationException;
88
use ReflectionClass;
9-
use ReflectionException;
109

1110
/**
12-
* Trait ReflectionFactoryTrait
11+
* Trait ReflectionFactoryTrait.
1312
*
1413
* Provides methods for creating instances of classes using reflection and managing configurations.
1514
*/
@@ -18,33 +17,36 @@ trait ReflectionFactoryTrait
1817
/**
1918
* Creates an instance of the specified class with the given parameters.
2019
*
21-
* @param string $class The fully qualified class name.
22-
* @param array $parameters An array of parameters to pass to the constructor.
23-
* @return object The created instance.
24-
* @throws InvalidConfigurationException If the class doesn't exist or is not instantiable.
25-
* @throws ReflectionException If there's an error during reflection.
20+
* @param string $class the fully qualified class name
21+
* @param array $parameters an array of parameters to pass to the constructor
22+
*
23+
* @throws InvalidConfigurationException if the class doesn't exist or is not instantiable
24+
* @throws \ReflectionException if there's an error during reflection
25+
*
26+
* @return object the created instance
2627
*/
2728
public function createInstance(string $class, array $parameters = []): object
2829
{
2930
$reflectionClass = $this->getReflectionClass($class);
3031
$filteredParameters = $this->filterConstructorParameters($reflectionClass, $parameters);
32+
3133
return $reflectionClass->newInstanceArgs($filteredParameters);
3234
}
3335

3436
/**
3537
* Gets a ReflectionClass instance after validating the class.
3638
*
37-
* @param string $class The fully qualified class name.
38-
* @return ReflectionClass
39-
* @throws InvalidConfigurationException If the class doesn't exist or is not instantiable.
39+
* @param string $class the fully qualified class name
40+
*
41+
* @throws InvalidConfigurationException if the class doesn't exist or is not instantiable
4042
*/
41-
protected function getReflectionClass(string $class): ReflectionClass
43+
protected function getReflectionClass(string $class): \ReflectionClass
4244
{
4345
if (!class_exists($class)) {
4446
throw new InvalidConfigurationException("Class does not exist: $class");
4547
}
4648

47-
$reflectionClass = new ReflectionClass($class);
49+
$reflectionClass = new \ReflectionClass($class);
4850

4951
if (!$reflectionClass->isInstantiable()) {
5052
throw new InvalidConfigurationException("Class is not instantiable: $class");
@@ -56,12 +58,14 @@ protected function getReflectionClass(string $class): ReflectionClass
5658
/**
5759
* Filters the parameters to match the constructor's expected parameters.
5860
*
59-
* @param ReflectionClass $reflectionClass The reflection class.
60-
* @param array $parameters The parameters to filter.
61-
* @return array The filtered parameters.
62-
* @throws InvalidConfigurationException If a required parameter is missing.
61+
* @param \ReflectionClass $reflectionClass the reflection class
62+
* @param array $parameters the parameters to filter
63+
*
64+
* @throws InvalidConfigurationException if a required parameter is missing
65+
*
66+
* @return array the filtered parameters
6367
*/
64-
protected function filterConstructorParameters(ReflectionClass $reflectionClass, array $parameters): array
68+
protected function filterConstructorParameters(\ReflectionClass $reflectionClass, array $parameters): array
6569
{
6670
$constructor = $reflectionClass->getConstructor();
6771
if (!$constructor) {
@@ -90,10 +94,12 @@ protected function filterConstructorParameters(ReflectionClass $reflectionClass,
9094
/**
9195
* Gets the class from a configuration map.
9296
*
93-
* @param array $map The configuration map.
94-
* @param string $key The key to look up in the map.
95-
* @return string The fully qualified class name.
96-
* @throws InvalidConfigurationException If the class configuration is invalid or the class doesn't exist.
97+
* @param array $map the configuration map
98+
* @param string $key the key to look up in the map
99+
*
100+
* @throws InvalidConfigurationException if the class configuration is invalid or the class doesn't exist
101+
*
102+
* @return string the fully qualified class name
97103
*/
98104
protected function getClassFromMap(array $map, string $key): string
99105
{
@@ -107,10 +113,12 @@ protected function getClassFromMap(array $map, string $key): string
107113
/**
108114
* Validates and extracts the class from a configuration value.
109115
*
110-
* @param mixed $config The configuration value.
111-
* @param string $key The configuration key (for error reporting).
112-
* @return string The validated class name.
113-
* @throws InvalidConfigurationException If the class configuration is invalid or the class doesn't exist.
116+
* @param mixed $config the configuration value
117+
* @param string $key the configuration key (for error reporting)
118+
*
119+
* @throws InvalidConfigurationException if the class configuration is invalid or the class doesn't exist
120+
*
121+
* @return string the validated class name
114122
*/
115123
protected function validateAndExtractClass($config, string $key): string
116124
{
@@ -126,11 +134,12 @@ protected function validateAndExtractClass($config, string $key): string
126134
/**
127135
* Gets configuration from a map for a specific key.
128136
*
129-
* @param array $map The configuration map.
130-
* @param string $key The key to look up in the map.
131-
* @param string $configKey The configuration key to retrieve (default: 'with').
132-
* @param array $default The default value if the configuration is not found.
133-
* @return array The configuration array.
137+
* @param array $map the configuration map
138+
* @param string $key the key to look up in the map
139+
* @param string $configKey the configuration key to retrieve (default: 'with')
140+
* @param array $default the default value if the configuration is not found
141+
*
142+
* @return array the configuration array
134143
*/
135144
protected function getConfigFromMap(array $map, string $key, string $configKey = 'with', $default = []): array
136145
{
@@ -141,7 +150,8 @@ protected function getConfigFromMap(array $map, string $key, string $configKey =
141150
* Merges multiple configurations.
142151
*
143152
* @param array ...$configs The configurations to merge.
144-
* @return array The merged configuration.
153+
*
154+
* @return array the merged configuration
145155
*/
146156
protected function mergeConfigurations(array ...$configs): array
147157
{
@@ -151,24 +161,27 @@ protected function mergeConfigurations(array ...$configs): array
151161
/**
152162
* Gets the component configuration by merging default and channel-specific configs.
153163
*
154-
* @param string $componentType The type of the component.
155-
* @param string $componentName The name of the component.
156-
* @param array $channelConfig The channel-specific configuration.
157-
* @param array $defaultConfig The default configuration.
158-
* @return array The merged component configuration.
164+
* @param string $componentType the type of the component
165+
* @param string $componentName the name of the component
166+
* @param array $channelConfig the channel-specific configuration
167+
* @param array $defaultConfig the default configuration
168+
*
169+
* @return array the merged component configuration
159170
*/
160171
protected function getComponentConfig(string $componentType, string $componentName, array $channelConfig, array $defaultConfig): array
161172
{
162173
$channelComponentConfig = $channelConfig[$componentType][$componentName] ?? [];
174+
163175
return $this->mergeConfigurations($defaultConfig, $channelComponentConfig);
164176
}
165177

166178
/**
167179
* Extracts the merged configuration from a key-value pair.
168180
*
169-
* @param mixed $key The configuration key.
170-
* @param mixed $value The configuration value.
171-
* @return array An array containing the extracted class and configuration.
181+
* @param mixed $key the configuration key
182+
* @param mixed $value the configuration value
183+
*
184+
* @return array an array containing the extracted class and configuration
172185
*/
173186
protected function extractMergedConfig($key, $value): array
174187
{
@@ -182,8 +195,9 @@ protected function extractMergedConfig($key, $value): array
182195
/**
183196
* Checks if the given key represents a simple handler configuration.
184197
*
185-
* @param mixed $key The configuration key to check.
186-
* @return bool True if it's a simple handler configuration, false otherwise.
198+
* @param mixed $key the configuration key to check
199+
*
200+
* @return bool true if it's a simple handler configuration, false otherwise
187201
*/
188202
protected function isSimpleHandlerConfig($key): bool
189203
{

src/Validation/ConfigurationValidator.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,22 @@ class ConfigurationValidator
1515
'processors',
1616
'formatters',
1717
];
18-
1918
private const CHANNEL_REQUIRED_KEYS = [
2019
'handlers',
2120
];
22-
2321
private const HANDLER_REQUIRED_KEYS = [
2422
'class',
2523
];
26-
2724
private const PROCESSOR_REQUIRED_KEYS = [
2825
'class',
2926
];
30-
3127
private const FORMATTER_REQUIRED_KEYS = [
3228
'class',
3329
];
34-
3530
private const OPTIONAL_LOG_KEYS = [
3631
'enabled',
3732
'channel',
3833
];
39-
4034
private const OPTIONAL_LOGS = [
4135
'query',
4236
'performance',
@@ -57,7 +51,7 @@ private function validateRequiredKeys(array $config, array $requiredKeys, string
5751
{
5852
foreach ($requiredKeys as $key) {
5953
if (!isset($config[$key])) {
60-
throw new InvalidConfigurationException("Missing required key '{$key}' in configuration" . ($context ? " for {$context}" : ""));
54+
throw new InvalidConfigurationException("Missing required key '{$key}' in configuration" . ($context ? " for {$context}" : ''));
6155
}
6256
}
6357
}

0 commit comments

Comments
 (0)