Skip to content

Commit

Permalink
Merge pull request #282 from php-school/cs-fixer
Browse files Browse the repository at this point in the history
Use php-cs-fixer
  • Loading branch information
AydinHassan authored Mar 10, 2024
2 parents 5b1d6f1 + 2a15681 commit ba42824
Show file tree
Hide file tree
Showing 122 changed files with 725 additions and 215 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
tools: composer:v2, cs2pr

- name: Install PHP Dependencies
run: composer install --prefer-dist
Expand All @@ -32,7 +32,7 @@ jobs:
run: composer phpunit

- name: Run phpcs
run: composer cs
run: composer cs:ci

- name: Run PHPStan
run: composer static
run: composer static
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
node_modules
.DS_Store
.php-cs-fixer.cache
npm-debug.log
/vendor/
/logs/*
Expand Down
15 changes: 15 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__ . '/src')
->in(__DIR__ . '/test')
->in(__DIR__ . '/app')
;

return (new PhpCsFixer\Config())
->setRules([
'@PER-CS2.0' => true,
'declare_strict_types' => true,
'no_unused_imports' => true,
])
->setFinder($finder);
25 changes: 13 additions & 12 deletions app/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use ahinkle\PackagistLatestVersion\PackagistLatestVersion;
use DI\Bridge\Slim\Bridge;
use Doctrine\DBAL\Types\Type;
Expand All @@ -10,7 +12,6 @@
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
use Github\Client;
use Jenssegers\Agent\Agent;
use League\CommonMark\Extension\CommonMarkCoreExtension;
use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension;
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
Expand Down Expand Up @@ -52,7 +53,6 @@
use PhpSchool\Website\Online\CloudWorkshopRepository;
use PhpSchool\Website\Online\Command\DownloadComposerPackageList;
use PhpSchool\Website\Online\Middleware\ExerciseRunnerRateLimiter;
use PhpSchool\Website\Online\Middleware\Styles;
use PhpSchool\Website\Online\PathGenerator;
use PhpSchool\Website\Online\ProblemFileConverter;
use PhpSchool\Website\Online\ProjectUploader;
Expand Down Expand Up @@ -101,6 +101,7 @@
use Symfony\Component\RateLimiter\Storage\CacheStorage;
use Symfony\Contracts\Cache\CacheInterface;
use Tuupola\Middleware\JwtAuthentication;

use function DI\factory;
use function DI\get;

Expand All @@ -121,7 +122,7 @@
$app = Bridge::create($c);
$app->addRoutingMiddleware();

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

Expand All @@ -139,7 +140,7 @@
}),
'cache' => factory(function (ContainerInterface $c): CacheInterface {
if (!$c->get('config')['enableCache']) {
return new NullAdapter;
return new NullAdapter();
}

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

return new RedisAdapter($redisConnection, 'default');
}),
LoggerInterface::class => factory(function (ContainerInterface $c): LoggerInterface{
LoggerInterface::class => factory(function (ContainerInterface $c): LoggerInterface {
$settings = $c->get('config')['logger'];
$logger = new Logger($settings['name']);
$logger->pushProcessor(new UidProcessor);
$logger->pushProcessor(new UidProcessor());
$logger->pushHandler(new StreamHandler($settings['path'], Logger::DEBUG));
return $logger;
}),

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

Session::class => function (ContainerInterface $c): Session {
return new Session;
return new Session();
},

FormHandlerFactory::class => function (ContainerInterface $c): FormHandlerFactory {
Expand Down Expand Up @@ -230,7 +231,7 @@
Login::class => \DI\factory(function (ContainerInterface $c): Login {
return new Login(
$c->get(AdminAuthenticationService::class),
$c->get(FormHandlerFactory::class)->create(new LoginInputFilter),
$c->get(FormHandlerFactory::class)->create(new LoginInputFilter()),
$c->get('config')['jwtSecret']
);
}),
Expand Down Expand Up @@ -365,7 +366,7 @@
},

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

EventAll::class => function (ContainerInterface $c): EventAll {
Expand Down Expand Up @@ -474,7 +475,7 @@

Generator::class => function (ContainerInterface $c): Generator {
return new Generator(
new Parser(null, new class implements \Mni\FrontYAML\Markdown\MarkdownParser {
new Parser(null, new class () implements \Mni\FrontYAML\Markdown\MarkdownParser {
public function parse($markdown): string
{
return (new Parsedown())->parse($markdown);
Expand Down Expand Up @@ -523,7 +524,7 @@ public function parse($markdown): string
);
},

JwtAuthentication::class => function (ContainerInterface $c): JwtAuthentication {
JwtAuthentication::class => function (ContainerInterface $c): JwtAuthentication {
return new JwtAuthentication([
'secret' => $c->get('config')['jwtSecret'],
'path' => '/api/admin',
Expand Down Expand Up @@ -566,7 +567,7 @@ public function parse($markdown): string
'src/User/Entity',
],
'auto_generate_proxies' => true,
'proxy_dir' => __DIR__.'/../cache/proxies',
'proxy_dir' => __DIR__ . '/../cache/proxies',
],
'connection' => [
'driver' => 'pdo_mysql',
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,21 @@
}
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.6",
"phpunit/phpunit": "^9.5",
"weirdan/doctrine-psalm-plugin": "^1.0",
"doctrine/data-fixtures": "^1.5",
"phpstan/phpstan": "^1.9"
"phpstan/phpstan": "^1.9",
"friendsofphp/php-cs-fixer": "^3.51"
},
"scripts" : {
"test": [
"@phpunit",
"@cs"
],
"phpunit": "phpunit",
"cs" : "phpcs",
"cs-fix": "phpcbf",
"cs" : "php-cs-fixer fix --dry-run --allow-risky=yes",
"cs:ci" : "php-cs-fixer fix --dry-run --allow-risky=yes --format=checkstyle | cs2pr",
"cs-fix": "php-cs-fixer --allow-risky=yes fix",
"static": "phpstan --ansi analyse --level max src",
"app:cc": "php bin/app clear-cache",
"app:gen:blog": "php bin/app generate-blog",
Expand Down
Loading

0 comments on commit ba42824

Please sign in to comment.