mirror of
https://github.com/archtechx/laravel-seo.git
synced 2025-12-12 01:44:03 +00:00
Code quality
This commit is contained in:
parent
0c0cf1ef5a
commit
2dc7b7048e
5 changed files with 32 additions and 27 deletions
14
phpstan.neon
14
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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\SEO;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -73,9 +75,10 @@ class SEOManager
|
|||
}
|
||||
|
||||
/** Set one or more values. */
|
||||
public function set(string|array $key, string|null $value = null): string|array
|
||||
public function set(string|array $key, string|null $value = null): string|array|null
|
||||
{
|
||||
if (is_array($key)) {
|
||||
/** @var array<string, string> $key */
|
||||
foreach ($key as $k => $v) {
|
||||
$this->set($k, $v);
|
||||
}
|
||||
|
|
@ -84,7 +87,8 @@ class SEOManager
|
|||
->keys()
|
||||
->mapWithKeys(fn (string $key) => [$key => $this->get($key)])
|
||||
->toArray();
|
||||
} else {
|
||||
}
|
||||
|
||||
$this->values[$key] = $value;
|
||||
|
||||
if (Str::contains($key, '.')) {
|
||||
|
|
@ -93,7 +97,6 @@ class SEOManager
|
|||
|
||||
return $this->get($key);
|
||||
}
|
||||
}
|
||||
|
||||
/** Resolve a value. */
|
||||
public function get(string $key): string|null
|
||||
|
|
@ -124,7 +127,7 @@ class SEOManager
|
|||
->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 @@ class SEOManager
|
|||
/**
|
||||
* 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<string, string> $key */
|
||||
foreach ($key as $k => $v) {
|
||||
$this->meta($k, $v);
|
||||
}
|
||||
|
|
@ -178,7 +182,7 @@ class SEOManager
|
|||
}
|
||||
|
||||
/** 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 @@ class SEOManager
|
|||
}
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use ArchTech\SEO\SEOManager;
|
||||
|
||||
if (! function_exists('seo')) {
|
||||
|
|
@ -7,7 +9,7 @@ if (! function_exists('seo')) {
|
|||
{
|
||||
if (! $key) {
|
||||
return app('seo');
|
||||
} else if (is_array($key)) {
|
||||
} elseif (is_array($key)) {
|
||||
return app('seo')->set($key);
|
||||
} else {
|
||||
return app('seo')->get($key);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
beforeEach(fn () => config(['services.flipp.key' => 'abc']));
|
||||
|
||||
test('flipp templates can be set', function () {
|
||||
seo()->flipp('blog', 'abcdefg');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue