Skip to content

Commit 7e00cc4

Browse files
committed
fix: php lint issues
1 parent cc5f7ec commit 7e00cc4

File tree

15 files changed

+50
-143
lines changed

15 files changed

+50
-143
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
}
7070
},
7171
"scripts": {
72-
"phpcbf": "phpcbf --parallel=4",
73-
"phpcs": "phpcs --parallel=4",
72+
"phpcbf": "phpcbf",
73+
"phpcs": "phpcs",
7474
"phplint": "parallel-lint --exclude node_modules --exclude vendor --exclude dependencies .",
7575
"phpstan": "phpstan analyze --memory-limit=-1 -v",
7676
"generate-stubs": "generate-stubs --finder=compat/stub-finder.php --out=compat/stubs.php --force",

phpstan-baseline.neon

Lines changed: 2 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -560,21 +560,6 @@ parameters:
560560
count: 1
561561
path: compat/src-deprecated/Defaults/Carrier/WebhookJson.php
562562

563-
-
564-
message: "#^Method BracketSpace\\\\Notification\\\\Utils\\\\Interfaces\\\\Cacheable\\:\\:add\\(\\) has no return type specified\\.$#"
565-
count: 1
566-
path: compat/src-deprecated/Utils/Interfaces/Cacheable.php
567-
568-
-
569-
message: "#^Method BracketSpace\\\\Notification\\\\Utils\\\\Interfaces\\\\Cacheable\\:\\:delete\\(\\) has no return type specified\\.$#"
570-
count: 1
571-
path: compat/src-deprecated/Utils/Interfaces/Cacheable.php
572-
573-
-
574-
message: "#^Method BracketSpace\\\\Notification\\\\Utils\\\\Interfaces\\\\Cacheable\\:\\:set\\(\\) has no return type specified\\.$#"
575-
count: 1
576-
path: compat/src-deprecated/Utils/Interfaces/Cacheable.php
577-
578563
-
579564
message: "#^Cannot call method getSetting\\(\\) on mixed\\.$#"
580565
count: 1
@@ -1075,11 +1060,6 @@ parameters:
10751060
count: 1
10761061
path: src/ErrorHandler.php
10771062

1078-
-
1079-
message: "#^Method BracketSpace\\\\Notification\\\\Integration\\\\WordPressEmails\\:\\:getSettingForUserRole\\(\\) is unused\\.$#"
1080-
count: 1
1081-
path: src/Integration/WordPressEmails.php
1082-
10831063
-
10841064
message: "#^Cannot access offset 'recipient' on mixed\\.$#"
10851065
count: 1
@@ -1150,26 +1130,6 @@ parameters:
11501130
count: 1
11511131
path: src/Repository/Field/CodeEditorField.php
11521132

1153-
-
1154-
message: "#^Parameter \\#1 \\$color of function sanitize_hex_color expects string, mixed given\\.$#"
1155-
count: 1
1156-
path: src/Repository/Field/ColorPickerField.php
1157-
1158-
-
1159-
message: "#^Parameter \\#1 \\$haystack of function strpos expects string, mixed given\\.$#"
1160-
count: 1
1161-
path: src/Repository/Field/ColorPickerField.php
1162-
1163-
-
1164-
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, mixed given\\.$#"
1165-
count: 1
1166-
path: src/Repository/Field/ColorPickerField.php
1167-
1168-
-
1169-
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, mixed given\\.$#"
1170-
count: 1
1171-
path: src/Repository/Field/ColorPickerField.php
1172-
11731133
-
11741134
message: "#^Method BracketSpace\\\\Notification\\\\Repository\\\\Field\\\\EditorField\\:\\:field\\(\\) should return string but returns string\\|false\\.$#"
11751135
count: 1
@@ -1180,11 +1140,6 @@ parameters:
11801140
count: 1
11811141
path: src/Repository/Field/EditorField.php
11821142

1183-
-
1184-
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, mixed given\\.$#"
1185-
count: 1
1186-
path: src/Repository/Field/EditorField.php
1187-
11881143
-
11891144
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Field\\\\EditorField\\:\\:\\$settings \\(string\\) does not accept mixed\\.$#"
11901145
count: 1
@@ -1195,23 +1150,18 @@ parameters:
11951150
count: 1
11961151
path: src/Repository/Field/ImageField.php
11971152

1198-
-
1199-
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, mixed given\\.$#"
1200-
count: 1
1201-
path: src/Repository/Field/ImageField.php
1202-
12031153
-
12041154
message: "#^Cannot cast mixed to string\\.$#"
12051155
count: 1
12061156
path: src/Repository/Field/InputField.php
12071157

12081158
-
1209-
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, mixed given\\.$#"
1159+
message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|null given\\.$#"
12101160
count: 1
12111161
path: src/Repository/Field/InputField.php
12121162

12131163
-
1214-
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Field\\\\InputField\\:\\:\\$type \\(string\\) does not accept mixed\\.$#"
1164+
message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, string\\|null given\\.$#"
12151165
count: 1
12161166
path: src/Repository/Field/InputField.php
12171167

@@ -1240,21 +1190,11 @@ parameters:
12401190
count: 1
12411191
path: src/Repository/Field/RepeaterField.php
12421192

1243-
-
1244-
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, mixed given\\.$#"
1245-
count: 1
1246-
path: src/Repository/Field/RepeaterField.php
1247-
12481193
-
12491194
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Field\\\\RepeaterField\\:\\:\\$fields \\(array\\<BracketSpace\\\\Notification\\\\Repository\\\\Field\\\\BaseField\\>\\) does not accept mixed\\.$#"
12501195
count: 1
12511196
path: src/Repository/Field/RepeaterField.php
12521197

1253-
-
1254-
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, mixed given\\.$#"
1255-
count: 1
1256-
path: src/Repository/Field/SectionRepeater.php
1257-
12581198
-
12591199
message: "#^Parameter \\#1 \\$text of function esc_html expects string, mixed given\\.$#"
12601200
count: 1
@@ -1270,11 +1210,6 @@ parameters:
12701210
count: 1
12711211
path: src/Repository/Field/SectionsField.php
12721212

1273-
-
1274-
message: "#^Parameter \\#1 \\$str of function sanitize_text_field expects string, mixed given\\.$#"
1275-
count: 1
1276-
path: src/Repository/Field/SelectField.php
1277-
12781213
-
12791214
message: "#^Parameter \\#1 \\$text of function esc_html expects string, mixed given\\.$#"
12801215
count: 1
@@ -1285,16 +1220,6 @@ parameters:
12851220
count: 1
12861221
path: src/Repository/Field/SelectField.php
12871222

1288-
-
1289-
message: "#^Parameter \\#1 \\$str of function sanitize_textarea_field expects string, mixed given\\.$#"
1290-
count: 1
1291-
path: src/Repository/Field/TextareaField.php
1292-
1293-
-
1294-
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Field\\\\TextareaField\\:\\:\\$placeholder \\(string\\) does not accept mixed\\.$#"
1295-
count: 1
1296-
path: src/Repository/Field/TextareaField.php
1297-
12981223
-
12991224
message: "#^Parameter \\#1 \\$params of class BracketSpace\\\\Notification\\\\Repository\\\\MergeTag\\\\EmailTag constructor expects array\\{slug\\?\\: string, name\\?\\: string, property_name\\?\\: string, group\\?\\: string\\|null, description\\?\\: string, example\\?\\: bool\\|string, resolver\\?\\: callable\\(\\)\\: mixed\\}, array\\{slug\\: 'admin_email', name\\: string, description\\: mixed, hidden\\: true, resolver\\: Closure\\(mixed\\)\\: mixed\\} given\\.$#"
13001225
count: 1
@@ -1340,11 +1265,6 @@ parameters:
13401265
count: 1
13411266
path: src/Repository/MergeTag/Post/ThumbnailUrl.php
13421267

1343-
-
1344-
message: "#^Parameter \\#1 \\$str of function sanitize_text_field expects string, mixed given\\.$#"
1345-
count: 1
1346-
path: src/Repository/MergeTag/StringTag.php
1347-
13481268
-
13491269
message: "#^Cannot access property \\$name on WP_Role\\|null\\.$#"
13501270
count: 1
@@ -1495,11 +1415,6 @@ parameters:
14951415
count: 1
14961416
path: src/Repository/Trigger/Privacy/DataEraseRequest.php
14971417

1498-
-
1499-
message: "#^Method BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\Privacy\\\\DataEraseRequest\\:\\:context\\(\\) has no return type specified\\.$#"
1500-
count: 1
1501-
path: src/Repository/Trigger/Privacy/DataEraseRequest.php
1502-
15031418
-
15041419
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\Privacy\\\\PrivacyTrigger\\:\\:\\$request \\(WP_User_Request\\) does not accept WP_User_Request\\|false\\.$#"
15051420
count: 1
@@ -1510,11 +1425,6 @@ parameters:
15101425
count: 1
15111426
path: src/Repository/Trigger/Privacy/DataErased.php
15121427

1513-
-
1514-
message: "#^Method BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\Privacy\\\\DataErased\\:\\:context\\(\\) has no return type specified\\.$#"
1515-
count: 1
1516-
path: src/Repository/Trigger/Privacy/DataErased.php
1517-
15181428
-
15191429
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\Privacy\\\\PrivacyTrigger\\:\\:\\$request \\(WP_User_Request\\) does not accept WP_User_Request\\|false\\.$#"
15201430
count: 1
@@ -1695,11 +1605,6 @@ parameters:
16951605
count: 1
16961606
path: src/Utils/Settings/CoreFields/Button.php
16971607

1698-
-
1699-
message: "#^Parameter \\#1 \\$data of function wp_kses_data expects string, mixed given\\.$#"
1700-
count: 1
1701-
path: src/Utils/Settings/CoreFields/Checkbox.php
1702-
17031608
-
17041609
message: "#^Parameter \\#3 \\$settings of function wp_editor expects array\\{wpautop\\?\\: bool, media_buttons\\?\\: bool, default_editor\\?\\: string, drag_drop_upload\\?\\: bool, textarea_name\\?\\: string, textarea_rows\\?\\: int, tabindex\\?\\: int\\|string, tabfocus_elements\\?\\: string, \\.\\.\\.\\}, array\\{textarea_name\\: string, editor_css\\: null, wpautop\\: mixed, media_buttons\\: mixed, textarea_rows\\: mixed, teeny\\: mixed\\} given\\.$#"
17051610
count: 1
@@ -1710,21 +1615,6 @@ parameters:
17101615
count: 1
17111616
path: src/Utils/Settings/CoreFields/Image.php
17121617

1713-
-
1714-
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, mixed given\\.$#"
1715-
count: 3
1716-
path: src/Utils/Settings/CoreFields/Number.php
1717-
1718-
-
1719-
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, mixed given\\.$#"
1720-
count: 3
1721-
path: src/Utils/Settings/CoreFields/Range.php
1722-
1723-
-
1724-
message: "#^Parameter \\#1 \\$str of function sanitize_text_field expects string, mixed given\\.$#"
1725-
count: 1
1726-
path: src/Utils/Settings/CoreFields/Select.php
1727-
17281618
-
17291619
message: "#^Property BracketSpace\\\\Notification\\\\Utils\\\\Settings\\\\Field\\:\\:\\$addons \\(string\\) does not accept mixed\\.$#"
17301620
count: 1

src/Repository/Field/ColorPickerField.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ class ColorPickerField extends BaseField
2222
*/
2323
public function field()
2424
{
25+
$value = $this->getValue();
2526
return sprintf(
2627
'<input type="text" name="%s" id="%s" value="%s" class="notification-color-picker %s" %s>',
2728
esc_attr($this->getName()),
2829
esc_attr($this->getId()),
29-
esc_attr((string)$this->getValue()),
30+
esc_attr(is_scalar($value) ? (string)$value : ''),
3031
esc_attr($this->cssClass()),
3132
$this->maybeDisable()
3233
);
@@ -40,11 +41,13 @@ public function field()
4041
*/
4142
public function sanitize($value)
4243
{
43-
if (strpos($value, 'rgba') === false) {
44-
return sanitize_hex_color($value);
44+
$stringValue = is_scalar($value) ? (string)$value : '';
45+
46+
if (strpos($stringValue, 'rgba') === false) {
47+
return sanitize_hex_color($stringValue);
4548
}
4649

47-
$color = str_replace(' ', '', $value);
50+
$color = str_replace(' ', '', $stringValue);
4851
sscanf($color, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha);
4952
return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')';
5053
}

src/Repository/Field/EditorField.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function sanitize($value)
7676
/**
7777
* Fixes WPLinkPreview TinyMCE component which adds the https:// prefix to invalid URL.
7878
*/
79-
return str_replace(['https://{', 'http://{'], '{', $value);
79+
$stringValue = is_scalar($value) ? (string)$value : '';
80+
return str_replace(['https://{', 'http://{'], '{', $stringValue);
8081
}
8182
}

src/Repository/Field/ImageField.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function field()
2727
? 'selected'
2828
: '';
2929

30+
$value = $this->getValue();
3031
return sprintf(
3132
'<div class="notification-image-field %s">
3233
<input type="text" name="%s" id="%s" value="%s" class="image-input %s" %s readonly>
@@ -39,11 +40,11 @@ public function field()
3940
esc_attr($class),
4041
esc_attr($this->getName()),
4142
esc_attr($this->getId()),
42-
esc_attr((string)$this->getValue()),
43+
esc_attr(is_scalar($value) ? (string)$value : ''),
4344
esc_attr($this->cssClass()),
4445
$this->maybeDisable(),
4546
esc_html__('Select image', 'notification'),
46-
wp_get_attachment_thumb_url($this->getValue())
47+
wp_get_attachment_thumb_url($value)
4748
);
4849
}
4950

src/Repository/Field/InputField.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ public function __construct($params = [])
8080
*/
8181
public function field()
8282
{
83+
$value = $this->getValue();
8384
return sprintf(
8485
'<input type="%s" name="%s" id="%s" value="%s" placeholder="%s" class="widefat %s" %s %s>',
8586
esc_attr($this->type),
8687
esc_attr($this->getName()),
8788
esc_attr($this->getId()),
88-
esc_attr((string)$this->getValue()),
89+
esc_attr(is_scalar($value) ? (string)$value : ''),
8990
esc_attr($this->placeholder),
9091
esc_attr($this->cssClass()),
9192
$this->maybeDisable(),
@@ -101,25 +102,27 @@ public function field()
101102
*/
102103
public function sanitize($value)
103104
{
105+
$stringValue = is_scalar($value) ? (string)$value : '';
106+
104107
// Remove script and style tags.
105-
$value = preg_replace(
108+
$stringValue = preg_replace(
106109
'@<(script|style)[^>]*?>.*?</\\1>@si',
107110
'',
108-
(string)$value
111+
$stringValue
109112
);
110113

111114
// Remove line breaks.
112115
if ($this->allowLinebreaks !== true) {
113-
$value = preg_replace(
116+
$stringValue = preg_replace(
114117
'/[\r\n\t ]+/',
115118
' ',
116-
(string)$value
119+
$stringValue
117120
);
118121
}
119122

120123
// Remove whitespace.
121-
$value = trim((string)$value);
124+
$stringValue = trim($stringValue);
122125

123-
return $value;
126+
return $stringValue;
124127
}
125128
}

src/Repository/Field/RepeaterField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function field()
118118
{
119119
$dataAttr = '';
120120
foreach ($this->dataAttr as $key => $value) {
121-
$dataAttr .= 'data-' . $key . '="' . esc_attr((string)$value) . '" ';
121+
$dataAttr .= 'data-' . $key . '="' . esc_attr(is_scalar($value) ? (string)$value : '') . '" ';
122122
}
123123

124124
$this->headers = [];

src/Repository/Field/SectionRepeater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function field()
137137
{
138138
$dataAttr = '';
139139
foreach ($this->dataAttr as $key => $value) {
140-
$dataAttr .= 'data-' . $key . '="' . esc_attr((string)$value) . '" ';
140+
$dataAttr .= 'data-' . $key . '="' . esc_attr(is_scalar($value) ? (string)$value : '') . '" ';
141141
}
142142

143143
$this->headers = [];

src/Repository/Field/SelectField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ public function field()
8484
*/
8585
public function sanitize($value)
8686
{
87-
return sanitize_text_field((string)$value);
87+
return sanitize_text_field(is_scalar($value) ? (string)$value : '');
8888
}
8989
}

src/Repository/Field/TextareaField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class TextareaField extends BaseField
4545
public function __construct($params = [])
4646
{
4747
if (isset($params['placeholder'])) {
48-
$this->placeholder = (string)$params['placeholder'];
48+
$this->placeholder = is_scalar($params['placeholder']) ? (string)$params['placeholder'] : '';
4949
}
5050

5151
if (isset($params['rows'])) {
@@ -88,6 +88,6 @@ public function field()
8888
*/
8989
public function sanitize($value)
9090
{
91-
return ($this->allowedUnfiltered) ? $value : sanitize_textarea_field((string)$value);
91+
return ($this->allowedUnfiltered) ? $value : sanitize_textarea_field(is_scalar($value) ? (string)$value : '');
9292
}
9393
}

0 commit comments

Comments
 (0)