diff --git a/README.md b/README.md
index 71a7b1a..de652c4 100644
--- a/README.md
+++ b/README.md
@@ -140,8 +140,8 @@ To add more tags to the document head, you can use the `tag()` and `rawTag()` me
```php
seo()->tag('fb:image', asset('foo'));
-seo()->rawTag('');
-seo()->rawTag('fb_url', ''); // Keyed, allows overrides later on
+seo()->rawTag('');
+seo()->rawTag('fb_url', ''); // Keyed, allows overrides later on
```
### Canonical URL
diff --git a/resources/views/components/extensions/twitter.blade.php b/resources/views/components/extensions/twitter.blade.php
index 661ddb4..2adcf5a 100644
--- a/resources/views/components/extensions/twitter.blade.php
+++ b/resources/views/components/extensions/twitter.blade.php
@@ -1,6 +1,6 @@
-@if(seo('twitter.creator')) @endif
-@if(seo('twitter.site')) @endif
-@if(seo('twitter.title')) @endif
-@if(seo('twitter.description')) @endif
-@if(seo('twitter.image')) @endif
+@if(seo('twitter.creator')) @endif
+@if(seo('twitter.site')) @endif
+@if(seo('twitter.title')) @endif
+@if(seo('twitter.description')) @endif
+@if(seo('twitter.image')) @endif
diff --git a/resources/views/components/meta.blade.php b/resources/views/components/meta.blade.php
index ed5d44f..0be1bdb 100644
--- a/resources/views/components/meta.blade.php
+++ b/resources/views/components/meta.blade.php
@@ -3,34 +3,34 @@
@unless(seo()->hasTag('og:title'))
{{-- If an og:title tag is provided directly, it's included in the @foreach below --}}
-
+
@endunless
@endif
@if(seo('description'))
-
-
+
+
@endif
@if(seo('keywords'))
-
+
@endif
@if(seo('type'))
-
+
@else
-
+
@endif
-@if(seo('site')) @endif
+@if(seo('site')) @endif
-@if(seo('locale')) @endif
+@if(seo('locale')) @endif
-@if(seo('image')) @endif
+@if(seo('image')) @endif
@if(seo('url'))
-
-
+
+
@endif
@foreach(seo()->tags() as $tag)
diff --git a/src/SEOManager.php b/src/SEOManager.php
index 1837d9d..58a4c85 100644
--- a/src/SEOManager.php
+++ b/src/SEOManager.php
@@ -9,20 +9,20 @@ use Illuminate\Support\Arr;
use Illuminate\Support\Str;
/**
- * @method $this title(string $title = null, ...$args) Set the title.
- * @method $this description(string $description = null, ...$args) Set the description.
- * @method $this keywords(string $keywords = null, ...$args) Set the keywords.
- * @method $this url(string $url = null, ...$args) Set the canonical URL.
- * @method $this site(string $site = null, ...$args) Set the site name.
- * @method $this image(string $url = null, ...$args) Set the cover image.
- * @method $this type(string $type = null, ...$args) Set the page type.
- * @method $this locale(string $locale = null, ...$args) Set the page locale.
+ * @method $this title(?string $title = null, ...$args) Set the title.
+ * @method $this description(?string $description = null, ...$args) Set the description.
+ * @method $this keywords(?string $keywords = null, ...$args) Set the keywords.
+ * @method $this url(?string $url = null, ...$args) Set the canonical URL.
+ * @method $this site(?string $site = null, ...$args) Set the site name.
+ * @method $this image(?string $url = null, ...$args) Set the cover image.
+ * @method $this type(?string $type = null, ...$args) Set the page type.
+ * @method $this locale(?string $locale = null, ...$args) Set the page locale.
* @method $this twitter(bool $enabled = true, ...$args) Enable the Twitter extension.
- * @method $this twitterCreator(string $username = null, ...$args) Set the Twitter author.
- * @method $this twitterSite(string $username = null, ...$args) Set the Twitter author.
- * @method $this twitterTitle(string $title = null, ...$args) Set the Twitter title.
- * @method $this twitterDescription(string $description = null, ...$args) Set the Twitter description.
- * @method $this twitterImage(string $url = null, ...$args) Set the Twitter cover image.
+ * @method $this twitterCreator(?string $username = null, ...$args) Set the Twitter author.
+ * @method $this twitterSite(?string $username = null, ...$args) Set the Twitter author.
+ * @method $this twitterTitle(?string $title = null, ...$args) Set the Twitter title.
+ * @method $this twitterDescription(?string $description = null, ...$args) Set the Twitter description.
+ * @method $this twitterImage(?string $url = null, ...$args) Set the Twitter cover image.
*/
class SEOManager
{
@@ -135,7 +135,7 @@ class SEOManager
}
/** Configure an extension. */
- public function extension(string $name, bool $enabled = true, string $view = null): static
+ public function extension(string $name, bool $enabled = true, ?string $view = null): static
{
$this->extensions[$name] = $enabled;
@@ -159,7 +159,7 @@ class SEOManager
}
/** Configure or use Flipp. */
- public function flipp(string $alias, string|array $data = null): string|static
+ public function flipp(string $alias, string|array|null $data = null): string|static
{
if (is_string($data)) {
$this->meta("flipp.templates.$alias", $data);
@@ -185,7 +185,7 @@ class SEOManager
}
/** Configure or use Previewify. */
- public function previewify(string $alias, int|string|array $data = null): string|static
+ public function previewify(string $alias, int|string|array|null $data = null): string|static
{
if (is_string($data) || is_int($data)) {
$this->meta("previewify.templates.$alias", (string) $data);
@@ -254,7 +254,7 @@ class SEOManager
}
/** Add a head tag. */
- public function rawTag(string $key, string $tag = null): static
+ public function rawTag(string $key, ?string $tag = null): static
{
$tag ??= $key;
@@ -268,7 +268,7 @@ class SEOManager
{
$content = e($content);
- $this->rawTag("meta.{$property}", "");
+ $this->rawTag("meta.{$property}", "");
return $this;
}
@@ -279,7 +279,7 @@ class SEOManager
* @param string|array|null $value The value (if a single key is provided).
* @return $this|string|null
*/
- public function meta(string|array $key, string|array $value = null): mixed
+ public function meta(string|array $key, string|array|null $value = null): mixed
{
if (is_array($key)) {
/** @var array $key */
diff --git a/src/helpers.php b/src/helpers.php
index d891180..9ab7dd3 100644
--- a/src/helpers.php
+++ b/src/helpers.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
use ArchTech\SEO\SEOManager;
if (! function_exists('seo')) {
- function seo(string|array $key = null): SEOManager|string|array|null
+ function seo(string|array|null $key = null): SEOManager|string|array|null
{
if ($key === null) {
return app('seo');
diff --git a/tests/Pest/ExtensionTest.php b/tests/Pest/ExtensionTest.php
index caefdba..22be51a 100644
--- a/tests/Pest/ExtensionTest.php
+++ b/tests/Pest/ExtensionTest.php
@@ -40,7 +40,7 @@ test('extensions can use custom blade paths', function () {
seo()->facebookTitle('abc');
- expect(meta())->toContain('');
+ expect(meta())->toContain('');
});
test('twitter falls back to the default values', function () {
@@ -56,7 +56,7 @@ test('twitter falls back to the default values', function () {
expect(seo('twitter.description'))->toBe('bar');
expect(seo('description'))->toBe('baz');
- expect(meta())->toContain('');
+ expect(meta())->toContain('');
});
test('extensions are automatically enabled when values for them are set', function () {
diff --git a/tests/Pest/ManagerTest.php b/tests/Pest/ManagerTest.php
index ea621f3..7b8dc3c 100644
--- a/tests/Pest/ManagerTest.php
+++ b/tests/Pest/ManagerTest.php
@@ -86,7 +86,7 @@ test('setting the defaults returns the manager instance', function () {
test('meta tags can be added to the template', function () {
seo()->tag('fb:image', 'foo');
- expect(meta())->toContain('');
+ expect(meta())->toContain('');
});
test('raw tags can be added to the template', function () {
@@ -114,8 +114,8 @@ test('canonical url can be read from request', function () {
seo()->withUrl();
expect(meta())
- ->toContain('')
- ->toContain('');
+ ->toContain('')
+ ->toContain('');
});
test('canonical url accepts origin', function () {
@@ -134,8 +134,8 @@ test('canonical url can be changed', function () {
seo()->url('http://foo.com/bar');
expect(meta())
- ->toContain('')
- ->toContain('');
+ ->toContain('')
+ ->toContain('');
});
test('og:title can be overridden using a tag', function () {
@@ -144,16 +144,16 @@ test('og:title can be overridden using a tag', function () {
expect(meta())
->toContain('foo')
- ->toContain('');
+ ->toContain('');
});
test('type can be overridden using the type method', function () {
- expect(meta())->toContain(''); // default
+ expect(meta())->toContain(''); // default
seo()->type('foo');
expect(meta())
- ->toContain('') // overridden
+ ->toContain('') // overridden
->not()->toContain('website');
});
@@ -165,5 +165,5 @@ test('og:locale is not included by default', function () {
test('og:locale can be added to the template', function () {
seo()->locale('de_DE');
- expect(meta())->toContain('');
+ expect(meta())->toContain('');
});
diff --git a/tests/Pest/SanitizationTest.php b/tests/Pest/SanitizationTest.php
index b1daa82..b2b420f 100644
--- a/tests/Pest/SanitizationTest.php
+++ b/tests/Pest/SanitizationTest.php
@@ -13,8 +13,8 @@ test('opengraph methods properly sanitize input', function (string $method, stri
expect($meta)->not()->toContain('content="Testing string " with several \' XSS characters " . \' ."');
expect($meta)->not()->toContain("content=\"{$unsanitizedContent}\"");
- expect($meta)->toContain("");
- expect($meta)->toContain("");
+ expect($meta)->toContain("");
+ expect($meta)->toContain("");
})->with([
['site', 'og:site_name'],
['url', 'og:url'],
@@ -37,8 +37,8 @@ test('the twitter extension properly sanitizes input', function (string $method,
expect($meta)->not()->toContain('content="Testing string " with several \' XSS characters " . \' ."');
expect($meta)->not()->toContain("content=\"{$unsanitizedContent}\"");
- expect($meta)->toContain("");
- expect($meta)->toContain("");
+ expect($meta)->toContain("");
+ expect($meta)->toContain("");
})->with([
['twitterCreator', 'twitter:creator'],
['twitterSite', 'twitter:site'],
@@ -65,8 +65,8 @@ test('the title method properly sanitizes both tags', function () {
expect($meta)->toContain("{$sanitizedContent}");
expect($meta)->toContain("Testing string " with several ' XSS characters </title> " . ' .");
- expect($meta)->toContain("");
- expect($meta)->toContain("");
+ expect($meta)->toContain("");
+ expect($meta)->toContain("");
});
test('seo blade directive calls are sanitized', function () {
diff --git a/tests/views/components/facebook.blade.php b/tests/views/components/facebook.blade.php
index 170548c..0333ed2 100644
--- a/tests/views/components/facebook.blade.php
+++ b/tests/views/components/facebook.blade.php
@@ -1 +1 @@
-
+