Skip to content

Commit

Permalink
Merge pull request #22 from madewithlove/cache
Browse files Browse the repository at this point in the history
Cache the output of the retrieved data
  • Loading branch information
WouterSioen authored Mar 19, 2020
2 parents 734eb8b + fbaf263 commit 66d49c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Composer/DependencyTreeRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@

class DependencyTreeRetriever
{
private static $output;

public function getDependencyTree(): string
{
if (!is_null(self::$output)) {
return self::$output;
}

$process = new Process(['composer', 'show', '-t', '-f', 'json']);
$process->run();

if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}

return $process->getOutput();
self::$output = $process->getOutput();

return self::$output;
}
}
10 changes: 9 additions & 1 deletion src/Composer/UsedLicensesRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@

class UsedLicensesRetriever
{
private static $output;

public function getComposerLicenses(): string
{
if (!is_null(self::$output)) {
return self::$output;
}

$process = new Process(['composer', 'license', '-f', 'json']);
$process->run();

if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}

return $process->getOutput();
self::$output = $process->getOutput();

return self::$output;
}
}

0 comments on commit 66d49c1

Please sign in to comment.