8000 Tweaks thanks to Nicolas' review · symfony/symfony@2cea0f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2cea0f8

Browse files
committed
Tweaks thanks to Nicolas' review
1 parent 136a5ec commit 2cea0f8

File tree

8 files changed

+17
-24
lines changed

8 files changed

+17
-24
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ CHANGELOG
2626
* Deprecate `framework.validation.enable_annotations`, use `framework.validation.enable_attributes` instead
2727
* Deprecate `framework.serializer.enable_annotations`, use `framework.serializer.enable_attributes` instead
2828
* Add `array $tokenAttributes = []` optional parameter to `KernelBrowser::loginUser()`
29-
* Add support for relative URLs in BrowserKit's redirect assertion.
29+
* Add support for relative URLs in BrowserKit's redirect assertion
3030
* Change BrowserKitAssertionsTrait::getClient() to be protected
31-
* Deprecate the `framework.asset_mapper.provider` config option.
31+
* Deprecate the `framework.asset_mapper.provider` config option
3232

3333
6.3
3434
---

src/Symfony/Component/AssetMapper/AssetMapperRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public function all(): array
103103
foreach ($this->getDirectories() as $path => $namespace) {
104104
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
105105
foreach ($iterator as $file) {
106+
/** @var \SplFileInfo $file */
106107
if (!$file->isFile()) {
107108
continue;
108109
}
@@ -112,7 +113,7 @@ public function all(): array
112113
}
113114 10000

114115
// avoid potentially exposing PHP files
115-
if (str_ends_with($file->getPathname(), '.php')) {
116+
if ('php' === $file->getExtension()) {
116117
continue;
117118
}
118119

src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5757
$progressBar->finish();
5858
$progressBar->clear();
5959

60-
if (0 === \count($downloadedPackages)) {
60+
if (!$downloadedPackages) {
6161
$io->success('No assets to install.');
6262

6363
return Command::SUCCESS;
@@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6666
$io->success(sprintf(
6767
'Downloaded %d asset%s into %s.',
6868
\count($downloadedPackages),
69-
1 == \count($downloadedPackages) ? '' : 's',
69+
1 === \count($downloadedPackages) ? '' : 's',
7070
str_replace($this->projectDir.'/', '', $this->packageDownloader->getVendorDir()),
7171
));
7272

src/Symfony/Component/AssetMapper/ImportMap/ImportMapConfigReader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ public function getRootDirectory(): string
133133
private function extractVersionFromLegacyUrl(string $url): ?string
134134
{
135135
// URL pattern https://ga.jspm.io/npm:bootstrap@5.3.2/dist/js/bootstrap.esm.js
136-
$lastAt = strrpos($url, '@');
137-
if (false === $lastAt) {
136+
if (false === $lastAt = strrpos($url, '@')) {
138137
return null;
139138
}
140139

src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private function updateImportMapConfig(bool $update, array $packagesToRequire, a
219219
if ($update) {
220220
foreach ($currentEntries as $entry) {
221221
$importName = $entry->importName;
222-
if (!$entry->isRemotePackage() || (0 !== \count($packagesToUpdate) && !\in_array($importName, $packagesToUpdate, true))) {
222+
if (!$entry->isRemotePackage() || ($packagesToUpdate && !\in_array($importName, $packagesToUpdate, true))) {
223223
continue;
224224
}
225225

src/Symfony/Component/AssetMapper/ImportMap/RemotePackageDownloader.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function downloadPackages(callable $progressCallback = null): array
3636
{
3737
try {
3838
$installed = $this->loadInstalled();
39-
} catch (\LogicException) {
39+
} catch (\InvalidArgumentException) {
4040
$installed = [];
4141
}
4242
$entries = $this->importMapConfigReader->getEntries();
@@ -60,7 +60,7 @@ public function downloadPackages(callable $progressCallback = null): array
6060
$remoteEntriesToDownload[$entry->importName] = $entry;
6161
}
6262

63-
if (0 === \count($remoteEntriesToDownload)) {
63+
if (!$remoteEntriesToDownload) {
6464
return [];
6565
}
6666

@@ -71,11 +71,7 @@ public function downloadPackages(callable $progressCallback = null): array
7171
throw new \LogicException(sprintf('The package "%s" was not in the requested packages.', $package));
7272
}
7373

74-
$filename = $this->savePackage(
75-
$package,
76-
$content,
77-
$remoteEntriesToDownload[$package]->type,
78-
);
74+
$filename = $this->savePackage($package, $content, $remoteEntriesToDownload[$package]->type);
7975
$newInstalled[$package] = [
8076
'path' => $filename,
8177
'version' => $remoteEntriesToDownload[$package]->version,
@@ -128,22 +124,22 @@ private function loadInstalled(): array
128124
}
129125

130126
$installedPath = $this->vendorDir.'/installed.php';
131-
if (!file_exists($installedPath)) {
127+
if (!is_file($installedPath)) {
132128
return [];
133129
}
134130

135131
$installed = is_file($installedPath) ? (static fn () => include $installedPath)() : [];
136132

137133
foreach ($installed as $package => $data) {
138134
if (!isset($data['path'])) {
139-
throw new \LogicException(sprintf('The package "%s" is missing its path.', $package));
135+
throw new \InvalidArgumentException(sprintf('The package "%s" is missing its path.', $package));
140136
}
141137

142138
if (!isset($data['version'])) {
143-
throw new \LogicException(sprintf('The package "%s" is missing its version.', $package));
139+
throw new \InvalidArgumentException(sprintf('The package "%s" is missing its version.', $package));
144140
}
145141

146-
if (!file_exists($this->vendorDir.'/'.$data['path'])) {
142+
if (!is_file($this->vendorDir.'/'.$data['path'])) {
147143
unset($installed[$package]);
148144
}
149145
}

src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,7 @@ private static function splitPackageNameAndFilePath(string $packageName): array
242242
*/
243243
private function makeImportsBare(string $content): string
244244
{
245-
$content = preg_replace_callback(self::IMPORT_REGEX, function ($matches) {
246-
$packageName = $matches[1];
247-
248-
return sprintf('from"%s"', $packageName);
249-
}, $content);
245+
$content = preg_replace_callback(self::IMPORT_REGEX, fn ($m) => sprintf('from"%s"', $m[1]), $content);
250246

251247
// source maps are not also downloaded - so remove the sourceMappingURL
252248
$content = preg_replace('{//# sourceMappingURL=.*$}m', '', $content);

src/Symfony/Component/AssetMapper/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=8.1",
20+
"symfony/deprecation-contracts": "^2.5|^3",
2021
"symfony/filesystem": "^5.4|^6.0|^7.0",
2122
"symfony/http-client": "^5.4|^6.0|^7.0"
2223
},

0 commit comments

Comments
 (0)
0