Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
fix priority
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-rubel committed Jan 3, 2022
1 parent 5debc0a commit 5f2847b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ parameters:

ignoreErrors:
- '#Property MichaelRubel\\SeoManager\\Exceptions\\ShouldImplementSeoTagInterfaceException\:\:\$message has no type specified\.#'
- '#Instanceof between \*NEVER\* and MichaelRubel\\SeoManager\\Models\\SeoTagContract will always evaluate to false\.#'
- '#Unreachable statement \- code above always terminates\.#'
- '#Method MichaelRubel\\SeoManager\\Composers\\SeoComposer\:\:getInstance\(\) is unused\.#'
- '#Call to an undefined static method MichaelRubel\\SeoManager\\Models\\SeoTagContract\:\:where\(\)\.#'

level: max

Expand Down
26 changes: 20 additions & 6 deletions src/Composers/SeoComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace MichaelRubel\SeoManager\Composers;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\View\View;
Expand Down Expand Up @@ -63,16 +65,17 @@ protected function getSeoTags(): ?Collection
: SeoTag::class
);

// @phpstan-ignore-next-line
if (! $model instanceof SeoTagContract) {
throw new ShouldImplementSeoTagInterfaceException();
}

// @phpstan-ignore-next-line
return $model::where($model->getUrlColumnName(), $url)
->orWhere($model->getUrlColumnName(), $wildcardUrl)
->first()
?->{$model->getTagsColumnName()};
$instance = $this->getInstance($model, $url);

if (! $instance->exists()) {
$instance = $this->getInstance($model, $wildcardUrl);
}

return $instance->first()?->{$model->getTagsColumnName()};
}

/**
Expand All @@ -89,4 +92,15 @@ protected function wildcard(string $url): string

return implode('/', $array);
}

/**
* @param SeoTagContract $model
* @param string $url
*
* @return Builder
*/
private function getInstance(SeoTagContract $model, string $url): Builder
{
return $model::where($model->getUrlColumnName(), $url);
}
}

0 comments on commit 5f2847b

Please sign in to comment.