diff --git a/phpstan.neon b/phpstan.neon index 5b8dfd1..f586106 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,16 +9,12 @@ parameters: universalObjectCratesClasses: - Illuminate\Routing\Route + - ArchTech\SEO\SEOManager ignoreErrors: - # - - # message: '#Offset (.*?) does not exist on array\|null#' - # paths: - # - tests/* - # - - # message: '#expects resource, resource\|false given#' - # paths: - # - tests/* - # - '#should return \$this#' + - '#SEOManager\|array\|string\|null#' + - '#string\|false given#' + - '#flipp\(\) should return#' + - '#\_\_set\(\) has no return typehint specified#' checkMissingIterableValueType: false diff --git a/src/SEOManager.php b/src/SEOManager.php index f6e3e5b..7f59ae0 100644 --- a/src/SEOManager.php +++ b/src/SEOManager.php @@ -1,5 +1,7 @@ $key */ foreach ($key as $k => $v) { $this->set($k, $v); } @@ -84,15 +87,15 @@ public function set(string|array $key, string|null $value = null): string|array ->keys() ->mapWithKeys(fn (string $key) => [$key => $this->get($key)]) ->toArray(); - } else { - $this->values[$key] = $value; + } - if (Str::contains($key, '.')) { - $this->extension(Str::before($key, '.'), enabled: true); - } + $this->values[$key] = $value; - return $this->get($key); + if (Str::contains($key, '.')) { + $this->extension(Str::before($key, '.'), enabled: true); } + + return $this->get($key); } /** Resolve a value. */ @@ -124,7 +127,7 @@ public function extensions(): array ->filter(fn (bool $enabled) => $enabled) ->keys() ->mapWithKeys(fn (string $extension) => [ - $extension => $this->meta("extensions.$extension.view") ?? ("seo::extensions." . $extension) + $extension => $this->meta("extensions.$extension.view") ?? ('seo::extensions.' . $extension), ]) ->toArray(); } @@ -155,12 +158,13 @@ public function flipp(string $template, string|array $data = null): string|stati /** * Get or set metadata. * @param string|array $key The key or key-value pair being set. - * @param string|array|mixed $value The value (if a single key is provided). - * @return mixed + * @param string|array|null $value The value (if a single key is provided). + * @return $this|string */ - public function meta(string|array $key, mixed $value = null): mixed + public function meta(string|array $key, string|array $value = null): mixed { if (is_array($key)) { + /** @var array $key */ foreach ($key as $k => $v) { $this->meta($k, $v); } @@ -178,7 +182,7 @@ public function meta(string|array $key, mixed $value = null): mixed } /** Handle magic method calls. */ - public function __call($name, $arguments) + public function __call(string $name, array $arguments): string|array|null|static { if (isset($this->extensions[$name])) { return $this->extension($name, $arguments[0] ?? true); @@ -209,13 +213,13 @@ public function __call($name, $arguments) } /** Handle magic get. */ - public function __get(string $key) + public function __get(string $key): string|null { return $this->get(Str::snake($key, '.')); } /** Handle magic set. */ - public function __set(string $key, mixed $value) + public function __set(string $key, string $value) { return $this->set(Str::snake($key, '.'), $value); } diff --git a/src/SEOServiceProvider.php b/src/SEOServiceProvider.php index 1a54a41..1fd36af 100644 --- a/src/SEOServiceProvider.php +++ b/src/SEOServiceProvider.php @@ -4,8 +4,8 @@ namespace ArchTech\SEO; -use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use ImLiam\BladeHelper\BladeHelperServiceProvider; use ImLiam\BladeHelper\Facades\BladeHelper; class SEOServiceProvider extends ServiceProvider @@ -13,6 +13,7 @@ class SEOServiceProvider extends ServiceProvider public function register(): void { $this->app->singleton('seo', SEOManager::class); + $this->app->register(BladeHelperServiceProvider::class); } public function boot(): void diff --git a/src/helpers.php b/src/helpers.php index 865a534..658df88 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -1,5 +1,7 @@ set($key); } else { return app('seo')->get($key); diff --git a/tests/Pest/FlippTest.php b/tests/Pest/FlippTest.php index 3bf2c67..05ad821 100644 --- a/tests/Pest/FlippTest.php +++ b/tests/Pest/FlippTest.php @@ -1,5 +1,7 @@ config(['services.flipp.key' => 'abc'])); + test('flipp templates can be set', function () { seo()->flipp('blog', 'abcdefg');