Skip to content

Commit 7fe4fbd

Browse files
HypeMCderrabus
authored andcommitted
Add PHP-CS-Fixer
1 parent b2b5f9a commit 7fe4fbd

22 files changed

+917
-875
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ on:
55
pull_request:
66

77
jobs:
8+
php-cs-fixer:
9+
runs-on: ubuntu-latest
10+
name: Coding Standards
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Setup PHP
16+
uses: shivammathur/setup-php@v2
17+
18+
with:
19+
php-version: 8.3
20+
coverage: none
21+
tools: php-cs-fixer, cs2pr
22+
23+
- name: Run PHP-CS-Fixer
24+
run: php-cs-fixer fix --dry-run --format checkstyle | cs2pr
25+
826
test:
927
runs-on: ubuntu-latest
1028
name: PHPUnit Tests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vendor
2+
.php-cs-fixer.cache
23
composer.phar
34
composer.lock
45
phpunit.xml

.php-cs-fixer.dist.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
$fileHeaderComment = <<<'EOF'
13+
This file is part of the Symfony package.
14+
15+
(c) Fabien Potencier <fabien@symfony.com>
16+
17+
For the full copyright and license information, please view the LICENSE
18+
file that was distributed with this source code.
19+
EOF;
20+
21+
return (new PhpCsFixer\Config())
22+
->setRules([
23+
'@PHP71Migration' => true,
24+
'@PHPUnit75Migration:risky' => true,
25+
'@Symfony' => true,
26+
'@Symfony:risky' => true,
27+
'protected_to_private' => false,
28+
'header_comment' => ['header' => $fileHeaderComment],
29+
'modernize_strpos' => false,
30+
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match', 'parameters']],
31+
])
32+
->setRiskyAllowed(true)
33+
->setFinder(
34+
PhpCsFixer\Finder::create()
35+
->in([__DIR__])
36+
->append([__FILE__])
37+
)
38+
;

DependencyInjection/Compiler/AddProcessorsPass.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ public function process(ContainerBuilder $container)
3434
foreach ($container->findTaggedServiceIds('monolog.processor') as $id => $tags) {
3535
foreach ($tags as $tag) {
3636
if (!empty($tag['channel']) && !empty($tag['handler'])) {
37-
throw new \InvalidArgumentException(sprintf('you cannot specify both the "handler" and "channel" attributes for the "monolog.processor" tag on service "%s"', $id));
37+
throw new \InvalidArgumentException(\sprintf('you cannot specify both the "handler" and "channel" attributes for the "monolog.processor" tag on service "%s"', $id));
3838
}
3939

4040
if (!empty($tag['handler'])) {
41-
$definition = $container->findDefinition(sprintf('monolog.handler.%s', $tag['handler']));
41+
$definition = $container->findDefinition(\sprintf('monolog.handler.%s', $tag['handler']));
4242
$parentDef = $definition;
4343
while (!$parentDef->getClass() && $parentDef instanceof ChildDefinition) {
4444
$parentDef = $container->findDefinition($parentDef->getParent());
4545
}
4646
$class = $container->getParameterBag()->resolveValue($parentDef->getClass());
4747
if (!method_exists($class, 'pushProcessor')) {
48-
throw new \InvalidArgumentException(sprintf('The "%s" handler does not accept processors', $tag['handler']));
48+
throw new \InvalidArgumentException(\sprintf('The "%s" handler does not accept processors', $tag['handler']));
4949
}
5050
} elseif (!empty($tag['channel'])) {
5151
if ('app' === $tag['channel']) {
5252
$definition = $container->getDefinition('monolog.logger');
5353
} else {
54-
$definition = $container->getDefinition(sprintf('monolog.logger.%s', $tag['channel']));
54+
$definition = $container->getDefinition(\sprintf('monolog.logger.%s', $tag['channel']));
5555
}
5656
} else {
5757
$definition = $container->getDefinition('monolog.logger_prototype');

DependencyInjection/Compiler/AddSwiftMailerTransportPass.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\ContainerBuilder;
1514
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Reference;
1717

1818
/**
@@ -25,9 +25,6 @@
2525
*/
2626
class AddSwiftMailerTransportPass implements CompilerPassInterface
2727
{
28-
/**
29-
* {@inheritdoc}
30-
*/
3128
public function process(ContainerBuilder $container)
3229
{
3330
$handlers = $container->getParameter('monolog.swift_mailer.handlers');

DependencyInjection/Compiler/DebugHandlerPass.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Reference;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
14+
use Monolog\Logger;
1615
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Definition;
18-
use Monolog\Logger;
18+
use Symfony\Component\DependencyInjection\Reference;
1919

2020
/**
2121
* Adds the DebugHandler when the profiler is enabled and kernel.debug is true.
@@ -31,7 +31,7 @@ class DebugHandlerPass implements CompilerPassInterface
3131

3232
public function __construct(LoggerChannelPass $channelPass)
3333
{
34-
@trigger_error('The '.__CLASS__.' class is deprecated since version 2.12 and will be removed in 4.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.', E_USER_DEPRECATED);
34+
@trigger_error('The '.__CLASS__.' class is deprecated since version 2.12 and will be removed in 4.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.', \E_USER_DEPRECATED);
3535

3636
$this->channelPass = $channelPass;
3737
}
@@ -51,7 +51,7 @@ public function process(ContainerBuilder $container)
5151

5252
foreach ($this->channelPass->getChannels() as $channel) {
5353
$container
54-
->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel)
54+
->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel)
5555
->addMethodCall('pushHandler', [new Reference('monolog.handler.debug')]);
5656
}
5757
}

DependencyInjection/Compiler/FixEmptyLoggerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function process(ContainerBuilder $container)
4444
{
4545
$container->register('monolog.handler.null_internal', 'Monolog\Handler\NullHandler');
4646
foreach ($this->channelPass->getChannels() as $channel) {
47-
$def = $container->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel);
47+
$def = $container->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel);
4848
foreach ($def->getMethodCalls() as $method) {
4949
if ('pushHandler' === $method[0]) {
5050
continue 2;

DependencyInjection/Compiler/LoggerChannelPass.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ class LoggerChannelPass implements CompilerPassInterface
3030
{
3131
protected $channels = ['app'];
3232

33-
/**
34-
* {@inheritDoc}
35-
*/
3633
public function process(ContainerBuilder $container)
3734
{
3835
if (!$container->hasDefinition('monolog.logger')) {
@@ -49,7 +46,7 @@ public function process(ContainerBuilder $container)
4946
$resolvedChannel = $container->getParameterBag()->resolveValue($tag['channel']);
5047

5148
$definition = $container->getDefinition($id);
52-
$loggerId = sprintf('monolog.logger.%s', $resolvedChannel);
49+
$loggerId = \sprintf('monolog.logger.%s', $resolvedChannel);
5350
$this->createLogger($resolvedChannel, $loggerId, $container);
5451

5552
foreach ($definition->getArguments() as $index => $argument) {
@@ -84,10 +81,10 @@ public function process(ContainerBuilder $container)
8481

8582
// create additional channels
8683
foreach ($container->getParameter('monolog.additional_channels') as $chan) {
87-
if ($chan === 'app') {
84+
if ('app' === $chan) {
8885
continue;
8986
}
90-
$loggerId = sprintf('monolog.logger.%s', $chan);
87+
$loggerId = \sprintf('monolog.logger.%s', $chan);
9188
$this->createLogger($chan, $loggerId, $container);
9289
$container->getDefinition($loggerId)->setPublic(true);
9390
}
@@ -98,7 +95,7 @@ public function process(ContainerBuilder $container)
9895
foreach ($handlersToChannels as $handler => $channels) {
9996
foreach ($this->processChannels($channels) as $channel) {
10097
try {
101-
$logger = $container->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel);
98+
$logger = $container->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel);
10299
} catch (InvalidArgumentException $e) {
103100
$msg = 'Monolog configuration error: The logging channel "'.$channel.'" assigned to the "'.substr($handler, 16).'" handler does not exist.';
104101
throw new \InvalidArgumentException($msg, 0, $e);
@@ -133,20 +130,20 @@ protected function processChannels(?array $configuration)
133130
}
134131

135132
/**
136-
* Create new logger from the monolog.logger_prototype
133+
* Create new logger from the monolog.logger_prototype.
137134
*
138135
* @return void
139136
*/
140137
protected function createLogger(string $channel, string $loggerId, ContainerBuilder $container)
141138
{
142-
if (!in_array($channel, $this->channels)) {
139+
if (!\in_array($channel, $this->channels)) {
143140
$logger = new ChildDefinition('monolog.logger_prototype');
144141
$logger->replaceArgument(0, $channel);
145142
$container->setDefinition($loggerId, $logger);
146143
$this->channels[] = $channel;
147144
}
148145

149-
$parameterName = $channel . 'Logger';
146+
$parameterName = $channel.'Logger';
150147

151148
$container->registerAliasForArgument($loggerId, LoggerInterface::class, $parameterName);
152149
}

0 commit comments

Comments
 (0)