Skip to content

Commit 599b0e7

Browse files
committed
cache
1 parent 51c2815 commit 599b0e7

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/Composer/ComposerOutdatedResponseProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private function resolveProjectComposerHash(): ?string
5656
private function resolveComposerOutdatedFilePath(): ?string
5757
{
5858
$projectComposerHash = $this->resolveProjectComposerHash();
59-
if (!in_array($projectComposerHash, [null, ''], true)) {
59+
if (! in_array($projectComposerHash, [null, ''], true)) {
6060
// load from cache if we already made the analysis
6161
return sys_get_temp_dir() . '/jack/composer-outdated-' . $projectComposerHash . '.json';
6262
}

src/Mapper/OutdatedPackageMapper.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
namespace Rector\Jack\Mapper;
66

7-
use Nette\Utils\FileSystem;
8-
use Nette\Utils\Json;
97
use Rector\Jack\ValueObject\OutdatedPackage;
108

119
final class OutdatedPackageMapper
1210
{
11+
/**
12+
* @var array<string, array<string, mixed>>
13+
*/
14+
private array $cachedComposerJson = [];
15+
1316
/**
1417
* @param array<array<string, mixed>> $outdatedPackages
1518
*
@@ -52,8 +55,17 @@ private function resolveRequiredPackages(string $composerJsonFilePath, string $s
5255
*/
5356
private function parseComposerJsonToJson(string $composerJsonFilePath): array
5457
{
55-
$composerJsonContents = FileSystem::read($composerJsonFilePath);
58+
if (isset($this->cachedComposerJson[$composerJsonFilePath])) {
59+
return $this->cachedComposerJson[$composerJsonFilePath];
60+
}
61+
62+
// use native functions to ease re-use by 3rd party packages
63+
$composerJsonContents = file_get_contents($composerJsonFilePath);
64+
65+
$composerJson = (array) json_decode($composerJsonContents, true);
66+
67+
$this->cachedComposerJson[$composerJsonFilePath] = $composerJson;
5668

57-
return (array) Json::decode($composerJsonContents, forceArrays: true);
69+
return $composerJson;
5870
}
5971
}

0 commit comments

Comments
 (0)