Skip to content

Commit 320f384

Browse files
authored
Fix some cs issues and remove visitor.php from phpcs.xml.dist (#136)
* Exclude "must be overriden" from adding return never * Remove NodeDumper * Add missing `use` statement * Fix some cs issues and remove visitor.php from phpcs.xml.dist * Exclude Squiz.PHP.CommentedOutCode.Found sniff
1 parent e65d562 commit 320f384

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

finder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
return \StubsGenerator\Finder::create()
46
->in('source/wordpress')
57
// Shim for load-styles.php and load-scripts.php.
@@ -41,5 +43,4 @@
4143
//->notPath('wp-includes/theme-compat/footer.php')
4244
//->notPath('wp-includes/theme-compat/header.php')
4345
//->notPath('wp-includes/theme-compat/sidebar.php')
44-
->sortByName()
45-
;
46+
->sortByName();

functionMap.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
$httpReturnType = 'array{headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary, body: string, response: array{code: int,message: string}, cookies: array<int, \WP_HTTP_Cookie>, filename: string|null, http_response: \WP_HTTP_Requests_Response}|\WP_Error';
46

5-
if (file_exists(__DIR__ . '/source/wordpress/wp-includes/Requests/Cookie/Jar.php')) {
7+
if (file_exists(sprintf('%s/source/wordpress/wp-includes/Requests/Cookie/Jar.php', __DIR__))) {
68
$httpReturnType = 'array{headers: \Requests_Utility_CaseInsensitiveDictionary, body: string, response: array{code: int,message: string}, cookies: array<int, \WP_HTTP_Cookie>, filename: string|null, http_response: \WP_HTTP_Requests_Response}|\WP_Error';
79
}
810
$cronArgsType = 'list<mixed>';
@@ -81,11 +83,11 @@
8183
'get_attachment_taxonomies' => ["(\$output is 'names' ? array<int, string> : array<string, \WP_Taxonomy>)"],
8284
'get_taxonomies_for_attachments' => ["(\$output is 'names' ? array<int, string> : array<string, \WP_Taxonomy>)"],
8385
'get_post_stati' => ["(\$output is 'names' ? array<string, string> : array<string, \stdClass>)"],
84-
'get_comment' => ["(\$comment is \WP_Comment ? array<array-key, mixed>|\WP_Comment : array<array-key, mixed>|\WP_Comment|null) & (\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Comment|null))", 'output'=>"'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
85-
'get_post' => ["(\$post is \WP_Post ? array<array-key, mixed>|\WP_Post : array<array-key, mixed>|\WP_Post|null) & (\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Post|null))", 'output'=>"'OBJECT'|'ARRAY_A'|'ARRAY_N'" ],
86+
'get_comment' => ["(\$comment is \WP_Comment ? array<array-key, mixed>|\WP_Comment : array<array-key, mixed>|\WP_Comment|null) & (\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Comment|null))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
87+
'get_post' => ["(\$post is \WP_Post ? array<array-key, mixed>|\WP_Post : array<array-key, mixed>|\WP_Post|null) & (\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Post|null))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'" ],
8688
'get_term_by' => ["(\$output is 'ARRAY_A' ? array<string, string|int>|\WP_Error|false : (\$output is 'ARRAY_N' ? list<string|int>|\WP_Error|false : \WP_Term|\WP_Error|false))"],
8789
'get_page_by_path' => ["(\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Post|null))"],
88-
'get_term' => ["(\$output is 'ARRAY_A' ? array<string, string|int>|\WP_Error|null : (\$output is 'ARRAY_N' ? list<string|int>|\WP_Error|null : \WP_Term|\WP_Error|null))", 'output'=>"'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
90+
'get_term' => ["(\$output is 'ARRAY_A' ? array<string, string|int>|\WP_Error|null : (\$output is 'ARRAY_N' ? list<string|int>|\WP_Error|null : \WP_Term|\WP_Error|null))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
8991
'has_action' => ['($callback is false ? bool : false|int)'],
9092
'has_filter' => ['($callback is false ? bool : false|int)'],
9193
'get_permalink' => ['($post is \WP_Post ? string : string|false)'],

phpcs.xml.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
<ruleset>
33
<file>finder.php</file>
44
<file>functionMap.php</file>
5-
<file>visitor.php</file>
5+
<!-- <file>visitor.php</file> -->
66

77
<rule ref="PSR12NeutronRuleset">
88
<exclude name="Generic.Files.LineLength"/>
99
<exclude name="PEAR.Commenting.ClassComment"/>
1010
<exclude name="PEAR.Commenting.FileComment"/>
11+
<exclude name="Squiz.PHP.CommentedOutCode.Found"/>
1112
</rule>
13+
1214
</ruleset>

visitor.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PhpParser\Node\Name;
1919
use PhpParser\Node\Expr\Exit_;
2020
use PhpParser\Node\Expr\FuncCall;
21+
use PhpParser\Node\Scalar\String_;
2122
use PhpParser\Node\Stmt\Class_;
2223
use PhpParser\Node\Stmt\ClassMethod;
2324
use PhpParser\Node\Stmt\Expression;
@@ -88,7 +89,7 @@ public function format(): array
8889
'%s %s%s',
8990
$this->tag,
9091
$this->type,
91-
($this->name !== null) ? (' $' . $this->name) : ''
92+
$this->name !== null ? " \$$this->name" : ''
9293
),
9394
];
9495
}
@@ -113,7 +114,7 @@ public function format(): array
113114
return [];
114115
}
115116

116-
$name = ($this->name !== null) ? (' $' . $this->name) : '';
117+
$name = $this->name !== null ? " \$$this->name" : '';
117118

118119
if ($this->isArrayShape()) {
119120
$strings[] = sprintf(
@@ -143,7 +144,7 @@ public function format(): array
143144
$description = '';
144145

145146
if ($this->description !== null) {
146-
$description = ' ' . $this->description;
147+
$description = " $this->description";
147148
}
148149

149150
$strings[] = $this->isArrayShape()
@@ -210,10 +211,10 @@ public function format(int $level = 1): array
210211

211212
if ($this->isArrayShape()) {
212213
if ($this->name !== null) {
213-
$strings[] = $padding . '},';
214+
$strings[] = "$padding},";
214215
}
215216
} else {
216-
$strings[] = $padding . '}>,';
217+
$strings[] = "$padding}>,";
217218
}
218219
} else {
219220
$strings[] = sprintf(
@@ -624,7 +625,7 @@ static function (WordPressTag $tag) use ($matchNames): bool {
624625
}
625626

626627
/**
627-
* @return string[]
628+
* @return list<string>
628629
*/
629630
private function getAdditionalTagsFromMap(string $symbolName): array
630631
{
@@ -866,10 +867,15 @@ private static function getTypeNameFromString(string $tagVariable): ?string
866867
return null;
867868
}
868869

869-
$tagVariableType = str_replace([
870+
$tagVariableType = str_replace(
871+
[
870872
'stdClass',
871873
'\\object',
872-
], 'object', $tagVariableType);
874+
],
875+
'object',
876+
$tagVariableType
877+
);
878+
873879
$supportedTypes = [
874880
'object',
875881
'array',

0 commit comments

Comments
 (0)