Skip to content

Commit 1a59bad

Browse files
Release/7.1 phpstan errors (#468)
1 parent e82dd1d commit 1a59bad

60 files changed

Lines changed: 363 additions & 162 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

classes/Admin/Tooltip.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,11 @@ class Tooltip
1818

1919
private string $position = 'right';
2020

21-
public function __construct(string $id, array $args = [])
21+
public function __construct(string $id)
2222
{
2323
$this->id = $id;
2424
$this->title = __('Notice', 'codepress-admin-columns');
2525
$this->link_label = __('Instructions', 'codepress-admin-columns');
26-
27-
$this->populate($args);
28-
}
29-
30-
private function populate($args): void
31-
{
32-
foreach ($args as $key => $value) {
33-
$method = 'set_' . $key;
34-
35-
if (method_exists($this, $method)) {
36-
call_user_func([$this, $method], $value);
37-
}
38-
}
3926
}
4027

4128
public function set_id(string $id): Tooltip

classes/Admin/Type/MenuGroup.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace AC\Admin\Type;
66

7+
use LogicException;
8+
79
class MenuGroup
810
{
911
private string $name;
@@ -50,6 +52,10 @@ public function has_icon(): bool
5052

5153
public function get_icon(): string
5254
{
55+
if (null === $this->icon) {
56+
throw new LogicException('Empty icon');
57+
}
58+
5359
return $this->icon;
5460
}
5561

classes/Asset/Enqueueable.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@ public function get_handle(): string
2626

2727
protected function get_version(): ?int
2828
{
29+
if (null === $this->location) {
30+
return null;
31+
}
32+
2933
$path = $this->location->get_path();
3034

31-
return file_exists($path)
32-
? filemtime($path)
33-
: null;
35+
if (! file_exists($path)) {
36+
return null;
37+
}
38+
39+
$mtime = filemtime($path);
40+
41+
return false === $mtime ? null : $mtime;
3442
}
3543

3644
abstract public function register(): void;

classes/Column/ColumnLabelTrait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ trait ColumnLabelTrait
1010
{
1111
public function get_column_label(Column $column): string
1212
{
13-
$label = $column->get_setting('label')->get_input()->get_value();
13+
$setting = $column->get_setting('label');
14+
$label = $setting
15+
? (string)$setting->get_input()->get_value()
16+
: '';
1417

1518
if (str_contains($label, 'dashicons')) {
1619
return trim($label);

classes/ColumnSize/ListStorage.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ private function create(Column $column): ?ColumnWidth
6666
return null;
6767
}
6868

69-
$unit = (string) $column->get_setting('width_unit')->get_input()->get_value();
69+
$unit_setting = $column->get_setting('width_unit');
70+
71+
if (! $unit_setting) {
72+
return null;
73+
}
74+
75+
$unit = (string) $unit_setting->get_input()->get_value();
7076

7177
try {
7278
$width = new ColumnWidth($unit, $width);

classes/Deprecated/Hook.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AC\Deprecated;
66

77
use Closure;
8+
use LogicException;
89
use ReflectionFunction;
910

1011
class Hook
@@ -34,6 +35,10 @@ public function get_version(): string
3435

3536
public function get_replacement(): string
3637
{
38+
if (null === $this->replacement) {
39+
throw new LogicException('Empty replacement');
40+
}
41+
3742
return $this->replacement;
3843
}
3944

@@ -49,7 +54,7 @@ public function has_hook(): bool
4954

5055
public function usage_count(): int
5156
{
52-
return count($this->get_callbacks());
57+
return count($this->get_callbacks() ?? []);
5358
}
5459

5560
private function get_filter_callbacks(): array

classes/Entity/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function get_url(): string
5454
return $this->url;
5555
}
5656

57-
public function get_location(): Location
57+
public function get_location(): Location\Absolute
5858
{
5959
return new Location\Absolute($this->url, $this->dir);
6060
}

classes/Form/Element/Checkbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function get_elements(): ?array
6262
$value = (array)$this->get_value();
6363

6464
foreach ($options as $key => $label) {
65-
$input = new Input($this->get_name());
65+
$input = new Input((string)$this->get_name());
6666

6767
$input
6868
->set_value($key)

classes/Formatter/ConditionalValue.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace AC\Formatter;
66

7+
use AC\Exception\ValueNotFoundException;
78
use AC\Formatter;
89
use AC\Type\Value;
910

@@ -25,7 +26,13 @@ public function format(Value $value): Value
2526
return $value;
2627
}
2728

28-
return $this->formatter->format($value);
29+
$formatted = $this->formatter->format($value);
30+
31+
if (! $formatted instanceof Value) {
32+
throw ValueNotFoundException::from_id($value->get_id());
33+
}
34+
35+
return $formatted;
2936
}
3037

3138
}

classes/Formatter/ExplodeToCollection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use AC\Exception\ValueNotFoundException;
88
use AC\Type\Value;
99
use AC\Type\ValueCollection;
10+
use InvalidArgumentException;
1011

1112
final class ExplodeToCollection extends ArrayToCollection
1213
{
@@ -16,14 +17,18 @@ public function __construct(string $separator)
1617
{
1718
parent::__construct();
1819

20+
if ('' === $separator) {
21+
throw new InvalidArgumentException('Separator can not be empty.');
22+
}
23+
1924
$this->separator = $separator;
2025
}
2126

2227
public function format(Value $value): ValueCollection
2328
{
2429
$result = explode($this->separator, (string)$value);
2530

26-
if (false === $result || $result === ['']) {
31+
if ($result === ['']) {
2732
throw new ValueNotFoundException('No values found');
2833
}
2934

0 commit comments

Comments
 (0)