Skip to content

Commit fe92cc7

Browse files
committed
CS fixes
1 parent dd75be0 commit fe92cc7

File tree

6 files changed

+40
-43
lines changed

6 files changed

+40
-43
lines changed

src/LiveComponent/src/EventListener/LiveComponentSubscriber.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
class LiveComponentSubscriber implements EventSubscriberInterface, ServiceSubscriberInterface
4545
{
4646
private const HTML_CONTENT_TYPE = 'application/vnd.live-component+html';
47-
47+
4848
private const REDIRECT_HEADER = 'X-Live-Redirect';
4949
private const DOWNLOAD_HEADER = 'X-Live-Download';
5050

@@ -257,10 +257,10 @@ public function onKernelView(ViewEvent $event): void
257257

258258
return;
259259
}
260-
260+
261261
if ($event->getControllerResult() instanceof BinaryFileResponse) {
262262
if (!$event->getControllerResult()->headers->has(self::DOWNLOAD_HEADER)) {
263-
263+
264264
}
265265
$event->setResponse(new Response());
266266
}

src/LiveComponent/src/LiveDownloadResponse.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@
1313
final class LiveDownloadResponse extends BinaryFileResponse
1414
{
1515
public const HEADER_LIVE_DOWNLOAD = 'X-Live-Download';
16-
16+
1717
public function __construct(string|SplFileInfo $file, ?string $filename = null)
1818
{
1919
if (\is_string($file)) {
2020
$file = new SplFileInfo($file);
2121
}
22-
22+
2323
if ((!$file instanceof SplFileInfo)) {
2424
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $file));
2525
}
26-
26+
2727
if ($file instanceof SplTempFileObject) {
2828
$file->rewind();
2929
}
30-
30+
3131
parent::__construct($file, 200, [
3232
self::HEADER_LIVE_DOWNLOAD => 1,
3333
'Content-Disposition' => HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $filename ?? basename($file)),

ux.symfony.com/src/Model/LiveDemo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getLongDescription(): string
4444
{
4545
return $this->longDescription;
4646
}
47-
47+
4848
public function isNew(): bool
4949
{
5050
return \DateTimeImmutable::createFromFormat('Y-m-d', $this->getPublishedAt()) > new \DateTimeImmutable('-30 days');

ux.symfony.com/src/Service/DocumentStorage.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,49 @@
1919
final class DocumentStorage
2020
{
2121
private readonly Filesystem $filesystem;
22-
22+
2323
public function __construct(
2424
#[Autowire('%kernel.project_dir%/assets/documents')]
2525
private readonly string $storageDirectory,
2626
) {
2727
$this->filesystem = new Filesystem();
28-
28+
2929
if (!$this->filesystem->exists($this->storageDirectory)) {
3030
$this->filesystem->mkdir($this->storageDirectory);
3131
}
3232
}
33-
33+
3434
public function readFile(string $path): string
3535
{
3636
if (!$this->hasFile($path)) {
37-
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $path));
37+
throw new \InvalidArgumentException(\sprintf('The file "%s" does not exist.', $path));
3838
}
39-
39+
4040
return $this->filesystem->readFile($this->getAbsolutePath($path));
4141
}
42-
42+
4343
public function hasFile(string $path): bool
4444
{
4545
return $this->filesystem->exists($this->getAbsolutePath($path));
4646
}
47-
47+
4848
public function getFile(string $path): Document
4949
{
5050
if (!$this->hasFile($path)) {
51-
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $path));
51+
throw new \InvalidArgumentException(\sprintf('The file "%s" does not exist.', $path));
5252
}
53-
53+
5454
return new Document($this->getAbsolutePath($path));
5555
}
56-
56+
5757
private function getAbsolutePath(string $path): string
5858
{
5959
try {
6060
$absolutePath = Path::makeAbsolute($path, $this->storageDirectory);
6161
} catch (\Throwable $e) {
62-
throw new \InvalidArgumentException(sprintf('The file "%s" is not valid.', $path), 0, $e);
62+
throw new \InvalidArgumentException(\sprintf('The file "%s" is not valid.', $path), 0, $e);
6363
}
64-
64+
6565
return $absolutePath;
6666
}
67-
6867
}

ux.symfony.com/src/Service/LiveDemoRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class LiveDemoRepository
2121
public function findAll(): array
2222
{
2323
return [
24-
new LiveDemo(
24+
new LiveDemo(
2525
'download',
2626
name: 'Downloading files',
2727
description: 'Return file as downloadable attachment from your Live Component.',

ux.symfony.com/src/Twig/Components/DownloadFiles.php

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace App\Twig\Components;
1313

1414
use App\Service\DocumentStorage;
15-
use DateTimeImmutable;
16-
use SplTempFileObject;
1715
use Symfony\Component\HttpFoundation\BinaryFileResponse;
1816
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
1917
use Symfony\UX\LiveComponent\Attribute\LiveAction;
@@ -27,77 +25,77 @@
2725
final class DownloadFiles
2826
{
2927
use DefaultActionTrait;
30-
28+
3129
#[LiveProp(writable: true)]
3230
public int $year = 2025;
33-
31+
3432
public function __construct(
3533
private readonly DocumentStorage $documentStorage,
3634
) {
3735
}
38-
36+
3937
#[LiveAction]
4038
public function download(): BinaryFileResponse
4139
{
4240
$file = $this->documentStorage->getFile('demos/empty.html');
43-
41+
4442
return new LiveDownloadResponse($file);
4543
}
46-
44+
4745
#[LiveAction]
4846
public function generate(#[LiveArg] string $format): BinaryFileResponse
4947
{
50-
$report = match($format) {
48+
$report = match ($format) {
5149
'csv' => $this->generateCsvReport($this->year),
5250
'json' => $this->generateJsonReport($this->year),
5351
'md' => $this->generateMarkdownReport($this->year),
5452
default => throw new \InvalidArgumentException('Invalid format provided'),
5553
};
56-
57-
$file = new SplTempFileObject();
54+
55+
$file = new \SplTempFileObject();
5856
$file->fwrite($report);
59-
57+
6058
return new LiveDownloadResponse($file, 'report.'.$format);
6159
}
62-
60+
6361
private function generateCsvReport(int $year): string
6462
{
65-
$file = new SplTempFileObject();
63+
$file = new \SplTempFileObject();
6664
// $file->fputcsv(['Month', 'Number', 'Name', 'Number of days']);
6765
foreach ($this->getReportData($year) as $row) {
6866
$file->fputcsv($row);
6967
}
70-
68+
7169
return $file->fread($file->ftell());
7270
}
73-
71+
7472
private function generateMarkdownReport(int $year): string
7573
{
7674
$rows = iterator_to_array($this->getReportData($year));
77-
75+
7876
foreach ($rows as $key => $row) {
7977
$rows[$key] = '|'.implode('|', $row).'|';
8078
}
81-
79+
8280
return implode("\n", $rows);
8381
}
8482

8583
private function generateJsonReport(int $year): string
8684
{
8785
$rows = iterator_to_array($this->getReportData($year));
88-
89-
return \json_encode($rows, JSON_FORCE_OBJECT | JSON_THROW_ON_ERROR);
86+
87+
return json_encode($rows, \JSON_FORCE_OBJECT | \JSON_THROW_ON_ERROR);
9088
}
9189

9290
/**
9391
* @param int<2000,2025> $year The year to generate the report for (2000-2025)
94-
*
92+
*
9593
* @return iterable<string, array{string, string}>
9694
*/
9795
private function getReportData(int $year): iterable
9896
{
9997
foreach (range(1, 12) as $month) {
100-
$startDate = DateTimeImmutable::createFromFormat('Y', $year)->setDate($year, $month, 1);
98+
$startDate = \DateTimeImmutable::createFromFormat('Y', $year)->setDate($year, $month, 1);
10199
$endDate = $startDate->modify('last day of this month');
102100
yield $month => [
103101
'name' => $startDate->format('F'),

0 commit comments

Comments
 (0)