Skip to content

Commit

Permalink
refactor: update services to avoid the stan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiorodriguesroque committed Nov 9, 2024
1 parent d99f68b commit 67ed9f1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
17 changes: 13 additions & 4 deletions app/Services/GitHubService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

class GitHubService
{
public function getRepositories(?string $searchQuery = null): Collection
/**
* @param string $searchQuery
* @return Collection<int|string, mixed>
*/
public function getRepositories(string $searchQuery = ''): Collection
{
if (!$this->isEnabled()) {
return collect();
Expand All @@ -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<int|string, string>
*/
public function getIssuesForRepository(?string $repository, string $searchQuery = ''): Collection
{
if (!$this->isEnabled() || $repository === null) {
return collect();
Expand Down Expand Up @@ -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('/');

Expand Down
12 changes: 10 additions & 2 deletions app/Services/OgImageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ class OgImageGenerator
private ?string $templateFile = null;

private bool $polygonEnabled = false;

/**
* @var array<int>|null
*/
private ?array $polygonPoints = null;

public static function make(?string $title): self
public static function make(string $title): self
{
return new self($title);
}
Expand Down Expand Up @@ -58,6 +62,10 @@ public function withFilename(?string $filename): self
return $this;
}

/**
* @param array<int>|null $points
* @return $this
*/
public function withPolygonDecoration(?array $points = null): static
{
$this->polygonEnabled = true;
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/Services/SystemChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
15 changes: 13 additions & 2 deletions app/Services/Tailwind.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

class Tailwind
{
/**
* @var array<string, string>
*/
public array $shades = [];

/**
* @var array<int, float>
*/
protected array $intensityMap = [
50 => 0.95,
100 => 0.9,
Expand All @@ -36,7 +42,7 @@ public function getCssFormat(): string
if ($this->name === 'primary') {
$color = Str::between($color, '(', ')');
}

$output .= "\t--color-{$shade}: {$color};" . PHP_EOL;
}

Expand All @@ -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<string, string>
*/
public function generateColorShades(string $name, string $baseColor = ''): array
{
$baseColor = Hex::fromString($baseColor);

Expand Down
2 changes: 1 addition & 1 deletion app/Traits/HasOgImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ parameters:
excludePaths:
- ./app/Spotlight
- ./app/SocialProviders
- ./app/Settings
- ./app/Services/Icons.php
- ./app/Services/GitHubService.php

0 comments on commit 67ed9f1

Please sign in to comment.