Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 494af0a

Browse files
committed
style : cs fixes from rector
1 parent b9e6cb6 commit 494af0a

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed

Cache.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ public function read($file)
4242
{
4343
$content = parent::read($file);
4444

45-
if ($this->tagsManager !== null && \is_string($content) && $this->tagsManager->hasProvider($file) && \is_array($data = \json_decode($content, true))) {
46-
$content = \json_encode($this->removeLegacyTags($data));
45+
if ($this->tagsManager !== null && \is_string($content) && $this->tagsManager->hasProvider($file) && \is_array($data = \json_decode($content, true, 512, \JSON_THROW_ON_ERROR))) {
46+
$content = \json_encode($this->removeLegacyTags($data), \JSON_THROW_ON_ERROR);
4747
}
4848

4949
return $content;
5050
}
5151

5252
/**
5353
* Helper to remove legacy tags.
54+
*
55+
* @return mixed[]
5456
*/
5557
public function removeLegacyTags(array $data): array
5658
{

ComposerRepository.php

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ protected function loadProviderListings($data): void
6060

6161
/**
6262
* {@inheritdoc}
63+
*
64+
* @return mixed|mixed[]
6365
*/
6466
protected function fetchFile($filename, $cacheKey = null, $sha256 = null, $storeLastModifiedTime = false): array
6567
{

LegacyTagsManager.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ final class LegacyTagsManager implements LegacyTagsManagerContract
5151
/** @var null|array */
5252
private $versions;
5353

54-
/**
55-
* Create a new LegacyTagsManager instance.
56-
*/
5754
public function __construct(IOInterface $io, Downloader $downloader)
5855
{
5956
$this->io = $io;
@@ -205,6 +202,7 @@ public function reset(): void
205202
}
206203

207204
/**
205+
* @param array<string, array<string, array<int, string>>> $versions
208206
* @param \Composer\Semver\Constraint\Constraint|\Composer\Semver\Constraint\MultiConstraint $symfonyConstraint
209207
*/
210208
private function getVersions(array $versions, $symfonyConstraint): array

Plugin.php

+18-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
use Symfony\Component\Console\Input\ArgvInput;
4646
use Symfony\Component\Console\Input\InputInterface;
4747

48-
class Plugin implements EventSubscriberInterface, PluginInterface
48+
final class Plugin implements EventSubscriberInterface, PluginInterface
4949
{
5050
/** @var string */
5151
public const VERSION = '0.13.1';
@@ -56,12 +56,20 @@ class Plugin implements EventSubscriberInterface, PluginInterface
5656
/** @var string */
5757
public const PACKAGE_NAME = 'narrowspark/automatic-composer-prefetcher';
5858

59+
public $providerRepos;
60+
61+
public $repositoryClasses;
62+
63+
public $repositories;
64+
65+
public $config;
66+
5967
/**
6068
* A Container instance.
6169
*
6270
* @var \Narrowspark\Automatic\Common\Contract\Container
6371
*/
64-
protected $container;
72+
private $container;
6573

6674
/**
6775
* Check if the the plugin is activated.
@@ -123,6 +131,8 @@ public function activate(Composer $composer, IOInterface $io): void
123131

124132
/**
125133
* {@inheritdoc}
134+
*
135+
* @return mixed[][][]|string[]
126136
*/
127137
public static function getSubscribedEvents(): array
128138
{
@@ -147,7 +157,7 @@ public function onPreDependenciesSolving(InstallerEvent $event): void
147157
$listed = [];
148158
$packages = [];
149159
$pool = $event->getPool();
150-
$pool = Closure::bind(function () {
160+
$pool = Closure::bind(function (): Pool {
151161
foreach ($this->providerRepos as $k => $repo) {
152162
$this->providerRepos[$k] = new class($repo) extends BaseComposerRepository {
153163
/**
@@ -164,8 +174,10 @@ public function __construct(RepositoryInterface $repo)
164174

165175
/**
166176
* {@inheritdoc}
177+
*
178+
* @return mixed[]
167179
*/
168-
public function whatProvides(Pool $pool, $name, $bypassFilters = false)
180+
public function whatProvides(Pool $pool, $name, $bypassFilters = false): array
169181
{
170182
$packages = [];
171183

@@ -260,8 +272,8 @@ private function configureLegacyTagsManager(
260272
}
261273

262274
$this->addLegacyTags($io, $requires, $tagsManager);
263-
} elseif (isset($extra[static::COMPOSER_EXTRA_KEY]['require'])) {
264-
$this->addLegacyTags($io, $extra[static::COMPOSER_EXTRA_KEY]['require'], $tagsManager);
275+
} elseif (isset($extra[self::COMPOSER_EXTRA_KEY]['require'])) {
276+
$this->addLegacyTags($io, $extra[self::COMPOSER_EXTRA_KEY]['require'], $tagsManager);
265277
}
266278
}
267279

Prefetcher.php

+15-19
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929

3030
final class Prefetcher implements PrefetcherContract
3131
{
32+
/** @var array */
33+
private const REPO_READING_COMMANDS = [
34+
'create-project' => true,
35+
'outdated' => true,
36+
'require' => true,
37+
'update' => true,
38+
'install' => true,
39+
];
40+
3241
/**
3342
* The composer io implementation.
3443
*
@@ -92,15 +101,6 @@ final class Prefetcher implements PrefetcherContract
92101
*/
93102
private $cacheDirPopulated = false;
94103

95-
/** @var array */
96-
private static $repoReadingCommands = [
97-
'create-project' => true,
98-
'outdated' => true,
99-
'require' => true,
100-
'update' => true,
101-
'install' => true,
102-
];
103-
104104
/**
105105
* Create a new PreFetcher instance.
106106
*/
@@ -148,12 +148,12 @@ public function prefetchComposerRepositories(): void
148148
$command = $this->input->getFirstArgument();
149149

150150
if ($this->populateRepoCacheDir === true
151-
&& isset(self::$repoReadingCommands[$command])
151+
&& isset(self::REPO_READING_COMMANDS[$command])
152152
&& ($command !== 'install' || (\file_exists(Factory::getComposerFile()) && ! \file_exists(Util::getComposerLockFile())))
153153
) {
154154
$repos = [];
155155

156-
foreach ($this->composer->getPackage()->getRepositories() as $name => $repo) {
156+
foreach ($this->composer->getPackage()->getRepositories() as $repo) {
157157
if (! isset($repo['type']) || $repo['type'] !== 'composer' || ! empty($repo['force-lazy-providers'])) {
158158
continue;
159159
}
@@ -179,15 +179,15 @@ public function prefetchComposerRepositories(): void
179179
*/
180180
public function fetchAllFromOperations($event): void
181181
{
182-
if ($this->cacheDirPopulated === true || $this->getDryRun() === true) {
182+
if ($this->cacheDirPopulated || $this->getDryRun()) {
183183
return;
184184
}
185185

186186
$this->cacheDirPopulated = true;
187187

188188
$downloads = [];
189189

190-
foreach ($event->getOperations() as $i => $operation) {
190+
foreach ($event->getOperations() as $operation) {
191191
switch ($operation->getJobType()) {
192192
case 'install':
193193
$package = $operation->getPackage();
@@ -245,7 +245,7 @@ private static function getUrlFromPackage(PackageInterface $package): ?string
245245
{
246246
$fileUrl = $package->getDistUrl();
247247

248-
if (! $fileUrl) {
248+
if ($fileUrl === '') {
249249
return null;
250250
}
251251

@@ -281,10 +281,6 @@ function (PackageInterface $package, $processedUrl) {
281281
*/
282282
private function getDryRun(): bool
283283
{
284-
if ($this->input->hasParameterOption('--dry-run')) {
285-
return true;
286-
}
287-
288-
return false;
284+
return $this->input->hasParameterOption('--dry-run');
289285
}
290286
}

0 commit comments

Comments
 (0)