Skip to content

Commit c77b2b2

Browse files
committed
Add symplify/easy-coding-standard
1 parent 73ebc25 commit c77b2b2

13 files changed

+164
-152
lines changed

Makefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,13 @@ yamllint: ## Lints yaml files
3333
phpstan: ## Static analysis
3434
$(EXEC_PHP) phpstan
3535

36+
.PHONY: cs
37+
cs: ## Coding standards check
38+
$(EXEC_PHP) ecs check
39+
40+
.PHONY: cs
41+
cs-fix: ## Coding standards fix
42+
$(EXEC_PHP) ecs check --fix
43+
3644
.PHONY: all
37-
all: phpstan yamllint ## Runs all test/lint targets
45+
all: phpstan yamllint cs ## Runs all test/lint targets

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"phpstan/phpstan": "^0.12.85",
2525
"phpstan/phpstan-deprecation-rules": "^0.12.6",
2626
"phpstan/phpstan-strict-rules": "^0.12.9",
27-
"phpunit/phpunit": "^9.5"
27+
"phpunit/phpunit": "^9.5",
28+
"symplify/easy-coding-standard": "^9.3"
2829
},
2930
"config": {
3031
"preferred-install": "dist",

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ services:
99
volumes:
1010
- '.:/usr/src/app'
1111
command: 'tail -f /dev/null'
12+
environment:
13+
PHP_EXTENSIONS: 'intl pdo_sqlite'

ecs.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
4+
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
5+
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
6+
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
7+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
8+
use Symplify\CodingStandard\Fixer\Spacing\MethodChainingNewlineFixer;
9+
use Symplify\EasyCodingStandard\ValueObject\Option;
10+
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
11+
12+
return static function (ContainerConfigurator $containerConfigurator): void {
13+
$services = $containerConfigurator->services();
14+
$services->set(ArraySyntaxFixer::class)
15+
->call('configure', [[
16+
'syntax' => 'short',
17+
]]);
18+
19+
$containerConfigurator->import(SetList::PSR_12);
20+
$containerConfigurator->import(SetList::PHP_CS_FIXER);
21+
$containerConfigurator->import(SetList::PHP_CS_FIXER_RISKY);
22+
$containerConfigurator->import(SetList::SYMPLIFY);
23+
$containerConfigurator->import(SetList::SYMFONY);
24+
$containerConfigurator->import(SetList::SYMFONY_RISKY);
25+
$containerConfigurator->import(SetList::COMMON);
26+
$containerConfigurator->import(SetList::CLEAN_CODE);
27+
28+
$parameters = $containerConfigurator->parameters();
29+
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
30+
$parameters->set(Option::SKIP, [
31+
MethodChainingIndentationFixer::class => [
32+
__DIR__ . '/src/DependencyInjection/Configuration.php',
33+
],
34+
MethodChainingNewlineFixer::class => [
35+
__DIR__ . '/src/DependencyInjection/Configuration.php',
36+
],
37+
YodaStyleFixer::class => [
38+
__DIR__,
39+
],
40+
NotOperatorWithSuccessorSpaceFixer::class => [
41+
__DIR__,
42+
],
43+
]);
44+
};

phpstan.neon

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ parameters:
1515
includes:
1616
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
1717
- vendor/phpstan/phpstan-strict-rules/rules.neon
18+
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

src/Behat/Listener/ProfilerToolbarListener.php

+36-37
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,34 @@
22

33
namespace Sourceability\ConsoleToolbarBundle\Behat\Listener;
44

5+
use function array_filter;
56
use Behat\Behat\EventDispatcher\Event\ScenarioTested;
67
use Behat\Behat\EventDispatcher\Event\StepTested;
8+
use function max;
79
use Sourceability\ConsoleToolbarBundle\Console\ProfilerToolbarRenderer;
810
use Sourceability\ConsoleToolbarBundle\Profiler\RecentProfileLoader;
11+
use function sprintf;
912
use Symfony\Component\Console\Output\ConsoleOutput;
1013
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1114
use Symfony\Component\HttpKernel\KernelInterface;
1215
use Symfony\Component\HttpKernel\Profiler\Profile;
1316
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1417
use Symfony\Component\Routing\RequestContext;
1518
use Symfony\Component\Routing\Router;
16-
use function array_filter;
17-
use function count;
18-
use function in_array;
19-
use function max;
20-
use function sprintf;
2119
use function time;
2220

2321
class ProfilerToolbarListener implements EventSubscriberInterface
2422
{
25-
/**
26-
* {@inheritdoc}
27-
*/
28-
public static function getSubscribedEvents()
29-
{
30-
return [
31-
ScenarioTested::BEFORE => ['beforeScenario', 10],
32-
StepTested::BEFORE => ['beforeAfterStep', 10],
33-
StepTested::AFTER => ['beforeAfterStep', 10],
34-
ScenarioTested::AFTER => ['afterScenario', 10],
35-
];
36-
}
37-
3823
private RecentProfileLoader $recentProfileLoader;
24+
3925
private ProfilerToolbarRenderer $profilerToolbarRenderer;
26+
4027
private Router $router;
28+
4129
private RequestContext $originalRouterContext;
4230

4331
private ?int $beforeScenarioTimestamp = null;
32+
4433
private ?int $lastProfileTimestamp = null;
4534

4635
/**
@@ -50,20 +39,36 @@ public static function getSubscribedEvents()
5039

5140
public function __construct(KernelInterface $kernel)
5241
{
53-
$recentProfileLoader = $kernel->getContainer()->get('sourceability.console_toolbar.profiler.recent_profile_loader');
54-
$profilerToolbarRenderer = $kernel->getContainer()->get('sourceability.console_toolbar.console.profiler_toolbar_renderer');
55-
$router = $kernel->getContainer()->get('router');
56-
57-
assert($recentProfileLoader instanceof RecentProfileLoader);
58-
assert($profilerToolbarRenderer instanceof ProfilerToolbarRenderer);
59-
assert($router instanceof Router);
42+
$recentProfileLoader = $kernel->getContainer()
43+
->get('sourceability.console_toolbar.profiler.recent_profile_loader')
44+
;
45+
$profilerToolbarRenderer = $kernel->getContainer()
46+
->get('sourceability.console_toolbar.console.profiler_toolbar_renderer')
47+
;
48+
$router = $kernel->getContainer()
49+
->get('router')
50+
;
51+
52+
\assert($recentProfileLoader instanceof RecentProfileLoader);
53+
\assert($profilerToolbarRenderer instanceof ProfilerToolbarRenderer);
54+
\assert($router instanceof Router);
6055

6156
$this->recentProfileLoader = $recentProfileLoader;
6257
$this->profilerToolbarRenderer = $profilerToolbarRenderer;
6358
$this->router = $router;
6459
$this->originalRouterContext = clone $this->router->getContext(); // clone is important here, we're making a copy
6560
}
6661

62+
public static function getSubscribedEvents()
63+
{
64+
return [
65+
ScenarioTested::BEFORE => ['beforeScenario', 10],
66+
StepTested::BEFORE => ['beforeAfterStep', 10],
67+
StepTested::AFTER => ['beforeAfterStep', 10],
68+
ScenarioTested::AFTER => ['afterScenario', 10],
69+
];
70+
}
71+
6772
public function beforeScenario(ScenarioTested $event): void
6873
{
6974
$this->beforeScenarioTimestamp = time();
@@ -77,18 +82,15 @@ public function beforeAfterStep(StepTested $event): void
7782

7883
$profiles = array_filter(
7984
$profiles,
80-
fn (Profile $newProfile) => !in_array($newProfile->getToken(), $this->profileTokensShown, true)
85+
fn (Profile $newProfile) => !\in_array($newProfile->getToken(), $this->profileTokensShown, true)
8186
);
8287

83-
if (count($profiles) > 0) {
88+
if (\count($profiles) > 0) {
8489
$this->profilerToolbarRenderer->render(new ConsoleOutput(), $profiles);
8590
}
8691

8792
foreach ($profiles as $profile) {
88-
$this->lastProfileTimestamp = max(
89-
$this->lastProfileTimestamp ?? 0,
90-
$profile->getTime()
91-
);
93+
$this->lastProfileTimestamp = max($this->lastProfileTimestamp ?? 0, $profile->getTime());
9294
$this->profileTokensShown[] = $profile->getToken();
9395
}
9496
}
@@ -110,19 +112,16 @@ public function afterScenario(ScenarioTested $event): void
110112
[
111113
'start' => $from,
112114
'end' => $to,
113-
'limit' => 100, // required otherwise list has no items
115+
'limit' => 100,
116+
// required otherwise list has no items
114117
],
115118
UrlGeneratorInterface::ABSOLUTE_URL
116119
);
117120
});
118121

119122
$output = new ConsoleOutput();
120123
$output->writeln(
121-
sprintf(
122-
'%d profiles collected, <href=%s>Open profile list</>',
123-
$profileCount,
124-
$profilerUrl
125-
)
124+
sprintf('%d profiles collected, <href=%s>Open profile list</>', $profileCount, $profilerUrl)
126125
);
127126
}
128127

src/Behat/SymfonyProfilerExtension.php

+1-18
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,26 @@
1414

1515
class SymfonyProfilerExtension implements ExtensionInterface
1616
{
17-
/**
18-
* {@inheritdoc}
19-
*/
2017
public function process(ContainerBuilder $container): void
2118
{
2219
}
2320

24-
/**
25-
* {@inheritdoc}
26-
*/
2721
public function getConfigKey()
2822
{
2923
return 'sourceability_instrumentation';
3024
}
3125

32-
/**
33-
* {@inheritdoc}
34-
*/
3526
public function initialize(ExtensionManager $extensionManager): void
3627
{
3728
}
3829

39-
/**
40-
* {@inheritdoc}
41-
*/
4230
public function configure(ArrayNodeDefinition $builder): void
4331
{
4432
}
4533

46-
/**
47-
* {@inheritdoc}
48-
*/
4934
public function load(ContainerBuilder $container, array $config): void
5035
{
51-
$definition = new Definition(ProfilerToolbarListener::class, [
52-
new Reference(SymfonyExtension::KERNEL_ID),
53-
]);
36+
$definition = new Definition(ProfilerToolbarListener::class, [new Reference(SymfonyExtension::KERNEL_ID)]);
5437
$definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG);
5538
$container->setDefinition(ProfilerToolbarListener::class, $definition);
5639
}

0 commit comments

Comments
 (0)