Skip to content

Commit 96440b9

Browse files
author
gguseynov
committed
Added php-cs-fixer coding standards check.
1 parent 16f16d6 commit 96440b9

15 files changed

Lines changed: 66 additions & 28 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Files that composer should ignore when downloading package
2+
/.* export-ignore
23
/Dockerfile export-ignore
34
/Makefile export-ignore
45
/README.md export-ignore

.php-cs-fixer.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
return (new PhpCsFixer\Config())
4+
->setRules([
5+
'@Symfony' => true,
6+
'@Symfony:risky' => true,
7+
])
8+
->setRiskyAllowed(true)
9+
->setFinder(
10+
PhpCsFixer\Finder::create()
11+
->in(__DIR__.'/src')
12+
->in(__DIR__.'/tests')
13+
)
14+
;

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ FROM php:8.1-fpm-alpine
22

33
RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
44

5+
RUN curl -s https://cs.symfony.com/download/php-cs-fixer-v3.phar -o /usr/local/bin/php-cs-fixer \
6+
&& chmod +x /usr/local/bin/php-cs-fixer
7+
58
WORKDIR /app

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
clear-cache:
22
rm -rf var
33

4+
php-cs-fixer: clear-cache
5+
docker-compose run --rm -T php /usr/local/bin/php-cs-fixer fix --no-interaction --verbose --dry-run
6+
47
phpunit: clear-cache
58
docker-compose run --rm -T php /usr/local/bin/php /app/vendor/bin/phpunit
69

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public function indexAction(Request $request)
4545

4646
Per default request content will be transformed only for requests with content type `json` or `jsonld`.
4747

48-
but you can stil configure it with
48+
But you can stil configure it with
4949

5050
``` yaml
51-
# serices.yaml
51+
# config/serices.yaml
5252

5353
json_request:
5454
content_types:

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
"symfony/phpunit-bridge": "^5.2 || ^6.2",
3030
"symfony/yaml": "^5.2 || ^6.0"
3131
},
32+
"scripts": {
33+
"csfixer": "php-cs-fixer fix --verbose --dry-run --diff",
34+
"csfixer-fix": "php-cs-fixer fix --verbose"
35+
},
3236
"config": {
3337
"preferred-install": "dist",
3438
"sort-packages": true

src/DependencyInjection/Configuration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace SymfonyBundles\JsonRequestBundle\DependencyInjection;
46

src/DependencyInjection/JsonRequestExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace SymfonyBundles\JsonRequestBundle\DependencyInjection;
46

57
use Symfony\Component\Config\Definition\Processor;
6-
use Symfony\Component\HttpKernel\KernelEvents;
78
use Symfony\Component\DependencyInjection\ContainerBuilder;
89
use Symfony\Component\DependencyInjection\Extension\Extension;
10+
use Symfony\Component\HttpKernel\KernelEvents;
911
use SymfonyBundles\JsonRequestBundle\EventListener\RequestTransformerListener;
1012

1113
final class JsonRequestExtension extends Extension

src/EventListener/RequestTransformerListener.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace SymfonyBundles\JsonRequestBundle\EventListener;
46

7+
use Symfony\Component\HttpFoundation\JsonResponse;
58
use Symfony\Component\HttpFoundation\Request;
69
use Symfony\Component\HttpFoundation\Response;
7-
use Symfony\Component\HttpFoundation\JsonResponse;
810
use Symfony\Component\HttpKernel\Event\RequestEvent;
911

1012
final class RequestTransformerListener
@@ -25,7 +27,7 @@ public function onKernelRequest(RequestEvent $event): void
2527
}
2628

2729
try {
28-
$data = \json_decode((string) $request->getContent(), true, 512, \JSON_THROW_ON_ERROR);
30+
$data = json_decode((string) $request->getContent(), true, 512, \JSON_THROW_ON_ERROR);
2931

3032
if (\is_array($data)) {
3133
$request->request->replace($data);
@@ -39,6 +41,6 @@ private function supports(Request $request): bool
3941
{
4042
$contentType = method_exists($request, 'getContentTypeFormat') ? $request->getContentTypeFormat() : $request->getContentType();
4143

42-
return in_array($contentType, $this->contentTypes, true) && $request->getContent();
44+
return \in_array($contentType, $this->contentTypes, true) && $request->getContent();
4345
}
4446
}

src/JsonRequestBundle.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace SymfonyBundles\JsonRequestBundle;
46

0 commit comments

Comments
 (0)