Skip to content

Commit

Permalink
Fix some PHPStan errors (#12)
Browse files Browse the repository at this point in the history
* Fix some PHPStan errors

* Fix return type of SEOManager::meta

* Fix CS

* Update SEOManager.php

* Update helpers.php

* Update SEOManager.php
  • Loading branch information
szepeviktor authored Nov 16, 2021
1 parent 7b24a50 commit 20f55c3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"imliam/laravel-blade-helper": "^1.0"
},
"require-dev": {
"orchestra/testbench": "^6.9",
"nunomaduro/larastan": "^0.6.10",
"orchestra/testbench": "^6.23",
"nunomaduro/larastan": "^1.0",
"pestphp/pest": "^1.2",
"pestphp/pest-plugin-laravel": "^1.0",
"intervention/image": "^2.7"
Expand Down
10 changes: 4 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ parameters:
universalObjectCratesClasses:
- Illuminate\Routing\Route
- ArchTech\SEO\SEOManager
checkMissingIterableValueType: false

ignoreErrors:
- '#SEOManager\|array\|string\|null#'
- '#string\|false given#'
- '#flipp\(\) should return#'
- '#\_\_set\(\) has no return typehint specified#'

checkMissingIterableValueType: false
# Waiting for https://github.com/phpstan/phpstan/issues/5706
- '#^Cannot call method (flipp|get|set)\(\) on ArchTech\\SEO\\SEOManager\|array\|string\|null\.$#'
- '#^Method ArchTech\\SEO\\SEOManager::flipp\(\) should return static\(ArchTech\\SEO\\SEOManager\)\|string but returns array\|string\|null\.$#'
17 changes: 12 additions & 5 deletions src/SEOManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ protected function modify(string $key): string|null
: value($this->values[$key]);
}

/** Set one or more values. */
/**
* Set one or more values.
*
* @param string|array<string, string> $key
*/
public function set(string|array $key, string|Closure|null $value = null): string|array|null
{
if (is_array($key)) {
/** @var array<string, string> $key */
foreach ($key as $k => $v) {
$this->set($k, $v);
}
Expand Down Expand Up @@ -166,7 +169,7 @@ public function flipp(string $alias, string|array $data = null): string|static
];
}

$query = base64_encode(json_encode($data));
$query = base64_encode(json_encode($data, JSON_THROW_ON_ERROR));

/** @var string $template */
$template = $this->meta("flipp.templates.$alias");
Expand Down Expand Up @@ -220,7 +223,7 @@ public function tag(string $property, string $content): static
* Get or set metadata.
* @param string|array $key The key or key-value pair being set.
* @param string|array|null $value The value (if a single key is provided).
* @return $this|string
* @return $this|string|null
*/
public function meta(string|array $key, string|array $value = null): mixed
{
Expand Down Expand Up @@ -281,7 +284,11 @@ public function __get(string $key): string|null
return $this->get(Str::snake($key, '.'));
}

/** Handle magic set. */
/**
* Handle magic set.
*
* @return string|array|null
*/
public function __set(string $key, string $value)
{
return $this->set(Str::snake($key, '.'), $value);
Expand Down

0 comments on commit 20f55c3

Please sign in to comment.