Skip to content

Commit 2ea5cb3

Browse files
committed
CS fixer run
1 parent e716dba commit 2ea5cb3

File tree

9 files changed

+72
-77
lines changed

9 files changed

+72
-77
lines changed

src/Filesystem/Attribute/PendingUploadedFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @readonly
2424
*/
25-
#[\Attribute(\Attribute::TARGET_PARAMETER|\Attribute::TARGET_PROPERTY)]
25+
#[\Attribute(\Attribute::TARGET_PARAMETER | \Attribute::TARGET_PROPERTY)]
2626
class PendingUploadedFile
2727
{
2828
public function __construct(

src/Filesystem/Attribute/UploadedFile.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Zenstruck\Filesystem\Attribute;
1313

14-
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
1514
use Zenstruck\Filesystem\Node\Path\Expression;
1615
use Zenstruck\Filesystem\Node\Path\Namer;
1716

@@ -20,7 +19,7 @@
2019
*
2120
* @readonly
2221
*/
23-
#[\Attribute(\Attribute::TARGET_PARAMETER|\Attribute::TARGET_PROPERTY)]
22+
#[\Attribute(\Attribute::TARGET_PARAMETER | \Attribute::TARGET_PROPERTY)]
2423
final class UploadedFile extends PendingUploadedFile
2524
{
2625
public string|Namer $namer;

src/Filesystem/Symfony/Exception/IncorrectFileHttpException.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@
1818
*/
1919
class IncorrectFileHttpException extends HttpException
2020
{
21-
2221
}

src/Filesystem/Symfony/HttpKernel/PendingFileValueResolverTrait.php

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
16-
use Symfony\Component\HttpKernel\Exception\HttpException;
1716
use Symfony\Component\Validator\ConstraintViolationList;
1817
use Symfony\Component\Validator\Validator\ValidatorInterface;
1918
use Symfony\Contracts\Service\ServiceProviderInterface;
@@ -23,9 +22,7 @@
2322
use Zenstruck\Filesystem\FilesystemRegistry;
2423
use Zenstruck\Filesystem\Node;
2524
use Zenstruck\Filesystem\Node\File;
26-
use Zenstruck\Filesystem\Node\File\LazyFile;
2725
use Zenstruck\Filesystem\Node\File\PendingFile;
28-
use Zenstruck\Filesystem\Node\Mapping;
2926
use Zenstruck\Filesystem\Node\PathGenerator;
3027
use Zenstruck\Filesystem\Symfony\Exception\IncorrectFileHttpException;
3128

@@ -36,87 +33,90 @@
3633
*/
3734
trait PendingFileValueResolverTrait
3835
{
39-
/** @phpstan-ignore-line */public function __construct(private ServiceProviderInterface $locator) {
36+
/** @phpstan-ignore-line */
37+
public function __construct(private ServiceProviderInterface $locator)
38+
{
4039
}
4140

42-
/**
41+
/**
4342
* @return iterable<File|array|null>
4443
*/
45-
public function resolve(Request $request, ArgumentMetadata $argument): iterable
46-
{
47-
$attribute = PendingUploadedFile::forArgument($argument);
48-
49-
$files = $this->extractor()->extractFilesFromRequest(
50-
$request,
51-
(string) $attribute->path,
52-
'array' === $argument->getType(),
53-
(bool) $attribute->image,
54-
);
44+
public function resolve(Request $request, ArgumentMetadata $argument): iterable
45+
{
46+
$attribute = PendingUploadedFile::forArgument($argument);
47+
48+
$files = $this->extractor()->extractFilesFromRequest(
49+
$request,
50+
(string) $attribute->path,
51+
'array' === $argument->getType(),
52+
(bool) $attribute->image,
53+
);
5554

56-
if (!$files) {
57-
return [$files];
58-
}
55+
if (!$files) {
56+
return [$files];
57+
}
5958

60-
if ($attribute->constraints) {
61-
$errors = $this->validator()->validate(
62-
$files,
63-
$attribute->constraints
64-
);
59+
if ($attribute->constraints) {
60+
$errors = $this->validator()->validate(
61+
$files,
62+
$attribute->constraints
63+
);
6564

66-
if (\count($errors)) {
67-
\assert($errors instanceof ConstraintViolationList);
65+
if (\count($errors)) {
66+
\assert($errors instanceof ConstraintViolationList);
6867

69-
throw new IncorrectFileHttpException($attribute->errorStatus, (string) $errors);
68+
throw new IncorrectFileHttpException($attribute->errorStatus, (string) $errors);
69+
}
7070
}
71-
}
7271

73-
if ($attribute instanceof UploadedFile) {
74-
if (is_array($files)) {
75-
$files = array_map(
76-
fn (PendingFile $file) => $this->saveFile($attribute, $file),
77-
$files
78-
);
79-
} else {
80-
$files = $this->saveFile($attribute, $files);
72+
if ($attribute instanceof UploadedFile) {
73+
if (\is_array($files)) {
74+
$files = \array_map(
75+
fn(PendingFile $file) => $this->saveFile($attribute, $file),
76+
$files
77+
);
78+
} else {
79+
$files = $this->saveFile($attribute, $files);
80+
}
8181
}
82+
83+
return [$files];
8284
}
8385

84-
return [$files];
85-
}
86+
private function saveFile(UploadedFile $uploadedFile, PendingFile $file): File
87+
{
88+
$path = $this->generatePath($uploadedFile, $file);
89+
$file = $this->filesystem($uploadedFile->filesystem)
90+
->write($path, $file)
91+
;
8692

87-
private function saveFile(UploadedFile $uploadedFile, PendingFile $file): File
88-
{
89-
$path = $this->generatePath($uploadedFile, $file);
90-
$file = $this->filesystem($uploadedFile->filesystem)
91-
->write($path, $file);
93+
if ($uploadedFile->image) {
94+
return $file->ensureImage();
95+
}
9296

93-
if ($uploadedFile->image) {
94-
return $file->ensureImage();
97+
return $file;
9598
}
9699

97-
return $file;
98-
}
99-
100-
private function extractor(): RequestFilesExtractor
101-
{
102-
return $this->locator->get(RequestFilesExtractor::class);
103-
}
100+
private function extractor(): RequestFilesExtractor
101+
{
102+
return $this->locator->get(RequestFilesExtractor::class);
103+
}
104104

105-
private function filesystem(string $filesystem): Filesystem
106-
{
107-
return $this->locator->get(FilesystemRegistry::class)->get($filesystem);
108-
}
105+
private function filesystem(string $filesystem): Filesystem
106+
{
107+
return $this->locator->get(FilesystemRegistry::class)->get($filesystem);
108+
}
109109

110-
private function generatePath(UploadedFile $uploadedFile, Node $node): string
111-
{
112-
return $this->locator->get(PathGenerator::class)->generate(
113-
$uploadedFile->namer,
114-
$node
115-
);
116-
}
110+
private function generatePath(UploadedFile $uploadedFile, Node $node): string
111+
{
112+
return $this->locator->get(PathGenerator::class)->generate(
113+
$uploadedFile->namer,
114+
$node
115+
);
116+
}
117117

118-
private function validator(): ValidatorInterface
119-
{
120-
return $this->locator->get(ValidatorInterface::class);
121-
}
118+
private function validator(): ValidatorInterface
119+
{
120+
return $this->locator->get(ValidatorInterface::class);
121+
}
122122
}

src/Filesystem/Symfony/HttpKernel/RequestFilesExtractor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
1818
use Symfony\Component\PropertyAccess\PropertyAccessor;
1919
use Zenstruck\Filesystem\Attribute\PendingUploadedFile;
20-
use Zenstruck\Filesystem\Attribute\PendingUploadedFile as UploadedFileAttribute;
2120
use Zenstruck\Filesystem\Exception\NodeTypeMismatch;
2221
use Zenstruck\Filesystem\Node\File;
2322
use Zenstruck\Filesystem\Node\File\Image\PendingImage;

tests/Filesystem/Symfony/HttpKernel/PendingDocumentValueResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function returns_exception_for_invalid_file(): void
170170
$response = $client->getResponse();
171171
self::assertSame(422, $response->getStatusCode());
172172

173-
if (PHP_VERSION_ID >= 80100) {
173+
if (\PHP_VERSION_ID >= 80100) {
174174
$client->request(
175175
'GET',
176176
'validated-file',

tests/Fixtures/Controller/ArgumentResolverController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Zenstruck\Filesystem\Attribute\UploadedFile;
1818
use Zenstruck\Filesystem\Node\File;
1919
use Zenstruck\Filesystem\Node\File\Image;
20-
use Zenstruck\Filesystem\Symfony\Validator\PendingFileConstraint;
2120

2221
/**
2322
* @author Jakub Caban <[email protected]>
@@ -64,9 +63,9 @@ public function singleFile(?File $file): Response
6463
public function singleStoredFile(
6564
#[UploadedFile('public')]
6665
File $file
67-
): Response{
66+
): Response {
6867
return new Response(
69-
sprintf(
68+
\sprintf(
7069
'%s:%s',
7170
$file->dsn(),
7271
$file->contents()

tests/Fixtures/Controller/ValidatedArgumentResolverController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
1312
namespace Zenstruck\Tests\Fixtures\Controller;
1413

1514
use Symfony\Component\HttpFoundation\Response;

tests/Fixtures/TestKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ protected function configureRoutes(RoutingConfigurator $routes): void
188188
;
189189
$routes->import(__DIR__.'/Controller/ArgumentResolverController.php', 'annotation');
190190

191-
if (PHP_VERSION_ID >= 80100) {
191+
if (\PHP_VERSION_ID >= 80100) {
192192
$routes->import(__DIR__.'/Controller/ValidatedArgumentResolverController.php', 'annotation');
193193
}
194194
}

0 commit comments

Comments
 (0)