Skip to content

Commit 76d97d6

Browse files
author
Arnaud RITTI
committed
PHP CS
1 parent 621b306 commit 76d97d6

33 files changed

Lines changed: 329 additions & 301 deletions

deploy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
]);
1919

2020
set('shared_files', [
21-
'.env.local'
21+
'.env.local',
2222
]);
2323

2424
set('writable_dirs', [

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"release": "release-it"
2929
},
3030
"lint-staged": {
31+
"*.php": [
32+
"vendor/bin/php-cs-fixer fix --diff --config .php-cs-fixer.dist.php --no-ansi",
33+
"vendor/bin/phpcs --no-colors",
34+
"vendor/bin/phpstan analyse --no-ansi --no-progress"
35+
],
3136
"*.{js,jsx,ts,tsx,vue}": [
3237
"prettier --write",
3338
"npm run lint:js --"

phpinsights.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
declare(strict_types=1);
44

55
return [
6-
76
/*
87
|--------------------------------------------------------------------------
98
| Default Preset
@@ -101,5 +100,4 @@
101100
*/
102101

103102
'threads' => null,
104-
105103
];

src/Command/BucketsRemoveExpiredCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3434
$this->binManager->setBinByUuid($binId);
3535
if ($this->binManager->isExpired()) {
3636
$this->binManager->deleteBin();
37-
$deleted++;
37+
++$deleted;
3838
}
3939
}
4040

src/Controller/API/CookieController.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
public function getCookies(Request $request): Response
3636
{
3737
return $this->json([
38-
'cookies' => array_filter($request->cookies->all(), static fn ($key) => $key !== 'sf_redirect', ARRAY_FILTER_USE_KEY),
38+
'cookies' => array_filter($request->cookies->all(), static fn ($key) => 'sf_redirect' !== $key, ARRAY_FILTER_USE_KEY),
3939
], Response::HTTP_OK);
4040
}
4141

@@ -59,6 +59,7 @@ public function newCookie(Request $request): Response
5959

6060
$response = $this->json($requestPayload, Response::HTTP_CREATED);
6161
$response->headers->setCookie($requestPayload->toCookie());
62+
6263
return $response;
6364
} catch (MissingConstructorArgumentsException) {
6465
return $this->json(
@@ -71,23 +72,25 @@ public function newCookie(Request $request): Response
7172
#[Route('/cookies/{key}', name: 'api.cookies.update', methods: ['PATCH'])]
7273
public function updateCookie(Request $request, string $key): Response
7374
{
74-
if (! $request->cookies->has($key)) {
75+
if (!$request->cookies->has($key)) {
7576
return $this->json(sprintf('No cookie found for key "%s"', $key), Response::HTTP_NOT_FOUND);
7677
}
7778
$requestPayload = new CookieRequestPayload($key, $request->getContent());
7879
$response = $this->json($requestPayload, Response::HTTP_OK);
7980
$response->headers->setCookie($requestPayload->toCookie());
81+
8082
return $response;
8183
}
8284

8385
#[Route('/cookies/{key}', name: 'api.cookies.delete', methods: ['DELETE'])]
8486
public function deleteCookie(Request $request, string $key): Response
8587
{
86-
if (! $request->cookies->has($key)) {
88+
if (!$request->cookies->has($key)) {
8789
return $this->json(sprintf('No cookie found for key "%s"', $key), Response::HTTP_NOT_FOUND);
8890
}
8991
$response = $this->json(sprintf('The cookie with key %s is deleted', $key), Response::HTTP_OK);
9092
$response->headers->clearCookie($key);
93+
9194
return $response;
9295
}
9396

@@ -227,14 +230,15 @@ public static function setupOpenApiDocumentation(OpenApi $openApi): void
227230
$openApi->getPaths()->addPath('/cookies/{key}', $singleItem);
228231
}
229232

230-
#[Pure] private function createErrorFromSerialization(): FormErrorRfc7807DTO
231-
{
232-
$mainDto = new FormErrorRfc7807DTO();
233-
$mainDto->title = 'Bad Request';
234-
$mainDto->type = 'Missing JSON node';
233+
#[Pure]
234+
private function createErrorFromSerialization(): FormErrorRfc7807DTO
235+
{
236+
$mainDto = new FormErrorRfc7807DTO();
237+
$mainDto->title = 'Bad Request';
238+
$mainDto->type = 'Missing JSON node';
235239

236-
return $mainDto;
237-
}
240+
return $mainDto;
241+
}
238242

239243
private function createErrorFromValidation(ConstraintViolationListInterface $violations): FormErrorRfc7807DTO
240244
{

src/Controller/API/ImageController.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ public function getPlaceholder(Request $request, string $dimensions, string $for
2828
[$width, $height] = self::parseDimensions($dimensions);
2929

3030
$bgColor = $request->query->get('bgColor', '#2b2d42');
31-
$bgColor = $bgColor === 'random' ? null : $bgColor;
31+
$bgColor = 'random' === $bgColor ? null : $bgColor;
3232

3333
$textColor = $request->query->get('textColor', '#edf2f4');
34-
$textColor = $textColor === 'random' ? null : $textColor;
34+
$textColor = 'random' === $textColor ? null : $textColor;
3535

3636
$projectRoot = $this->getParameter('kernel.project_dir');
3737

3838
ob_start();
3939
(new ImageGenerator(
40-
$width . 'x' . $height,
40+
$width.'x'.$height,
4141
$textColor,
4242
$bgColor,
43-
$projectRoot . '/var/fonts/Noto.ttf',
43+
$projectRoot.'/var/fonts/Noto.ttf',
4444
min($width, $height) * 0.125,
4545
2
4646
))
@@ -62,7 +62,7 @@ public function getPlaceholder(Request $request, string $dimensions, string $for
6262
public function getSpace(Request $request, string $dimensions, string $category = 'random', string $format = 'png'): Response
6363
{
6464
[$width, $height] = self::parseDimensions($dimensions);
65-
$url = sprintf('https://api.lorem.space/image%s?w=%s&h=%s', $category && $category !== 'random' ? '/'.$category : '', $width ? $width : '', $height ? $height : '');
65+
$url = sprintf('https://api.lorem.space/image%s?w=%s&h=%s', $category && 'random' !== $category ? '/'.$category : '', $width ? $width : '', $height ? $height : '');
6666
$client = HttpClient::create();
6767
$response = $client->request('GET', $url);
6868

@@ -161,7 +161,7 @@ private function renderImage(string $content, string $format = 'png'): Response
161161
$content = ob_get_clean();
162162

163163
$response = new Response();
164-
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, uniqid('', true). ".${format}");
164+
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, uniqid('', true).".${format}");
165165
$response->headers->set('Content-Disposition', $disposition);
166166
$response->headers->set('Content-Type', $mimeType);
167167
$response->setContent($content);
@@ -172,10 +172,11 @@ private function renderImage(string $content, string $format = 'png'): Response
172172
private static function parseDimensions(string $dimensions): array
173173
{
174174
$dimensions = explode('x', $dimensions);
175-
if (count($dimensions) === 1) {
175+
if (1 === count($dimensions)) {
176176
$dimensions[1] = $dimensions[0];
177177
}
178178
$dimensions = implode('x', $dimensions);
179+
179180
return explode('x', $dimensions);
180181
}
181182
}

src/Controller/API/RequestController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getAnything(Request $request): Response
5151
'headers' => array_map(static fn ($entry) => implode('', $entry), $request->headers->all()),
5252
'content-type' => $request->getContentType(),
5353
'raw_body' => $request->getContent(),
54-
'body' => $request->getContentType() === 'json' ? json_decode($request->getContent(), false, 512, JSON_THROW_ON_ERROR) : $request->getContent(),
54+
'body' => 'json' === $request->getContentType() ? json_decode($request->getContent(), false, 512, JSON_THROW_ON_ERROR) : $request->getContent(),
5555
]);
5656
}
5757

src/Controller/API/StatusController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class StatusController extends AbstractController
1818
#[Route('/status/{code}', name: 'api.status.code', methods: ['DELETE', 'GET', 'POST', 'PUT', 'PATCH'])]
1919
public function getStatusCode(string $code): Response
2020
{
21-
if (! array_key_exists($code, Response::$statusTexts)) {
21+
if (!array_key_exists($code, Response::$statusTexts)) {
2222
return new Response('Invalid status code', Response::HTTP_BAD_REQUEST);
2323
}
2424

src/Controller/Http/BinController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(private BinManager $binManager)
3737
public function bin(Request $request): Response
3838
{
3939
$this->binManager->setCurrentBin($request->attributes->get('_bin'));
40-
if ($request->getContentType() === 'json' && $request->getContent()) {
40+
if ('json' === $request->getContentType() && $request->getContent()) {
4141
$data = json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR);
4242
$request->request->replace(is_array($data) ? $data : []);
4343
}
@@ -50,6 +50,7 @@ public function bin(Request $request): Response
5050
'bin' => (string) $this->binManager->getCurrentBin(),
5151
]), $requestBinId),
5252
]);
53+
5354
return $response;
5455
}
5556

@@ -60,6 +61,7 @@ public static function getBaseHost(Request $request)
6061
if (Uuid::isValid($pathInfo)) {
6162
$baseHost = str_replace("${pathInfo}.", '', $baseHost);
6263
}
64+
6365
return $baseHost;
6466
}
6567
}

src/Controller/Http/DocumentationController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function tag(string $tag): Response
3535
{
3636
$paths = [];
3737
/**
38-
* @var string $path
38+
* @var string $path
3939
* @var PathItem $pathItem
4040
*/
4141
foreach ($this->openApi->getPaths()->getPaths() as $path => $pathItem) {
@@ -59,7 +59,7 @@ public function tag(string $tag): Response
5959

6060
foreach ($operations as $operation) {
6161
foreach ($operation->getTags() as $tagName) {
62-
if (! isset($paths[$tagName])) {
62+
if (!isset($paths[$tagName])) {
6363
$paths[$tagName] = [];
6464
}
6565
$paths[$tagName][$path] = $pathItem;

0 commit comments

Comments
 (0)