Skip to content

Commit

Permalink
chore: Increase strictness
Browse files Browse the repository at this point in the history
  • Loading branch information
marcreichel committed Mar 13, 2024
1 parent a88168b commit b160ae1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ includes:

parameters:
level: 9
checkUninitializedProperties: true
checkImplicitMixed: true
rememberPossiblyImpureFunctionValues: false
paths:
- src
6 changes: 3 additions & 3 deletions src/Command/ConfigurationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function askForMantisUrl(): void
label: 'The URL of your Mantis installation',
placeholder: 'E.g. https://tickets.company.tld/',
required: true,
validate: function ($value) {
validate: function (string $value) {
$parsedUrl = parse_url($value);

if ($parsedUrl === false) {
Expand Down Expand Up @@ -124,7 +124,7 @@ private function askForGitHubToken(): void
$this->config['githubToken'] = $this->password(
label: 'GitHub Personal Access Token',
required: true,
validate: fn ($value) => !str_starts_with($value, 'ghp_') && str_starts_with($value, 'github_pat_')
validate: fn (string $value) => !str_starts_with($value, 'ghp_') && str_starts_with($value, 'github_pat_')
? 'The provided value is not a valid GitHub PAT.'
: null,
);
Expand All @@ -136,7 +136,7 @@ private function askForGitHubRepository(): void
label: 'GitHub Repository(e.g. user/repository)',
placeholder: 'E.g. user/repository',
required: true,
validate: fn ($value) => count(explode('/', $value)) !== 2
validate: fn (string $value) => count(explode('/', $value)) !== 2
? 'Invalid repository name.'
: null,
);
Expand Down
1 change: 1 addition & 0 deletions src/Command/CreateGithubIssueFromMantisIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function __invoke(): int
return self::INVALID;
}

/** @var string[] $ids */
$ids = array_unique($idsArgument);
$message = count($ids) !== 1 ? 'Creating issues ...' : 'Creating issue ...';

Expand Down
2 changes: 1 addition & 1 deletion src/Command/IssuesListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __invoke(): int
GRAPHQL;

/** @var array{ repository: array<string, array{ title: string, url: string, closed: bool }> } $result */
$result = $this->githubConnector->graphql($query);
$result = $this->githubConnector->graphql($query)['data'];
$githubResult = $result['repository'];

switch ($this->option('output')) {
Expand Down
12 changes: 11 additions & 1 deletion src/Helper/VersionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ public static function latestVersion(): ?string
return null;
}

return $packagist->getLatestRelease($packageName)['version'] ?? null;
$latestRelease = $packagist->getLatestRelease($packageName);
if (!is_array($latestRelease) || !array_key_exists('version', $latestRelease)) {
return null;
}

$version = $latestRelease['version'] ?? null;
if (!is_string($version)) {
return null;
}

return $version;
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/Service/GithubConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ class GithubConnector

public function __construct(?ConfigValues $config)
{
if (!$config) {
return;
}
$this->client = new Client([
'headers' => [
'Accept' => 'application/vnd.github.v3+json',
'Authorization' => 'token ' . $config->getGithubToken(),
'Authorization' => 'token ' . $config?->getGithubToken(),
],
'verify' => false,
'base_uri' => 'https://api.github.com/repos/' . $config->getGithubRepo() . '/',
'base_uri' => 'https://api.github.com/repos/' . $config?->getGithubRepo() . '/',
]);
}

Expand Down
7 changes: 2 additions & 5 deletions src/Service/MantisConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ class MantisConnector

public function __construct(private ?ConfigValues $config)
{
if (!$this->config) {
return;
}
$this->client = new Client([
'headers' => [
'Authorization' => $this->config->getMantisToken(),
'Authorization' => $this->config?->getMantisToken(),
'Content-Type' => 'application/json',
],
'verify' => false,
'base_uri' => rtrim($this->config->getMantisUrl(), '/') . '/api/rest/issues/',
'base_uri' => rtrim($this->config?->getMantisUrl() ?? '', '/') . '/api/rest/issues/',
]);
}

Expand Down

0 comments on commit b160ae1

Please sign in to comment.