Skip to content

Commit ba42824

Browse files
authored
Merge pull request #282 from php-school/cs-fixer
Use php-cs-fixer
2 parents 5b1d6f1 + 2a15681 commit ba42824

File tree

122 files changed

+725
-215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+725
-215
lines changed

.github/workflows/php.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: shivammathur/setup-php@v2
2424
with:
2525
php-version: ${{ matrix.php }}
26-
tools: composer:v2
26+
tools: composer:v2, cs2pr
2727

2828
- name: Install PHP Dependencies
2929
run: composer install --prefer-dist
@@ -32,7 +32,7 @@ jobs:
3232
run: composer phpunit
3333

3434
- name: Run phpcs
35-
run: composer cs
35+
run: composer cs:ci
3636

3737
- name: Run PHPStan
38-
run: composer static
38+
run: composer static

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea
22
node_modules
33
.DS_Store
4+
.php-cs-fixer.cache
45
npm-debug.log
56
/vendor/
67
/logs/*

.php-cs-fixer.dist.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$finder = (new PhpCsFixer\Finder())
4+
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/test')
6+
->in(__DIR__ . '/app')
7+
;
8+
9+
return (new PhpCsFixer\Config())
10+
->setRules([
11+
'@PER-CS2.0' => true,
12+
'declare_strict_types' => true,
13+
'no_unused_imports' => true,
14+
])
15+
->setFinder($finder);

app/config.php

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use ahinkle\PackagistLatestVersion\PackagistLatestVersion;
46
use DI\Bridge\Slim\Bridge;
57
use Doctrine\DBAL\Types\Type;
@@ -10,7 +12,6 @@
1012
use Doctrine\ORM\Tools\Console\ConsoleRunner;
1113
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
1214
use Github\Client;
13-
use Jenssegers\Agent\Agent;
1415
use League\CommonMark\Extension\CommonMarkCoreExtension;
1516
use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension;
1617
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
@@ -52,7 +53,6 @@
5253
use PhpSchool\Website\Online\CloudWorkshopRepository;
5354
use PhpSchool\Website\Online\Command\DownloadComposerPackageList;
5455
use PhpSchool\Website\Online\Middleware\ExerciseRunnerRateLimiter;
55-
use PhpSchool\Website\Online\Middleware\Styles;
5656
use PhpSchool\Website\Online\PathGenerator;
5757
use PhpSchool\Website\Online\ProblemFileConverter;
5858
use PhpSchool\Website\Online\ProjectUploader;
@@ -101,6 +101,7 @@
101101
use Symfony\Component\RateLimiter\Storage\CacheStorage;
102102
use Symfony\Contracts\Cache\CacheInterface;
103103
use Tuupola\Middleware\JwtAuthentication;
104+
104105
use function DI\factory;
105106
use function DI\get;
106107

@@ -121,7 +122,7 @@
121122
$app = Bridge::create($c);
122123
$app->addRoutingMiddleware();
123124

124-
$app->add(function (Request $request, RequestHandler $handler) use($c) : Response {
125+
$app->add(function (Request $request, RequestHandler $handler) use ($c): Response {
125126
/** @var Session $session */
126127
$session = $this->get(Session::class);
127128

@@ -139,7 +140,7 @@
139140
}),
140141
'cache' => factory(function (ContainerInterface $c): CacheInterface {
141142
if (!$c->get('config')['enableCache']) {
142-
return new NullAdapter;
143+
return new NullAdapter();
143144
}
144145

145146
$redisConnection = new \Predis\Client(['host' => $c->get('config')['redisHost']]);
@@ -157,18 +158,18 @@
157158

158159
return new RedisAdapter($redisConnection, 'default');
159160
}),
160-
LoggerInterface::class => factory(function (ContainerInterface $c): LoggerInterface{
161+
LoggerInterface::class => factory(function (ContainerInterface $c): LoggerInterface {
161162
$settings = $c->get('config')['logger'];
162163
$logger = new Logger($settings['name']);
163-
$logger->pushProcessor(new UidProcessor);
164+
$logger->pushProcessor(new UidProcessor());
164165
$logger->pushHandler(new StreamHandler($settings['path'], Logger::DEBUG));
165166
return $logger;
166167
}),
167168

168169
SessionStorageInterface::class => get(Session::class),
169170

170171
Session::class => function (ContainerInterface $c): Session {
171-
return new Session;
172+
return new Session();
172173
},
173174

174175
FormHandlerFactory::class => function (ContainerInterface $c): FormHandlerFactory {
@@ -230,7 +231,7 @@
230231
Login::class => \DI\factory(function (ContainerInterface $c): Login {
231232
return new Login(
232233
$c->get(AdminAuthenticationService::class),
233-
$c->get(FormHandlerFactory::class)->create(new LoginInputFilter),
234+
$c->get(FormHandlerFactory::class)->create(new LoginInputFilter()),
234235
$c->get('config')['jwtSecret']
235236
);
236237
}),
@@ -365,7 +366,7 @@
365366
},
366367

367368
'form.event' => function (ContainerInterface $c): FormHandler {
368-
return $c->get(FormHandlerFactory::class)->create(new EventInputFilter);
369+
return $c->get(FormHandlerFactory::class)->create(new EventInputFilter());
369370
},
370371

371372
EventAll::class => function (ContainerInterface $c): EventAll {
@@ -474,7 +475,7 @@
474475

475476
Generator::class => function (ContainerInterface $c): Generator {
476477
return new Generator(
477-
new Parser(null, new class implements \Mni\FrontYAML\Markdown\MarkdownParser {
478+
new Parser(null, new class () implements \Mni\FrontYAML\Markdown\MarkdownParser {
478479
public function parse($markdown): string
479480
{
480481
return (new Parsedown())->parse($markdown);
@@ -523,7 +524,7 @@ public function parse($markdown): string
523524
);
524525
},
525526

526-
JwtAuthentication::class => function (ContainerInterface $c): JwtAuthentication {
527+
JwtAuthentication::class => function (ContainerInterface $c): JwtAuthentication {
527528
return new JwtAuthentication([
528529
'secret' => $c->get('config')['jwtSecret'],
529530
'path' => '/api/admin',
@@ -566,7 +567,7 @@ public function parse($markdown): string
566567
'src/User/Entity',
567568
],
568569
'auto_generate_proxies' => true,
569-
'proxy_dir' => __DIR__.'/../cache/proxies',
570+
'proxy_dir' => __DIR__ . '/../cache/proxies',
570571
],
571572
'connection' => [
572573
'driver' => 'pdo_mysql',

composer.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,21 @@
6161
}
6262
},
6363
"require-dev": {
64-
"squizlabs/php_codesniffer": "^3.6",
6564
"phpunit/phpunit": "^9.5",
6665
"weirdan/doctrine-psalm-plugin": "^1.0",
6766
"doctrine/data-fixtures": "^1.5",
68-
"phpstan/phpstan": "^1.9"
67+
"phpstan/phpstan": "^1.9",
68+
"friendsofphp/php-cs-fixer": "^3.51"
6969
},
7070
"scripts" : {
7171
"test": [
7272
"@phpunit",
7373
"@cs"
7474
],
7575
"phpunit": "phpunit",
76-
"cs" : "phpcs",
77-
"cs-fix": "phpcbf",
76+
"cs" : "php-cs-fixer fix --dry-run --allow-risky=yes",
77+
"cs:ci" : "php-cs-fixer fix --dry-run --allow-risky=yes --format=checkstyle | cs2pr",
78+
"cs-fix": "php-cs-fixer --allow-risky=yes fix",
7879
"static": "phpstan --ansi analyse --level max src",
7980
"app:cc": "php bin/app clear-cache",
8081
"app:gen:blog": "php bin/app generate-blog",

0 commit comments

Comments
 (0)