Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump: EB-0 Upgrade dependencies #33

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DependencyInjection/CompilerPass/HttpClientPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class HttpClientPass implements CompilerPassInterface
{
private const DECORATOR_PRIORITY = 5;
private const int DECORATOR_PRIORITY = 5;

public function process(ContainerBuilder $container): void
{
Expand Down
41 changes: 20 additions & 21 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ETSGlobal\LogBundle\DependencyInjection;

use Monolog\Logger;
use Monolog\Level;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
Expand All @@ -15,16 +15,16 @@
/** @internal */
final class Configuration implements ConfigurationInterface
{
private const DEFAULT_APP_NAME = 'default';
private const string DEFAULT_APP_NAME = 'default';
// phpcs:ignore Generic.Files.LineLength.TooLong
private const DEFAULT_LOG_FORMAT = "[%%datetime%%][%%token_collection%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n";
private const DEFAULT_SLACK_CHANNEL = '#random';
private const DEFAULT_SLACK_ICON_EMOJI = ':warning';
private const DEFAULT_HTTP_EXCEPTIONS_LEVELS = [
BadRequestHttpException::class => Logger::WARNING,
AccessDeniedHttpException::class => Logger::WARNING,
NotFoundHttpException::class => Logger::WARNING,
UnauthorizedHttpException::class => Logger::WARNING,
private const string DEFAULT_LOG_FORMAT = "[%%datetime%%][%%token_collection%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n";
private const string DEFAULT_SLACK_CHANNEL = '#random';
private const string DEFAULT_SLACK_ICON_EMOJI = ':warning';
private const array DEFAULT_HTTP_EXCEPTIONS_LEVELS = [
BadRequestHttpException::class => Level::Warning->value,
AccessDeniedHttpException::class => Level::Warning->value,
NotFoundHttpException::class => Level::Warning->value,
UnauthorizedHttpException::class => Level::Warning->value,
];

public function getConfigTreeBuilder(): TreeBuilder
Expand All @@ -41,14 +41,14 @@ public function getConfigTreeBuilder(): TreeBuilder
->defaultValue(self::DEFAULT_HTTP_EXCEPTIONS_LEVELS)
->useAttributeAsKey('name')
->prototype('enum')->values([
Logger::DEBUG,
Logger::INFO,
Logger::NOTICE,
Logger::WARNING,
Logger::ERROR,
Logger::CRITICAL,
Logger::ALERT,
Logger::EMERGENCY,
Level::Debug->value,
Level::Info->value,
Level::Notice->value,
Level::Warning->value,
Level::Error->value,
Level::Critical->value,
Level::Alert->value,
Level::Emergency->value,
])->end()
->end()
->arrayNode('custom_exceptions_levels')
Expand All @@ -62,13 +62,12 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('token')->cannotBeEmpty()->defaultValue('')->end()
->scalarNode('channel')->cannotBeEmpty()->defaultValue(self::DEFAULT_SLACK_CHANNEL)->end()
->scalarNode('icon_emoji')->cannotBeEmpty()->defaultValue(self::DEFAULT_SLACK_ICON_EMOJI)->end()
->scalarNode('log_level')->cannotBeEmpty()->defaultValue(Logger::ERROR)->end()
->scalarNode('log_level')->cannotBeEmpty()->defaultValue(Level::Error->value)->end()
->scalarNode('jira_url')->cannotBeEmpty()->defaultValue('')->end()
->scalarNode('kibana_url')->cannotBeEmpty()->defaultValue('')->end()
->end()
->end()
->end()
;
->end();

return $treeBuilder;
}
Expand Down
10 changes: 6 additions & 4 deletions EventSubscriber/TracingEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
/** @internal */
final class TracingEventSubscriber implements EventSubscriberInterface
{
private const HIGHEST_PRIORITY = 512;
private const LOWEST_PRIORITY = -512;
private const int HIGHEST_PRIORITY = 512;
private const int LOWEST_PRIORITY = -512;

public function __construct(private TokenCollection $tokenCollection, private HttpFoundation $httpFoundation)
{
public function __construct(
private readonly TokenCollection $tokenCollection,
private readonly HttpFoundation $httpFoundation,
) {
}

public function onKernelRequest(RequestEvent $event): void
Expand Down
4 changes: 2 additions & 2 deletions Monolog/Formatter/TokenCollectionFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
final class TokenCollectionFormatter extends LineFormatter
{
public function __construct(
private TokenCollection $tokenCollection,
private ?string $originalFormat = null,
private readonly TokenCollection $tokenCollection,
private readonly ?string $originalFormat = null,
?string $dateFormat = null,
bool $allowInlineLineBreaks = false,
bool $ignoreEmptyContextAndExtra = false,
Expand Down
6 changes: 3 additions & 3 deletions Monolog/Handler/ContentDataModifier/AddJiraLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
/** @internal */
final class AddJiraLink implements ContentDataModifierInterface
{
private const JIRA_PATH = '/secure/CreateIssue.jspa';
private const string JIRA_PATH = '/secure/CreateIssue.jspa';

private const URI_PARAMS = [
private const array URI_PARAMS = [
'pid=10631', // Project ID
'issueType=1', // Bug
'summary=%1$s', // Replaced by log message
'description=%1$s', // Replaced by log message
];

public function __construct(private string $jiraUrl)
public function __construct(private readonly string $jiraUrl)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
final class AddKibanaTokenFilterLinks implements ContentDataModifierInterface
{
// phpcs:disable Generic.Files.LineLength.TooLong
private const KIBANA_URI_PATTERN = '#/?_g=(filters:!(),time:(from:now-24h,to:now))&_a=(columns:!(_source),filters:!((\'$state\':(store:appState),meta:(alias:!n,disabled:!f,key:%1$s,negate:!f,params:(query:%2$s),type:phrase),query:(match_phrase:(%1$s:%2$s)))),interval:auto,query:(language:kuery,query:\'\'),sort:!())';
private const string KIBANA_URI_PATTERN = '#/?_g=(filters:!(),time:(from:now-24h,to:now))&_a=(columns:!(_source),filters:!((\'$state\':(store:appState),meta:(alias:!n,disabled:!f,key:%1$s,negate:!f,params:(query:%2$s),type:phrase),query:(match_phrase:(%1$s:%2$s)))),interval:auto,query:(language:kuery,query:\'\'),sort:!())';

public function __construct(private string $kibanaUrl, private TokenCollection $tokenCollection)
public function __construct(private readonly string $kibanaUrl, private readonly TokenCollection $tokenCollection)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests\ETSGlobal\LogBundle\Monolog\Handler\ContentDataModifier;

use ETSGlobal\LogBundle\Monolog\Handler\ContentDataModifier\AddClassLineContext;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/** @internal */
Expand All @@ -17,7 +18,7 @@ protected function setUp(): void
$this->modifier = new AddClassLineContext();
}

/** @dataProvider modifyDataProvider */
#[DataProvider('modifyDataProvider')]
public function testAddsClassLineToAttachements(array $record, array $expectedContentData): void
{
$contentData = [];
Expand All @@ -27,7 +28,7 @@ public function testAddsClassLineToAttachements(array $record, array $expectedCo
$this->assertEquals($expectedContentData, $contentData);
}

public function modifyDataProvider(): array
public static function modifyDataProvider(): array
{
return [
[
Expand Down
5 changes: 3 additions & 2 deletions Tests/Monolog/Handler/ContentDataModifier/AddJiraLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests\ETSGlobal\LogBundle\Monolog\Handler\ContentDataModifier;

use ETSGlobal\LogBundle\Monolog\Handler\ContentDataModifier\AddJiraLink;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/** @internal */
Expand All @@ -17,7 +18,7 @@ protected function setUp(): void
$this->modifier = new AddJiraLink('https://example.jira.com');
}

/** @dataProvider modifyDataProvider */
#[DataProvider('modifyDataProvider')]
public function testAddsJiraLink(array $record, array $expectedContentData): void
{
$contentData = [];
Expand All @@ -27,7 +28,7 @@ public function testAddsJiraLink(array $record, array $expectedContentData): voi
$this->assertEquals($expectedContentData, $contentData);
}

public function modifyDataProvider(): array
public static function modifyDataProvider(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ETSGlobal\LogBundle\Monolog\Handler\ContentDataModifier\AddKibanaTokenFilterLinks;
use ETSGlobal\LogBundle\Tracing\TokenCollection;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/** @internal */
Expand All @@ -25,7 +26,7 @@ protected function setUp(): void
);
}

/** @dataProvider modifyDataProvider */
#[DataProvider('modifyDataProvider')]
public function testAddsTokensToContents(array $record, array $tokens, array $expectedContentData): void
{
$contentData = [];
Expand All @@ -39,7 +40,7 @@ public function testAddsTokensToContents(array $record, array $tokens, array $ex
$this->assertEquals($expectedContentData, $contentData);
}

public function modifyDataProvider(): array
public static function modifyDataProvider(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ETSGlobal\LogBundle\Monolog\Handler\ExclusionStrategy\StatusCodesHttpExceptionExclusionStrategy;
use Monolog\Logger;
use Monolog\LogRecord;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
Expand Down Expand Up @@ -56,15 +57,15 @@ public function testDoesNotExcludeRecordWhenInvalidException(): void
);
}

public function exceptionProvider(): array
public static function exceptionProvider(): array
{
return [
[new ConflictHttpException()],
[new GoneHttpException()],
];
}

/** @dataProvider exceptionProvider */
#[DataProvider('exceptionProvider')]
public function testDoesNotExcludeRecordsWhenStatusCodesNotExcluded(\Throwable $exception): void
{
$this->assertFalse(
Expand All @@ -81,15 +82,15 @@ public function testDoesNotExcludeRecordsWhenStatusCodesNotExcluded(\Throwable $
);
}

public function excludedExceptionProvider(): array
public static function excludedExceptionProvider(): array
{
return [
[new BadRequestHttpException()],
[new NotFoundHttpException()],
];
}

/** @dataProvider excludedExceptionProvider */
#[DataProvider('excludedExceptionProvider')]
public function testExcludesRecordsWhenExcludedExceptionCodes(\Throwable $exception): void
{
$this->assertTrue(
Expand Down
5 changes: 3 additions & 2 deletions Tests/Monolog/Handler/IgnoreDeprecationHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
use ETSGlobal\LogBundle\Monolog\Handler\IgnoreDeprecationHandler;
use Monolog\Logger;
use Monolog\LogRecord;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class IgnoreDeprecationHandlerTest extends TestCase
{
public function provideData(): array
public static function provideData(): array
{
return [
[
Expand Down Expand Up @@ -50,7 +51,7 @@ public function provideData(): array
];
}

/** @dataProvider provideData */
#[DataProvider('provideData')]
public function testHandle(LogRecord $record, bool $expected): void
{
$handler = new IgnoreDeprecationHandler();
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"require": {
"php": "^8.3",
"ext-json": "*",
"graylog2/gelf-php": "^2.0",
"symfony/config": "^7.0",
"symfony/console": "^7.0",
"symfony/dependency-injection": "^7.0",
Expand Down
20 changes: 6 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<coverage>
<include>
<directory>.</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache">
<php>
<ini name="error_reporting" value="-1"/>
</php>
Expand All @@ -19,7 +9,9 @@
<directory>Tests</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
<source>
<include>
<directory>.</directory>
</include>
</source>
</phpunit>
Loading