Skip to content

Commit 5d38252

Browse files
authored
Merge pull request #6 from aporat/analysis-01mklE
Apply fixes from StyleCI
2 parents c61d9a4 + b6aa3f7 commit 5d38252

5 files changed

+46
-42
lines changed

config/cloudwatch-logger.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
*/
2222
'cloudwatch' => [
2323
'driver' => 'custom',
24-
'via' => \Aporat\CloudWatchLogger\CloudWatchLoggerFactory::class,
25-
'aws' => [
26-
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
27-
'version' => env('AWS_VERSION', 'latest'),
24+
'via' => \Aporat\CloudWatchLogger\CloudWatchLoggerFactory::class,
25+
'aws' => [
26+
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
27+
'version' => env('AWS_VERSION', 'latest'),
2828
'credentials' => [
29-
'key' => env('AWS_ACCESS_KEY_ID', ''),
29+
'key' => env('AWS_ACCESS_KEY_ID', ''),
3030
'secret' => env('AWS_SECRET_ACCESS_KEY', ''),
3131
],
3232
],
33-
'group' => env('CLOUDWATCH_LOG_GROUP_NAME', env('APP_NAME', 'laravel').'-'.env('APP_ENV', 'production')),
34-
'stream' => env('CLOUDWATCH_LOG_STREAM', 'default'),
35-
'name' => env('CLOUDWATCH_LOG_NAME', env('APP_NAME', 'laravel')),
36-
'retention' => env('CLOUDWATCH_LOG_RETENTION', 14),
37-
'level' => env('CLOUDWATCH_LOG_LEVEL', \Monolog\Level::Error->value),
33+
'group' => env('CLOUDWATCH_LOG_GROUP_NAME', env('APP_NAME', 'laravel').'-'.env('APP_ENV', 'production')),
34+
'stream' => env('CLOUDWATCH_LOG_STREAM', 'default'),
35+
'name' => env('CLOUDWATCH_LOG_NAME', env('APP_NAME', 'laravel')),
36+
'retention' => env('CLOUDWATCH_LOG_RETENTION', 14),
37+
'level' => env('CLOUDWATCH_LOG_LEVEL', \Monolog\Level::Error->value),
3838
'batch_size' => env('CLOUDWATCH_LOG_BATCH_SIZE', 10000),
39-
'formatter' => function (array $config) {
39+
'formatter' => function (array $config) {
4040
return new \Monolog\Formatter\LineFormatter(
4141
format: '%channel%: %level_name%: %message% %context% %extra%',
4242
dateFormat: null,

src/CloudWatchLoggerFactory.php

+15-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class CloudWatchLoggerFactory
2929
/**
3030
* Create a new CloudWatch logger factory instance.
3131
*
32-
* @param Container|null $container Laravel container instance (optional, defaults to null)
32+
* @param Container|null $container Laravel container instance (optional, defaults to null)
3333
*/
3434
public function __construct(?Container $container = null)
3535
{
@@ -39,10 +39,11 @@ public function __construct(?Container $container = null)
3939
/**
4040
* Create a configured CloudWatch logger instance.
4141
*
42-
* @param array<string, mixed> $config Configuration array for CloudWatch logging
43-
* @return Logger Configured Monolog logger instance
42+
* @param array<string, mixed> $config Configuration array for CloudWatch logging
4443
*
4544
* @throws IncompleteCloudWatchConfig If required config is missing or invalid
45+
*
46+
* @return Logger Configured Monolog logger instance
4647
*/
4748
public function __invoke(array $config): Logger
4849
{
@@ -67,14 +68,15 @@ public function __invoke(array $config): Logger
6768
/**
6869
* Resolve the formatter for CloudWatch logs based on configuration.
6970
*
70-
* @param array<string, mixed> $config Configuration array with optional formatter settings
71-
* @return FormatterInterface Formatter instance for Monolog
71+
* @param array<string, mixed> $config Configuration array with optional formatter settings
7272
*
7373
* @throws IncompleteCloudWatchConfig If formatter configuration is invalid
74+
*
75+
* @return FormatterInterface Formatter instance for Monolog
7476
*/
7577
private function resolveFormatter(array $config): FormatterInterface
7678
{
77-
if (! isset($config['formatter'])) {
79+
if (!isset($config['formatter'])) {
7880
return new LineFormatter(
7981
'%channel%: %level_name%: %message% %context% %extra%',
8082
null,
@@ -86,8 +88,8 @@ private function resolveFormatter(array $config): FormatterInterface
8688
$formatter = $config['formatter'];
8789

8890
if (is_string($formatter) && class_exists($formatter)) {
89-
if (! $this->container) {
90-
return new $formatter;
91+
if (!$this->container) {
92+
return new $formatter();
9193
}
9294

9395
return $this->container->make($formatter);
@@ -103,12 +105,13 @@ private function resolveFormatter(array $config): FormatterInterface
103105
/**
104106
* Validate and retrieve a required configuration value.
105107
*
106-
* @param array<string, mixed> $config Configuration array
107-
* @param string $key Config key to retrieve
108-
* @param string $description Description of the key for error messaging
109-
* @return mixed Config value
108+
* @param array<string, mixed> $config Configuration array
109+
* @param string $key Config key to retrieve
110+
* @param string $description Description of the key for error messaging
110111
*
111112
* @throws IncompleteCloudWatchConfig If the key is missing or empty
113+
*
114+
* @return mixed Config value
112115
*/
113116
private function validateConfig(array $config, string $key, string $description): mixed
114117
{

src/Exceptions/IncompleteCloudWatchConfig.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class IncompleteCloudWatchConfig extends Exception
1717
/**
1818
* Create a new incomplete CloudWatch configuration exception.
1919
*
20-
* @param string $message The exception message (default: 'Incomplete CloudWatch configuration')
21-
* @param int $code The exception code (default: 0)
22-
* @param Exception|null $previous The previous exception for chaining (default: null)
20+
* @param string $message The exception message (default: 'Incomplete CloudWatch configuration')
21+
* @param int $code The exception code (default: 0)
22+
* @param Exception|null $previous The previous exception for chaining (default: null)
2323
*/
2424
public function __construct(string $message = 'Incomplete CloudWatch configuration', int $code = 0, ?Exception $previous = null)
2525
{

tests/CloudWatchLoggerServiceProviderTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public function test_publishes_configuration(): void
4242

4343
$this->artisan('vendor:publish', [
4444
'--provider' => CloudWatchLoggerServiceProvider::class,
45-
'--tag' => 'config',
46-
'--force' => true,
45+
'--tag' => 'config',
46+
'--force' => true,
4747
]);
4848

4949
$this->assertFileExists($targetPath, 'Config file should be published');

tests/LoggerTest.php

+15-14
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public function test_throws_exception_for_invalid_formatter(): void
5757
public function test_creates_logger_with_line_formatter_callable(): void
5858
{
5959
$config = $this->getBaseConfig([
60-
'group' => 'myapp-testing',
61-
'stream' => 'default',
62-
'name' => 'default',
60+
'group' => 'myapp-testing',
61+
'stream' => 'default',
62+
'name' => 'default',
6363
'formatter' => fn (array $configs) => new LineFormatter(
6464
'%channel%: %level_name%: %message% %context% %extra%',
6565
null,
@@ -81,7 +81,7 @@ public function test_creates_logger_with_line_formatter_callable(): void
8181
Level::Error,
8282
'Test log message',
8383
['user_id' => 123],
84-
['key' => 'value']
84+
['key' => 'value']
8585
);
8686
$formatted = $formatter->format($record);
8787

@@ -97,27 +97,28 @@ protected function tearDown(): void
9797
/**
9898
* Generate a base CloudWatch configuration with optional overrides.
9999
*
100-
* @param array<string, mixed> $overrides Custom config values to merge
100+
* @param array<string, mixed> $overrides Custom config values to merge
101+
*
101102
* @return array<string, mixed> Complete config array
102103
*/
103104
private function getBaseConfig(array $overrides = []): array
104105
{
105106
return array_merge([
106107
'driver' => 'custom',
107-
'via' => CloudWatchLoggerFactory::class,
108-
'aws' => [
109-
'region' => 'us-east-1',
110-
'version' => 'latest',
108+
'via' => CloudWatchLoggerFactory::class,
109+
'aws' => [
110+
'region' => 'us-east-1',
111+
'version' => 'latest',
111112
'credentials' => [
112-
'key' => 'AWS_ACCESS_KEY_ID',
113+
'key' => 'AWS_ACCESS_KEY_ID',
113114
'secret' => 'AWS_SECRET_ACCESS_KEY',
114115
],
115116
],
116-
'name' => 'CLOUDWATCH_LOG_NAME',
117-
'group' => 'CLOUDWATCH_LOG_GROUP_NAME',
118-
'stream' => 'CLOUDWATCH_LOG_STREAM',
117+
'name' => 'CLOUDWATCH_LOG_NAME',
118+
'group' => 'CLOUDWATCH_LOG_GROUP_NAME',
119+
'stream' => 'CLOUDWATCH_LOG_STREAM',
119120
'retention' => 7,
120-
'level' => Level::Error,
121+
'level' => Level::Error,
121122
], $overrides);
122123
}
123124
}

0 commit comments

Comments
 (0)