Skip to content

Commit

Permalink
psalm fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
slash3b committed May 17, 2022
1 parent 72e7e73 commit b8e40fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
14 changes: 6 additions & 8 deletions build-conflicts.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use DateTime;
use DateTimeZone;
use ErrorException;
use Http\Client\Curl\Client;
use Psl\Dict;
use Psl\Env;
use Psl\Filesystem;
Expand All @@ -32,14 +33,12 @@
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesAdvisoryRuleDecorator;
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromFriendsOfPhp;
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromGithubApi;
use Http\Client\Curl\Client;
use Roave\SecurityAdvisories\AdvisorySources\GetAdvisoriesFromMultipleSources;
use Roave\SecurityAdvisories\Helper\ConstraintsMap;
use Roave\SecurityAdvisories\Rule\RuleProviderFactory;

use function file_get_contents;
use function iterator_to_array;
use function json_decode;
use function set_error_handler;

use const E_NOTICE;
Expand Down Expand Up @@ -182,7 +181,6 @@ static function (array $components): array {
);

$updatedAdvisoriesMessage = '';
/** @var Advisory $advisory */
foreach ($addedAdvisories as $advisory) {
$updatedAdvisoriesMessage .= Str\format(
"\n\t%-15s| %s\n\t%-15s| %s\n\t%-15s| %s\n\t%-15s| %s\n",
Expand All @@ -193,7 +191,7 @@ static function (array $components): array {
'URI',
$advisory->source->uri,
'Constraints',
$advisory->getConstraint() ?? "",
$advisory->getConstraint() ?? '',
);
}

Expand Down Expand Up @@ -241,10 +239,10 @@ static function (array $components): array {
$validateComposerJson(__DIR__ . '/build/composer.json');

$prevComposerJSONFileData = file_get_contents(__DIR__ . '/build/roave-security-advisories/composer.json');
/** @var array<string, array<string, array<string, string>>> $prevComposerDecodedData */
$prevComposerDecodedData = Json\decode($prevComposerJSONFileData, true);
$currentConstraints = ConstraintsMap::fromArray($prevComposerDecodedData['conflict']);
$updatedAdvisories = $currentConstraints->advisoriesDiff(iterator_to_array($getAdvisories()));
/** @var array<string, array<string, string>> $prevComposerDecodedData */
$prevComposerDecodedData = Json\decode($prevComposerJSONFileData, true);
$currentConstraints = ConstraintsMap::fromArray($prevComposerDecodedData['conflict']);
$updatedAdvisories = $currentConstraints->advisoriesDiff(iterator_to_array($getAdvisories()));

$copyGeneratedComposerJson(
__DIR__ . '/build/composer.json',
Expand Down
13 changes: 7 additions & 6 deletions src/Roave/SecurityAdvisories/Helper/ConstraintsMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ final class ConstraintsMap
/** @var array<string, array<VersionConstraint>> $map */
private array $map;

private function __construct()
/**
* @param array<string, array<VersionConstraint>> $conflicts
*/
private function __construct(array $conflicts)
{
$this->map = $conflicts;
}

/**
* @param array<string, array<string, string>> $packageConflictsParsedData
* @param array<string, string> $packageConflictsParsedData
*
* @return ConstraintsMap
*/
Expand All @@ -37,10 +41,7 @@ public static function fromArray(array $packageConflictsParsedData): self
$packageConflicts[$referenceName] = $packageConstraints;
}

$conflicts = new self();
$conflicts->map = $packageConflicts;

return $conflicts;
return new self($packageConflicts);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
final class ConstraintsMapTest extends TestCase
{
/**
* @param array<string, array<string, array<string, string>>> $data
* @param array<Advisory> $incomingAdvisories
* @param array<string, array<string, string>> $data
* @param array<Advisory> $incomingAdvisories
*
* @dataProvider newAdvisoriesDataProvider
*/
Expand All @@ -50,8 +50,8 @@ public function testAdvisoriesDiffDetectsUpdatedAndNewAdvisory(
}

/**
* @param array<string, array<string, array<string, string>>> $data
* @param array<Advisory> $incomingAdvisories
* @param array<string, array<string, string>> $data
* @param array<Advisory> $incomingAdvisories
*
* @dataProvider sameAdvisoriesDataProvider
*/
Expand Down

0 comments on commit b8e40fb

Please sign in to comment.