Skip to content

Commit 42153f6

Browse files
author
Kirill Nesmeyanov
committed
Improve codestyle rules
1 parent e322457 commit 42153f6

File tree

3 files changed

+234
-4
lines changed

3 files changed

+234
-4
lines changed

.php-cs-fixer.php

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,232 @@
88
'@PER-CS2.0' => true,
99
'@PER-CS2.0:risky' => true,
1010
'strict_param' => true,
11+
'align_multiline_comment' => true,
1112
'array_syntax' => [
1213
'syntax' => 'short',
1314
],
15+
'backtick_to_shell_exec' => true,
16+
'binary_operator_spaces' => true,
17+
'blank_line_before_statement' => [
18+
'statements' => [
19+
'return',
20+
],
21+
],
22+
'braces_position' => [
23+
'allow_single_line_anonymous_functions' => true,
24+
'allow_single_line_empty_anonymous_classes' => true,
25+
],
26+
'class_attributes_separation' => [
27+
'elements' => [
28+
'method' => 'one',
29+
],
30+
],
31+
'class_reference_name_casing' => true,
32+
'clean_namespace' => true,
33+
'declare_parentheses' => true,
34+
'echo_tag_syntax' => true,
35+
'empty_loop_body' => ['style' => 'braces'],
36+
'empty_loop_condition' => true,
37+
'fully_qualified_strict_types' => true,
38+
'general_phpdoc_tag_rename' => [
39+
'replacements' => [
40+
'inheritDocs' => 'inheritDoc',
41+
],
42+
],
43+
'global_namespace_import' => [
44+
'import_classes' => false,
45+
'import_constants' => false,
46+
'import_functions' => false,
47+
],
48+
'include' => true,
49+
'increment_style' => true,
50+
'integer_literal_case' => true,
51+
'lambda_not_used_import' => true,
52+
'linebreak_after_opening_tag' => true,
53+
'magic_constant_casing' => true,
54+
'magic_method_casing' => true,
55+
'native_function_casing' => true,
56+
'native_type_declaration_casing' => true,
57+
'no_alias_language_construct_call' => true,
58+
'no_alternative_syntax' => true,
59+
'no_binary_string' => true,
60+
'no_blank_lines_after_phpdoc' => true,
61+
'no_empty_comment' => true,
62+
'no_empty_phpdoc' => true,
63+
'no_empty_statement' => true,
64+
'no_extra_blank_lines' => [
65+
'tokens' => [
66+
'attribute',
67+
'case',
68+
'continue',
69+
'curly_brace_block',
70+
'default',
71+
'extra',
72+
'parenthesis_brace_block',
73+
'square_brace_block',
74+
'switch',
75+
'throw',
76+
'use',
77+
],
78+
],
79+
'no_leading_namespace_whitespace' => true,
80+
'no_mixed_echo_print' => true,
81+
'no_null_property_initialization' => true,
82+
'no_short_bool_cast' => true,
83+
'no_singleline_whitespace_before_semicolons' => true,
84+
'no_spaces_around_offset' => true,
85+
'no_superfluous_phpdoc_tags' => [
86+
'allow_hidden_params' => true,
87+
'remove_inheritdoc' => true,
88+
],
89+
'no_trailing_comma_in_singleline' => true,
90+
'no_unneeded_braces' => [
91+
'namespaces' => true,
92+
],
93+
'no_unneeded_control_parentheses' => [
94+
'statements' => [
95+
'break',
96+
'clone',
97+
'continue',
98+
'echo_print',
99+
'others',
100+
'return',
101+
'switch_case',
102+
'yield',
103+
'yield_from',
104+
],
105+
],
106+
'no_unneeded_import_alias' => true,
107+
'no_unset_cast' => true,
108+
'no_unused_imports' => true,
109+
'no_useless_concat_operator' => true,
110+
'no_useless_nullsafe_operator' => true,
111+
'no_whitespace_before_comma_in_array' => true,
112+
'normalize_index_brace' => true,
113+
'nullable_type_declaration' => true,
114+
'nullable_type_declaration_for_default_null_value' => true,
115+
'object_operator_without_whitespace' => true,
116+
'operator_linebreak' => [
117+
'only_booleans' => true,
118+
],
119+
'ordered_imports' => [
120+
'imports_order' => [
121+
'class',
122+
'function',
123+
'const',
124+
],
125+
'sort_algorithm' => 'alpha',
126+
],
127+
'ordered_types' => [
128+
'null_adjustment' => 'always_last',
129+
'sort_algorithm' => 'none',
130+
],
131+
'php_unit_fqcn_annotation' => true,
132+
'php_unit_method_casing' => true,
133+
'phpdoc_align' => false,
134+
'phpdoc_annotation_without_dot' => true,
135+
'phpdoc_indent' => true,
136+
'phpdoc_inline_tag_normalizer' => true,
137+
'phpdoc_no_access' => true,
138+
'phpdoc_no_alias_tag' => false,
139+
'phpdoc_no_package' => true,
140+
'phpdoc_no_useless_inheritdoc' => true,
141+
'phpdoc_order' => [
142+
'order' => [
143+
'internal',
144+
'psalm-internal',
145+
'template',
146+
'template-extends',
147+
'extends',
148+
'template-implements',
149+
'implements',
150+
'property',
151+
'property-read',
152+
'property-write',
153+
'psalm-require-implements',
154+
'phpstan-require-implements',
155+
'psalm-require-extends',
156+
'phpstan-require-extends',
157+
'mixin',
158+
'readonly',
159+
'psalm-readonly',
160+
'phpstan-readonly',
161+
'param',
162+
'return',
163+
'throws',
164+
'api',
165+
'psalm-suppress',
166+
],
167+
],
168+
'phpdoc_return_self_reference' => true,
169+
'phpdoc_scalar' => true,
170+
'phpdoc_separation' => [
171+
'groups' => [
172+
[
173+
'property',
174+
'property-read',
175+
'property-write',
176+
],
177+
['internal', 'psalm-internal', 'phpstan-internal'],
178+
[
179+
'template',
180+
'template-extends',
181+
'extends',
182+
'template-implements',
183+
'implements',
184+
'psalm-require-implements',
185+
'phpstan-require-implements',
186+
'psalm-require-extends',
187+
'phpstan-require-extends',
188+
],
189+
['psalm-taint-sink', 'param'],
190+
['return', 'throws', 'api'],
191+
['psalm-suppress'],
192+
],
193+
],
194+
'phpdoc_single_line_var_spacing' => true,
195+
'phpdoc_tag_type' => [
196+
'tags' => [
197+
'inheritDoc' => 'inline',
198+
],
199+
],
200+
'phpdoc_to_comment' => false,
201+
'phpdoc_trim' => true,
202+
'phpdoc_trim_consecutive_blank_line_separation' => true,
203+
'phpdoc_types' => true,
204+
'phpdoc_types_order' => [
205+
'null_adjustment' => 'always_last',
206+
'sort_algorithm' => 'none',
207+
],
208+
'phpdoc_var_without_name' => true,
209+
'semicolon_after_instruction' => true,
210+
'simple_to_complex_string_variable' => true,
211+
'single_class_element_per_statement' => true,
212+
'single_import_per_statement' => true,
213+
'single_line_comment_spacing' => true,
214+
'single_line_comment_style' => [
215+
'comment_types' => [
216+
'hash',
217+
],
218+
],
219+
'single_line_throw' => false,
220+
'single_quote' => true,
221+
'space_after_semicolon' => [
222+
'remove_in_empty_for_expressions' => true,
223+
],
224+
'standardize_increment' => true,
225+
'standardize_not_equals' => true,
226+
'statement_indentation' => [
227+
'stick_comment_to_next_continuous_control_statement' => true,
228+
],
229+
'switch_continue_to_break' => true,
230+
'trailing_comma_in_multiline' => true,
231+
'trim_array_spaces' => true,
232+
'type_declaration_spaces' => true,
233+
'types_spaces' => true,
234+
'unary_operator_spaces' => true,
235+
'whitespace_after_comma_in_array' => true,
236+
'yoda_style' => false,
14237
])
15238
->setCacheFile(__DIR__ . '/vendor/.cache.php-cs-fixer')
16239
->setFinder($files);

src/PrettyPrinter.php

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

55
namespace TypeLang\Printer;
66

7-
use TypeLang\Parser\Node\Node;
87
use TypeLang\Parser\Node\Literal\LiteralNode;
8+
use TypeLang\Parser\Node\Node;
9+
use TypeLang\Parser\Node\Statement;
910
use TypeLang\Parser\Node\Stmt\Callable\ParameterNode;
1011
use TypeLang\Parser\Node\Stmt\CallableTypeNode;
1112
use TypeLang\Parser\Node\Stmt\ClassConstMaskNode;
@@ -26,7 +27,6 @@
2627
use TypeLang\Parser\Node\Stmt\Shape\FieldsListNode;
2728
use TypeLang\Parser\Node\Stmt\Shape\NamedFieldNode;
2829
use TypeLang\Parser\Node\Stmt\Shape\NumericFieldNode;
29-
use TypeLang\Parser\Node\Statement;
3030
use TypeLang\Parser\Node\Stmt\Shape\StringNamedFieldNode;
3131
use TypeLang\Parser\Node\Stmt\Template\ArgumentNode as TemplateArgumentNode;
3232
use TypeLang\Parser\Node\Stmt\Template\ArgumentsListNode as TemplateArgumentsListNode;
@@ -121,6 +121,7 @@ protected function make(Statement $stmt): string
121121

122122
/**
123123
* @param TypesListNode<TypeStatement> $node
124+
*
124125
* @return non-empty-string
125126
* @throws NonPrintableNodeException
126127
*/
@@ -165,6 +166,7 @@ protected function printCondition(Condition $node): string
165166

166167
/**
167168
* @param NullableTypeNode<TypeStatement> $node
169+
*
168170
* @return non-empty-string
169171
* @throws NonPrintableNodeException
170172
*/
@@ -191,7 +193,7 @@ protected function printClassConstMaskNode(ClassConstMaskNode $node): string
191193
{
192194
return \vsprintf('%s::%s', [
193195
$node->class->toString(),
194-
(string) ($node->constant?->toString()) . '*',
196+
(string) $node->constant?->toString() . '*',
195197
]);
196198
}
197199

@@ -308,6 +310,7 @@ protected function printCallableArgumentNode(ParameterNode $node): string
308310

309311
/**
310312
* @param UnionTypeNode<TypeStatement> $node
313+
*
311314
* @return non-empty-string
312315
*/
313316
protected function printUnionTypeNode(UnionTypeNode $node): string
@@ -327,6 +330,7 @@ protected function printUnionTypeNode(UnionTypeNode $node): string
327330

328331
/**
329332
* @param IntersectionTypeNode<TypeStatement> $node
333+
*
330334
* @return non-empty-string
331335
*/
332336
protected function printIntersectionTypeNode(IntersectionTypeNode $node): string
@@ -346,6 +350,7 @@ protected function printIntersectionTypeNode(IntersectionTypeNode $node): string
346350

347351
/**
348352
* @param LiteralNode<mixed> $node
353+
*
349354
* @return non-empty-string
350355
*/
351356
protected function printLiteralNode(LiteralNode $node): string

src/Printer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ abstract protected function make(Statement $stmt): string;
5454
/**
5555
* @param int<0, max>|null $depth
5656
*/
57-
protected function prefix(int $depth = null): string
57+
protected function prefix(?int $depth = null): string
5858
{
5959
$depth ??= $this->depth;
6060

@@ -108,7 +108,9 @@ protected function printMap(iterable $stmts): array
108108

109109
/**
110110
* @template T of TypeStatement
111+
*
111112
* @param LogicalTypeNode<T> $logical
113+
*
112114
* @return iterable<array-key, T>
113115
*/
114116
protected function unwrap(LogicalTypeNode $logical): iterable

0 commit comments

Comments
 (0)