Skip to content

Commit

Permalink
Fixed PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed May 14, 2024
1 parent 9dcf1e0 commit 42b439b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/ComposerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function getPath(): string

public function getType(): ?string
{
return Arrays::get($this->data, 'type', NULL);
$type = Arrays::get($this->data, 'type', NULL);
assert(is_string($type) || is_null($type));
return $type;
}


Expand Down
12 changes: 10 additions & 2 deletions src/Extensions/JanpechaActionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private function processBuildFile(CodeChecker\Engine $engine): void
$created = FALSE;
$oldContent = $engine->readFile(self::BuildPath);
$yaml = Yaml::decode($oldContent);
assert(is_array($yaml));
}

if (!isset($yaml['name'])) {
Expand Down Expand Up @@ -129,6 +130,7 @@ private function processBuildFile(CodeChecker\Engine $engine): void
$yaml = $this->createTestsJob($yaml, $engine);
$yaml = $this->createCodingStyleJob($yaml, $engine);
$yaml = $this->createStaticAnalysisJob($yaml, $engine);
assert(isset($yaml['jobs']) && is_array($yaml['jobs']));

if (count($yaml['jobs']) > 0) {
$newContent = Yaml::encode($yaml);
Expand All @@ -152,6 +154,8 @@ private function createCodingStyleJob(array $yaml, CodeChecker\Engine $engine):
return $yaml;
}

assert(isset($yaml['jobs']) && is_array($yaml['jobs']));

if (!isset($yaml['jobs']['coding-style'])) {
$engine->reportFixInFile("Created job 'coding-style'", self::BuildPath);
$yaml['jobs']['coding-style'] = [
Expand All @@ -174,6 +178,8 @@ private function createCodingStyleJob(array $yaml, CodeChecker\Engine $engine):
*/
private function createStaticAnalysisJob(array $yaml, CodeChecker\Engine $engine): array
{
assert(isset($yaml['jobs']) && is_array($yaml['jobs']));

if (!isset($yaml['jobs']['static-analysis']) && ($phpstanConfigPath = $this->findPhpStanConfig($engine)) !== NULL) {
$engine->reportFixInFile("Created job 'static-analysis'", self::BuildPath);
$yaml['jobs']['static-analysis'] = [
Expand Down Expand Up @@ -217,6 +223,8 @@ private function createTestsJob(array $yaml, CodeChecker\Engine $engine): array
return $yaml;
}

assert(isset($yaml['jobs']) && is_array($yaml['jobs']));

if (!isset($yaml['jobs']['tests'])) {
$engine->reportFixInFile("Created job 'tests'", self::BuildPath);
$yaml['jobs']['tests'] = [
Expand All @@ -238,7 +246,7 @@ private function createTestsJob(array $yaml, CodeChecker\Engine $engine): array
$yaml['jobs']['tests']['with']['workingDirectory'] = $this->workingDirectory;
}

if (count($yaml['jobs']['tests']['with']) === 0) {
if (count($yaml['jobs']['tests']['with']) === 0) { // @phpstan-ignore identical.alwaysFalse
unset($yaml['jobs']['tests']['with']);
}

Expand Down Expand Up @@ -268,7 +276,7 @@ public static function configure(CodeChecker\CheckerConfig $config): void
);

$config->addExtension(new self(
$config->getComposerFile()->getType(),
$config->getComposerFile()->getType() ?? 'library',
$config->getPhpVersion(),
$config->getMaxPhpVersion(),
$config->getConfigFile() !== NULL,
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static function addEmptyLinesBetweenItems(string $result): string
{
$i = 0;

return preg_replace_callback('#^([\s]{4})?[a-zA-Z_\\\'-]+:#m', function ($match) use (&$i) {
return (string) preg_replace_callback('#^([\s]{4})?[a-zA-Z_\\\'-]+:#m', function ($match) use (&$i) {
$i++;

if ($i === 1) {
Expand Down

0 comments on commit 42b439b

Please sign in to comment.