From 67ed9f10d8f8f18ee751fdb185899d4a3dbe9ceb Mon Sep 17 00:00:00 2001 From: fabiorodriguesroque Date: Sat, 9 Nov 2024 14:23:30 +0000 Subject: [PATCH] refactor: update services to avoid the stan errors --- app/Services/GitHubService.php | 17 +++++++++++++---- app/Services/OgImageGenerator.php | 12 ++++++++++-- app/Services/SystemChecker.php | 8 ++++---- app/Services/Tailwind.php | 15 +++++++++++++-- app/Traits/HasOgImage.php | 2 +- phpstan.neon | 3 +++ 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/app/Services/GitHubService.php b/app/Services/GitHubService.php index b5fc2b92..13dfa04d 100644 --- a/app/Services/GitHubService.php +++ b/app/Services/GitHubService.php @@ -9,7 +9,11 @@ class GitHubService { - public function getRepositories(?string $searchQuery = null): Collection + /** + * @param string $searchQuery + * @return Collection + */ + public function getRepositories(string $searchQuery = ''): Collection { if (!$this->isEnabled()) { return collect(); @@ -31,10 +35,15 @@ public function getRepositories(?string $searchQuery = null): Collection public function isEnabled(): bool { - return config('github.enabled'); + return (bool) config('github.enabled'); } - public function getIssuesForRepository(?string $repository, ?string $searchQuery = null): Collection + /** + * @param string|null $repository + * @param string $searchQuery + * @return Collection + */ + public function getIssuesForRepository(?string $repository, string $searchQuery = ''): Collection { if (!$this->isEnabled() || $repository === null) { return collect(); @@ -76,7 +85,7 @@ public function getIssueTitle(?string $repository, ?int $issueNumber): ?string } } - public function createIssueInRepository(string $repository, $title, $body): int + public function createIssueInRepository(string $repository, string $title, string $body): int { $repo = str($repository)->explode('/'); diff --git a/app/Services/OgImageGenerator.php b/app/Services/OgImageGenerator.php index 746a45e8..284f9903 100644 --- a/app/Services/OgImageGenerator.php +++ b/app/Services/OgImageGenerator.php @@ -18,9 +18,13 @@ class OgImageGenerator private ?string $templateFile = null; private bool $polygonEnabled = false; + + /** + * @var array|null + */ private ?array $polygonPoints = null; - public static function make(?string $title): self + public static function make(string $title): self { return new self($title); } @@ -58,6 +62,10 @@ public function withFilename(?string $filename): self return $this; } + /** + * @param array|null $points + * @return $this + */ public function withPolygonDecoration(?array $points = null): static { $this->polygonEnabled = true; @@ -76,7 +84,7 @@ public function getFilename(): string $this->filename = 'og-' . $this->filename; } - return $this->filename ?? 'og-' . md5(time()) . '.jpg'; + return $this->filename ?? 'og-' . md5((string) time()) . '.jpg'; } public function generate(): OgImage diff --git a/app/Services/SystemChecker.php b/app/Services/SystemChecker.php index 605194ac..91272eb9 100644 --- a/app/Services/SystemChecker.php +++ b/app/Services/SystemChecker.php @@ -12,20 +12,20 @@ class SystemChecker public function getVersions(): self { - $this->remoteVersion = trim($this->getRemoteVersion()); - $this->currentVersion = trim($this->getApplicationVersion()); + $this->remoteVersion = trim((string) $this->getRemoteVersion()); + $this->currentVersion = trim((string) $this->getApplicationVersion()); return $this; } - public function getApplicationVersion(): string|null + public function getApplicationVersion(): string|null|bool { return cache()->remember($this->cacheKeyCurrent, now()->addDay(), function () { return shell_exec('git describe --tag --abbrev=0'); }); } - public function getRemoteVersion(): string|null + public function getRemoteVersion(): string|null|bool { return cache()->remember($this->cacheKeyRemote, now()->addDay(), function () { shell_exec('git fetch --tags'); diff --git a/app/Services/Tailwind.php b/app/Services/Tailwind.php index a03706a4..a528bfde 100644 --- a/app/Services/Tailwind.php +++ b/app/Services/Tailwind.php @@ -8,8 +8,14 @@ class Tailwind { + /** + * @var array + */ public array $shades = []; + /** + * @var array + */ protected array $intensityMap = [ 50 => 0.95, 100 => 0.9, @@ -36,7 +42,7 @@ public function getCssFormat(): string if ($this->name === 'primary') { $color = Str::between($color, '(', ')'); } - + $output .= "\t--color-{$shade}: {$color};" . PHP_EOL; } @@ -46,7 +52,12 @@ public function getCssFormat(): string return $output; } - public function generateColorShades(string $name, ?string $baseColor): array + /** + * @param string $name + * @param string $baseColor + * @return array + */ + public function generateColorShades(string $name, string $baseColor = ''): array { $baseColor = Hex::fromString($baseColor); diff --git a/app/Traits/HasOgImage.php b/app/Traits/HasOgImage.php index 3a422857..1507766b 100644 --- a/app/Traits/HasOgImage.php +++ b/app/Traits/HasOgImage.php @@ -8,7 +8,7 @@ trait HasOgImage { public function getOgImage(?string $description, string $subject = 'Roadmap'): string { - return OgImageGenerator::make($this->title) + return OgImageGenerator::make($this->title ?? '') ->withSubject($subject) ->withDescription($description) ->withPolygonDecoration() diff --git a/phpstan.neon b/phpstan.neon index 4e594c06..94f158c0 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,3 +8,6 @@ parameters: excludePaths: - ./app/Spotlight - ./app/SocialProviders + - ./app/Settings + - ./app/Services/Icons.php + - ./app/Services/GitHubService.php