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:
|
universalObjectCratesClasses:
|
||||||
- Illuminate\Routing\Route
|
- Illuminate\Routing\Route
|
||||||
|
- ArchTech\SEO\SEOManager
|
||||||
|
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
# -
|
- '#SEOManager\|array\|string\|null#'
|
||||||
# message: '#Offset (.*?) does not exist on array\|null#'
|
- '#string\|false given#'
|
||||||
# paths:
|
- '#flipp\(\) should return#'
|
||||||
# - tests/*
|
- '#\_\_set\(\) has no return typehint specified#'
|
||||||
# -
|
|
||||||
# message: '#expects resource, resource\|false given#'
|
|
||||||
# paths:
|
|
||||||
# - tests/*
|
|
||||||
# - '#should return \$this#'
|
|
||||||
|
|
||||||
checkMissingIterableValueType: false
|
checkMissingIterableValueType: false
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ArchTech\SEO;
|
namespace ArchTech\SEO;
|
||||||
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
@ -73,9 +75,10 @@ class SEOManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set one or more values. */
|
/** 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)) {
|
if (is_array($key)) {
|
||||||
|
/** @var array<string, string> $key */
|
||||||
foreach ($key as $k => $v) {
|
foreach ($key as $k => $v) {
|
||||||
$this->set($k, $v);
|
$this->set($k, $v);
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +87,8 @@ class SEOManager
|
||||||
->keys()
|
->keys()
|
||||||
->mapWithKeys(fn (string $key) => [$key => $this->get($key)])
|
->mapWithKeys(fn (string $key) => [$key => $this->get($key)])
|
||||||
->toArray();
|
->toArray();
|
||||||
} else {
|
}
|
||||||
|
|
||||||
$this->values[$key] = $value;
|
$this->values[$key] = $value;
|
||||||
|
|
||||||
if (Str::contains($key, '.')) {
|
if (Str::contains($key, '.')) {
|
||||||
|
|
@ -93,7 +97,6 @@ class SEOManager
|
||||||
|
|
||||||
return $this->get($key);
|
return $this->get($key);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** Resolve a value. */
|
/** Resolve a value. */
|
||||||
public function get(string $key): string|null
|
public function get(string $key): string|null
|
||||||
|
|
@ -124,7 +127,7 @@ class SEOManager
|
||||||
->filter(fn (bool $enabled) => $enabled)
|
->filter(fn (bool $enabled) => $enabled)
|
||||||
->keys()
|
->keys()
|
||||||
->mapWithKeys(fn (string $extension) => [
|
->mapWithKeys(fn (string $extension) => [
|
||||||
$extension => $this->meta("extensions.$extension.view") ?? ("seo::extensions." . $extension)
|
$extension => $this->meta("extensions.$extension.view") ?? ('seo::extensions.' . $extension),
|
||||||
])
|
])
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
@ -155,12 +158,13 @@ class SEOManager
|
||||||
/**
|
/**
|
||||||
* Get or set metadata.
|
* Get or set metadata.
|
||||||
* @param string|array $key The key or key-value pair being set.
|
* @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).
|
* @param string|array|null $value The value (if a single key is provided).
|
||||||
* @return mixed
|
* @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)) {
|
if (is_array($key)) {
|
||||||
|
/** @var array<string, string> $key */
|
||||||
foreach ($key as $k => $v) {
|
foreach ($key as $k => $v) {
|
||||||
$this->meta($k, $v);
|
$this->meta($k, $v);
|
||||||
}
|
}
|
||||||
|
|
@ -178,7 +182,7 @@ class SEOManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handle magic method calls. */
|
/** 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])) {
|
if (isset($this->extensions[$name])) {
|
||||||
return $this->extension($name, $arguments[0] ?? true);
|
return $this->extension($name, $arguments[0] ?? true);
|
||||||
|
|
@ -209,13 +213,13 @@ class SEOManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handle magic get. */
|
/** Handle magic get. */
|
||||||
public function __get(string $key)
|
public function __get(string $key): string|null
|
||||||
{
|
{
|
||||||
return $this->get(Str::snake($key, '.'));
|
return $this->get(Str::snake($key, '.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handle magic set. */
|
/** Handle magic set. */
|
||||||
public function __set(string $key, mixed $value)
|
public function __set(string $key, string $value)
|
||||||
{
|
{
|
||||||
return $this->set(Str::snake($key, '.'), $value);
|
return $this->set(Str::snake($key, '.'), $value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace ArchTech\SEO;
|
namespace ArchTech\SEO;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Blade;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use ImLiam\BladeHelper\BladeHelperServiceProvider;
|
||||||
use ImLiam\BladeHelper\Facades\BladeHelper;
|
use ImLiam\BladeHelper\Facades\BladeHelper;
|
||||||
|
|
||||||
class SEOServiceProvider extends ServiceProvider
|
class SEOServiceProvider extends ServiceProvider
|
||||||
|
|
@ -13,6 +13,7 @@ class SEOServiceProvider extends ServiceProvider
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
$this->app->singleton('seo', SEOManager::class);
|
$this->app->singleton('seo', SEOManager::class);
|
||||||
|
$this->app->register(BladeHelperServiceProvider::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
use ArchTech\SEO\SEOManager;
|
use ArchTech\SEO\SEOManager;
|
||||||
|
|
||||||
if (! function_exists('seo')) {
|
if (! function_exists('seo')) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
beforeEach(fn () => config(['services.flipp.key' => 'abc']));
|
||||||
|
|
||||||
test('flipp templates can be set', function () {
|
test('flipp templates can be set', function () {
|
||||||
seo()->flipp('blog', 'abcdefg');
|
seo()->flipp('blog', 'abcdefg');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue