Skip to content

Commit

Permalink
Switching to psalm's totallyTyped="true" configuration for better t…
Browse files Browse the repository at this point in the history
…ype-checking
  • Loading branch information
Ocramius committed Jul 9, 2020
1 parent e93416f commit a82e801
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
totallyTyped="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down
1 change: 1 addition & 0 deletions src/Git/Value/MergeTargetCandidateBranches.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static function fromAllBranches(BranchName ...$branches): self
return $a->majorAndMinor() <=> $b->majorAndMinor();
});

/** @psalm-var non-empty-list<BranchName> $mergeTargetBranches */
return new self(array_values($mergeTargetBranches));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ public static function fromPayload(array $payload): self
Assert::isMap($payload['author']);
Assert::isMap($payload['labels']);
Assert::keyExists($payload['labels'], 'nodes');
Assert::isList($payload['labels']['nodes']);
Assert::stringNotEmpty($payload['url']);
Assert::boolean($payload['closed']);

$labels = $payload['labels']['nodes'];

Assert::isList($labels);
Assert::allIsMap($labels);

return new self(
$payload['number'],
$payload['title'],
Author::fromPayload($payload['author']),
array_values(array_map([Label::class, 'fromPayload'], $payload['labels']['nodes'])),
array_values(array_map([Label::class, 'fromPayload'], $labels)),
isset($payload['merged'])
? (bool) $payload['merged'] || $payload['closed']
: $payload['closed'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,26 @@ public static function fromPayload(array $payload): self

Assert::isMap($payload['issues']);
Assert::keyExists($payload['issues'], 'nodes');
Assert::isList($payload['issues']['nodes']);

Assert::isMap($payload['pullRequests']);
Assert::keyExists($payload['pullRequests'], 'nodes');
Assert::isList($payload['pullRequests']['nodes']);

$issues = $payload['issues']['nodes'];
$pullRequests = $payload['pullRequests']['nodes'];

Assert::isList($issues);
Assert::isList($pullRequests);
Assert::allIsMap($issues);
Assert::allIsMap($pullRequests);

return new self(
$payload['number'],
$payload['closed'],
$payload['title'],
$payload['description'],
array_merge(
array_map([IssueOrPullRequest::class, 'fromPayload'], $payload['issues']['nodes']),
array_map([IssueOrPullRequest::class, 'fromPayload'], $payload['pullRequests']['nodes'])
array_map([IssueOrPullRequest::class, 'fromPayload'], $issues),
array_map([IssueOrPullRequest::class, 'fromPayload'], $pullRequests)
),
new Uri($payload['url'])
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\AutomaticReleases\Github\Api\GraphQL\Query\GetMilestoneChangelog\Response\Milestone;
use Laminas\AutomaticReleases\Github\Api\GraphQL\RunQuery;
use Laminas\AutomaticReleases\Github\Value\RepositoryName;
use Webmozart\Assert\Assert;

final class GetMilestoneFirst100IssuesAndPullRequests implements GetGithubMilestone
{
Expand Down Expand Up @@ -76,13 +77,20 @@ public function __invoke(
RepositoryName $repositoryName,
int $milestoneNumber
): Milestone {
return Milestone::fromPayload($this->runQuery->__invoke(
$queryResult = $this->runQuery->__invoke(
self::QUERY,
[
'repositoryName' => $repositoryName->name(),
'owner' => $repositoryName->owner(),
'milestoneNumber' => $milestoneNumber,
]
)['repository']['milestone']);
);

Assert::keyExists($queryResult, 'repository');
Assert::isMap($queryResult['repository']);
Assert::keyExists($queryResult['repository'], 'milestone');
Assert::isMap($queryResult['repository']['milestone']);

return Milestone::fromPayload($queryResult['repository']['milestone']);
}
}
4 changes: 3 additions & 1 deletion src/Gpg/ImportGpgKeyFromStringViaTemporaryFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public function __invoke(string $keyContents): SecretKeyId

preg_match('/key\\s+([A-F0-9]+):\\s+secret\\s+key\\s+imported/im', $output, $matches);

Assert::isList($matches);
unlink($keyFileName);

Assert::isList($matches);
Assert::allString($matches);

return SecretKeyId::fromBase16String($matches[1]);
}
}
6 changes: 4 additions & 2 deletions test/unit/Environment/EnvironmentVariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use Laminas\AutomaticReleases\Gpg\SecretKeyId;
use PHPUnit\Framework\TestCase;

use function array_combine;
use function array_map;
use function array_walk;
use function Safe\array_combine;
use function Safe\putenv;
use function uniqid;

Expand Down Expand Up @@ -45,8 +45,10 @@ protected function setUp(): void

protected function tearDown(): void
{
$originalValues = $this->originalValues;

array_walk(
$this->originalValues,
$originalValues,
/** @param string|false $value */
static function ($value, string $key): void {
if ($value === false) {
Expand Down

0 comments on commit a82e801

Please sign in to comment.