Skip to content

Commit 3c33ba5

Browse files
authored
Merge pull request #20 from minvws/replace-yml-driver
2 parents fa12aa3 + 8cdfc3b commit 3c33ba5

6 files changed

Lines changed: 65 additions & 45 deletions

File tree

phpstan-baseline.neon

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#1 \\$config \\(array\\{encryption\\: array\\{public_key\\: string, private_key\\: string\\}, loggers\\: array\\{psr_logger\\?\\: array\\{enabled\\: bool, encrypted\\: bool, log_pii\\: bool\\}, doctrine_logger\\?\\: array\\{enabled\\: bool, encrypted\\: bool, log_pii\\: bool\\}, file_logger\\?\\: array\\{enabled\\: bool, encrypted\\: bool, log_pii\\: bool, path\\: string\\}, rabbitmq_logger\\?\\: array\\{enabled\\: bool, encrypted\\: bool, log_pii\\: bool, path\\: string, producer_service\\: string, routing_key\\: string, additional_events\\: array\\<string, string\\>\\}\\}\\}\\) of method MinVWS\\\\AuditLoggerBundle\\\\AuditLoggerBundle\\:\\:loadExtension\\(\\) should be contravariant with parameter \\$config \\(array\\) of method Symfony\\\\Component\\\\DependencyInjection\\\\Extension\\\\ConfigurableExtensionInterface\\:\\:loadExtension\\(\\)$#"
5+
count: 1
6+
path: src/AuditLoggerBundle.php
7+
8+
-
9+
message: "#^Parameter \\#1 \\$config \\(array\\{encryption\\: array\\{public_key\\: string, private_key\\: string\\}, loggers\\: array\\{psr_logger\\?\\: array\\{enabled\\: bool, encrypted\\: bool, log_pii\\: bool\\}, doctrine_logger\\?\\: array\\{enabled\\: bool, encrypted\\: bool, log_pii\\: bool\\}, file_logger\\?\\: array\\{enabled\\: bool, encrypted\\: bool, log_pii\\: bool, path\\: string\\}, rabbitmq_logger\\?\\: array\\{enabled\\: bool, encrypted\\: bool, log_pii\\: bool, path\\: string, producer_service\\: string, routing_key\\: string, additional_events\\: array\\<string, string\\>\\}\\}\\}\\) of method MinVWS\\\\AuditLoggerBundle\\\\AuditLoggerBundle\\:\\:loadExtension\\(\\) should be contravariant with parameter \\$config \\(array\\) of method Symfony\\\\Component\\\\HttpKernel\\\\Bundle\\\\AbstractBundle\\:\\:loadExtension\\(\\)$#"
10+
count: 1
11+
path: src/AuditLoggerBundle.php

phpstan.neon.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
includes:
2+
- phpstan-baseline.neon
23
- vendor/phpstan/phpstan-mockery/extension.neon
34
- vendor/phpstan/phpstan-strict-rules/rules.neon
45
- vendor/phpstan/phpstan-symfony/extension.neon
@@ -10,5 +11,3 @@ parameters:
1011
- tests
1112
tmpDir: ./.phpstan.cache
1213
level: max
13-
excludePaths:
14-
- src/AuditLoggerBundle.php

sonar-project.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ sonar.php.coverage.reportPaths=coverage-phpunit.xml
1919

2020
# Additional reports
2121
sonar.php.phpstan.reportPaths=phpstan.json
22+
23+
sonar.coverage.exclusions=\
24+
src/AuditLoggerBundle.php

src/AuditLoggerBundle.php

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,57 @@
1212
use MinVWS\AuditLoggerBundle\Loggers\DoctrineLogger;
1313
use MinVWS\AuditLoggerBundle\Loggers\RabbitmqLogger;
1414
use OldSound\RabbitMqBundle\OldSoundRabbitMqBundle;
15+
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1516
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
1819
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1920
use Symfony\Component\DependencyInjection\Reference;
2021
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
2122

23+
use function realpath;
24+
25+
/**
26+
* @phpstan-type ConfigEncryptionArray array{public_key: string, private_key: string}
27+
* @phpstan-type ConfigLoggersArray array{
28+
* enabled: bool,
29+
* encrypted: bool,
30+
* log_pii: bool,
31+
* }
32+
* @phpstan-type ConfigFileLoggersArray array{
33+
* enabled: bool,
34+
* encrypted: bool,
35+
* log_pii: bool,
36+
* path: string,
37+
* }
38+
* @phpstan-type ConfigRabbitMqLoggersArray array{
39+
* enabled: bool,
40+
* encrypted: bool,
41+
* log_pii: bool,
42+
* path: string,
43+
* producer_service: string,
44+
* routing_key: string,
45+
* additional_events: array<string,string>,
46+
* }
47+
* @phpstan-type ConfigArray array{
48+
* encryption: ConfigEncryptionArray,
49+
* loggers: array{
50+
* psr_logger?: ConfigLoggersArray,
51+
* doctrine_logger?: ConfigLoggersArray,
52+
* file_logger?: ConfigFileLoggersArray,
53+
* rabbitmq_logger?: ConfigRabbitMqLoggersArray,
54+
* }
55+
* }
56+
*/
2257
class AuditLoggerBundle extends AbstractBundle
2358
{
2459
public function configure(DefinitionConfigurator $definition): void
2560
{
26-
$definition->rootNode()
61+
$arrayDef = $definition->rootNode();
62+
63+
assert($arrayDef instanceof ArrayNodeDefinition);
64+
65+
$arrayDef
2766
->children()
2867
->arrayNode('encryption')
2968
->children()
@@ -76,6 +115,9 @@ public function configure(DefinitionConfigurator $definition): void
76115
->end();
77116
}
78117

118+
/**
119+
* @phpstan-param ConfigArray $config
120+
*/
79121
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
80122
{
81123
$container->import('Resources/config/services.yml');
@@ -159,11 +201,14 @@ public function build(ContainerBuilder $container): void
159201
{
160202
parent::build($container);
161203

162-
$mappings = [
163-
realpath(__DIR__ . '/Resources/config/doctrine') => 'MinVWS\AuditLoggerBundle\Entity',
164-
];
204+
$path = realpath(__DIR__ . '/Entity');
205+
assert($path !== false);
165206

166-
$container->addCompilerPass(DoctrineOrmMappingsPass::createYamlMappingDriver($mappings));
207+
$container->addCompilerPass(DoctrineOrmMappingsPass::createAttributeMappingDriver(
208+
['MinVWS\AuditLoggerBundle\Entity'],
209+
[$path],
210+
reportFieldsWhereDeclared: true,
211+
));
167212
}
168213

169214
public function getAlias(): string

src/Resources/config/doctrine/AuditEntry.orm.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Resources/config/doctrine/EncryptedAuditEntry.orm.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)