Skip to content

Commit

Permalink
Update method return types and yield statements (#218)
Browse files Browse the repository at this point in the history
The methods' return types have been updated from iterable<Data> to iterable<string, Data> in several files, namely FaviconsCompiler.php, ManifestCompiler.php, FileCompilerInterface.php, and ServiceWorkerCompiler.php. Moreover, yield statements have been modified to yield a pair of string (URL) and Data instead of just Data to enhance data identification and access.
  • Loading branch information
Spomky committed Jun 8, 2024
1 parent c1419d2 commit 65c2a87
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
19 changes: 10 additions & 9 deletions src/Service/FaviconsCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
}

/**
* @return iterable<Data>
* @return iterable<string, Data>
*/
public function getFiles(): iterable
{
Expand Down Expand Up @@ -234,14 +234,15 @@ public function getFiles(): iterable
);
$completeHash = hash('xxh128', $hash . $configuration);
$filename = sprintf($size['url'], $size['width'], $size['height'], $completeHash);
yield $this->processIcon($asset, $filename, $configuration, $size['mimetype'], $size['rel']);
yield $filename => $this->processIcon($asset, $filename, $configuration, $size['mimetype'], $size['rel']);
}
if ($this->favicons->tileColor !== null) {
$this->logger->debug('Creating browserconfig.xml.');
yield from $this->processBrowserConfig($asset, $hash);
}
if ($this->favicons->safariPinnedTabColor !== null && $this->favicons->useSilhouette === true) {
yield $this->generateSafariPinnedTab($asset, $hash);
$safariPinnedTab = $this->generateSafariPinnedTab($asset, $hash);
yield $safariPinnedTab->url => $safariPinnedTab;
}
$this->logger->debug('Favicons created.');
}
Expand Down Expand Up @@ -400,17 +401,17 @@ private function processBrowserConfig(string $asset, string $hash): array
);

return [
$icon70x70,
$icon150x150,
$icon310x310,
$icon310x150,
Data::create(
$icon70x70->url => $icon70x70,
$icon150x150->url => $icon150x150,
$icon310x310->url => $icon310x310,
$icon310x150->url => $icon310x150,
$icon144x144->url => Data::create(
$icon144x144->url,
$icon144x144->getRawData(),
$icon144x144->headers,
sprintf('<meta name="msapplication-TileImage" content="%s">', $icon144x144->url)
),
$browserConfig,
$browserConfig->url => $browserConfig,
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Service/FileCompilerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
interface FileCompilerInterface
{
/**
* @return iterable<Data>
* @return iterable<string, Data>
*/
public function getFiles(): iterable;
}
8 changes: 5 additions & 3 deletions src/Service/ManifestCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(
}

/**
* @return iterable<Data>
* @return iterable<string, Data>
*/
public function getFiles(): iterable
{
Expand All @@ -81,13 +81,15 @@ public function getFiles(): iterable
}
if ($this->locales === []) {
$this->logger->debug('No locale defined. Compiling default manifest.');
yield $this->compileManifest(null);
$manifest = $this->compileManifest(null);
yield $manifest->url => $manifest;
}
foreach ($this->locales as $locale) {
$this->logger->debug('Compiling manifest for locale.', [
'locale' => $locale,
]);
yield $this->compileManifest($locale);
$manifest = $this->compileManifest($locale);
yield $manifest->url => $manifest;
}
$this->logger->debug('Manifest files compiled.');
}
Expand Down
9 changes: 5 additions & 4 deletions src/Service/ServiceWorkerCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ public function __construct(
}

/**
* @return iterable<Data>
* @return iterable<string, Data>
*/
public function getFiles(): iterable
{
yield $this->compileSW();
$sw = $this->compileSW();
yield $sw->url => $sw;
yield from $this->getWorkboxFiles();
}

Expand Down Expand Up @@ -118,7 +119,7 @@ private function includeRootSW(): string
}

/**
* @return iterable<Data>
* @return iterable<string, Data>
*/
private function getWorkboxFiles(): iterable
{
Expand Down Expand Up @@ -150,7 +151,7 @@ private function getWorkboxFiles(): iterable
if ($data === null) {
continue;
}
yield $data;
yield $data->url => $data;
}
}

Expand Down

0 comments on commit 65c2a87

Please sign in to comment.