Skip to content

Commit

Permalink
Fix all PHPStan level MAX errors
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Aug 28, 2024
1 parent 5bc77bf commit 016df4c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
16 changes: 3 additions & 13 deletions src/Behaviours/MakeTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,14 @@ public function encodeValueForComparison(mixed $value, string|null $type = null)
return 'null';
}

if ($type === 'integer' || is_numeric($value)) {
if ($type === 'integer' && is_numeric($value)) {
return (string) $value;
}

if ($type === 'boolean' || is_bool($value)) {
return (bool) $value ? 'true' : 'false';
}

if ($type === 'object' || is_object($value)) {
return json_encode($value);
}

if ($type === 'string' || $type === 'array' || $type === 'object') {
if (is_string($value)) {
return "'$value'";
Expand All @@ -108,14 +104,8 @@ public function encodeValueForComparison(mixed $value, string|null $type = null)
}
}

try {
$value = (string) $value;

return $value;
} catch (\Throwable $e) {
/// FIXME: we cannot cast this value to a string, so we are generating a random string that will not match anything else, fow now
return '--- cannot cast to string --- ' . Str::random(16);
}
/// FIXME: we cannot cast this value to a string, so we are generating a random string that will not match anything else, fow now
return '--- cannot cast to string --- ' . Str::random(16);
}

public function granularPropertyIsAllowed(string $name, Model|string $model): bool
Expand Down
6 changes: 5 additions & 1 deletion src/Console/Commands/Urls.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ public function handle(): int
return 0;
}

protected function replaceDomain(string $url): string
protected function replaceDomain(mixed $url): string
{
$newDomain = config('app.url');

if (!is_string($url) || !is_string($newDomain)) {
return '';
}

$oldDomain = parse_url($url, PHP_URL_SCHEME) . '://'. parse_url($url, PHP_URL_HOST);

$url = str_replace($oldDomain, $newDomain, $url);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/Zap.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct()
*/
public function handle(): int
{
if (!$this->option('force')) {
if ($this->option('force') === false) {
$this->error('This operation can only be executed if forced.');

return 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Services/CdnBaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function maxUrls(): int

public function enabled(): bool
{
if (isset($this->enabled) && $this->enabled !== null) {
if (isset($this->enabled)) {
return $this->enabled;
}

Expand Down
24 changes: 18 additions & 6 deletions src/Services/CloudFront/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function getClient(): CloudFrontClient|null

protected function hasInProgressInvalidation(): bool
{
if ($this->client() === null) {
return false;
}

$list = $this->client()
->listInvalidations([
'DistributionId' => $this->getDistributionId(),
Expand All @@ -91,6 +95,12 @@ public function createInvalidationRequest(Invalidation|array $invalidation = nul
{
$invalidation = $this->createInvalidation($invalidation);

if ($this->client() === null) {
Helpers::debug('[CLOUD FRONT]: Service is disabled.');

return $invalidation;
}

$paths = $invalidation->paths()->toArray();

Helpers::debug(
Expand All @@ -101,12 +111,6 @@ public function createInvalidationRequest(Invalidation|array $invalidation = nul
')...',
);

if (!$this->isProperlyConfigured()) {
Helpers::debug('[CLOUD FRONT]: Service is disabled.');

return $invalidation;
}

try {
$response = $this->client()->createInvalidation([
'DistributionId' => $this->getDistributionId(),
Expand Down Expand Up @@ -139,6 +143,10 @@ public function isProperlyConfigured(): bool

public function invalidationIsCompleted(string $invalidationId): bool
{
if (!$this->isProperlyConfigured()) {
return false;
}

$response = $this->getInvalidation($invalidationId);

if (blank($response)) {
Expand All @@ -150,6 +158,10 @@ public function invalidationIsCompleted(string $invalidationId): bool

public function getInvalidation(string $invalidationId): AwsResult
{
if ($this->client() === null) {
return new AwsResult();
}

return $this->client()->getInvalidation([
'DistributionId' => $this->getDistributionId(),
'Id' => $invalidationId,
Expand Down

0 comments on commit 016df4c

Please sign in to comment.