Skip to content

Commit 5029e81

Browse files
committed
Update coding style
1 parent c5527ba commit 5029e81

File tree

151 files changed

+963
-1034
lines changed

Some content is hidden

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

151 files changed

+963
-1034
lines changed

.php-cs-fixer.dist.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
'braces' => true,
2323
'cast_spaces' => true,
2424
'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one']], // const are often grouped with other related const
25-
'class_definition' => false,
26-
'class_keyword_remove' => false, // ::class keyword gives us better support in IDE
25+
'class_definition' => false, // phpcs disagree
26+
'class_keyword_remove' => false, // Deprecated, and ::class keyword gives us better support in IDE
2727
'combine_consecutive_issets' => true,
2828
'combine_consecutive_unsets' => true,
2929
'combine_nested_dirname' => true,
@@ -40,15 +40,17 @@
4040
'doctrine_annotation_indentation' => true,
4141
'doctrine_annotation_spaces' => true,
4242
'elseif' => true,
43+
'empty_loop_body' => true,
44+
'empty_loop_condition' => true,
4345
'encoding' => true,
4446
'ereg_to_preg' => true,
47+
'error_suppression' => false, // it breaks \PhpOffice\PhpSpreadsheet\Helper\Handler
4548
'escape_implicit_backslashes' => true,
4649
'explicit_indirect_variable' => false, // I feel it makes the code actually harder to read
4750
'explicit_string_variable' => false, // I feel it makes the code actually harder to read
4851
'final_class' => false, // We need non-final classes
4952
'final_internal_class' => true,
5053
'final_public_method_for_abstract_class' => false, // We need non-final methods
51-
'self_static_accessor' => true,
5254
'fopen_flag_order' => true,
5355
'fopen_flags' => true,
5456
'full_opening_tag' => true,
@@ -57,15 +59,19 @@
5759
'function_to_constant' => true,
5860
'function_typehint_space' => true,
5961
'general_phpdoc_annotation_remove' => ['annotations' => ['access', 'category', 'copyright']],
62+
'general_phpdoc_tag_rename' => true,
6063
'global_namespace_import' => true,
64+
'group_import' => false, // I feel it makes the code actually harder to read
6165
'header_comment' => false, // We don't use common header in all our files
6266
'heredoc_indentation' => true,
6367
'heredoc_to_nowdoc' => false, // Not sure about this one
6468
'implode_call' => true,
6569
'include' => true,
6670
'increment_style' => true,
6771
'indentation_type' => true,
72+
'integer_literal_case' => true,
6873
'is_null' => true,
74+
'lambda_not_used_import' => true,
6975
'line_ending' => true,
7076
'linebreak_after_opening_tag' => true,
7177
'list_syntax' => ['syntax' => 'short'],
@@ -78,6 +84,7 @@
7884
'mb_str_functions' => false, // No, too dangerous to change that
7985
'method_argument_space' => true,
8086
'method_chaining_indentation' => true,
87+
'modernize_strpos' => true,
8188
'modernize_types_casting' => true,
8289
'multiline_comment_opening_closing' => true,
8390
'multiline_whitespace_before_semicolons' => true,
@@ -87,6 +94,7 @@
8794
'native_function_type_declaration_casing' => true,
8895
'new_with_braces' => true,
8996
'no_alias_functions' => true,
97+
'no_alias_language_construct_call' => true,
9098
'no_alternative_syntax' => true,
9199
'no_binary_string' => true,
92100
'no_blank_lines_after_class_opening' => true,
@@ -108,6 +116,7 @@
108116
'no_short_bool_cast' => true,
109117
'echo_tag_syntax' => ['format' => 'long'],
110118
'no_singleline_whitespace_before_semicolons' => true,
119+
'no_space_around_double_colon' => true,
111120
'no_spaces_after_function_name' => true,
112121
'no_spaces_around_offset' => true,
113122
'no_spaces_inside_parenthesis' => true,
@@ -117,6 +126,7 @@
117126
'no_trailing_comma_in_singleline_array' => true,
118127
'no_trailing_whitespace' => true,
119128
'no_trailing_whitespace_in_comment' => true,
129+
'no_trailing_whitespace_in_string' => false, // Too dangerous
120130
'no_unneeded_control_parentheses' => true,
121131
'no_unneeded_curly_braces' => true,
122132
'no_unneeded_final_method' => true,
@@ -126,6 +136,7 @@
126136
'no_unused_imports' => true,
127137
'no_useless_else' => true,
128138
'no_useless_return' => true,
139+
'no_useless_sprintf' => true,
129140
'no_whitespace_before_comma_in_array' => true,
130141
'no_whitespace_in_blank_line' => true,
131142
'non_printable_character' => true,
@@ -135,9 +146,11 @@
135146
'nullable_type_declaration_for_default_null_value' => true,
136147
'object_operator_without_whitespace' => true,
137148
'octal_notation' => true,
149+
'operator_linebreak' => true,
138150
'ordered_class_elements' => false, // We prefer to keep some freedom
139151
'ordered_imports' => true,
140152
'ordered_interfaces' => true,
153+
'ordered_traits' => true,
141154
'php_unit_construct' => true,
142155
'php_unit_dedicate_assert' => true,
143156
'php_unit_dedicate_assert_internal_type' => true,
@@ -173,9 +186,12 @@
173186
'phpdoc_separation' => true,
174187
'phpdoc_single_line_var_spacing' => true,
175188
'phpdoc_summary' => true,
189+
'phpdoc_tag_casing' => true,
190+
'phpdoc_tag_type' => true,
176191
'phpdoc_to_comment' => false, // interferes with annotations
177192
'phpdoc_to_param_type' => false, // Because experimental, but interesting for one shot use
178-
'phpdoc_to_return_type' => false, // idem
193+
'phpdoc_to_property_type' => false, // Because experimental, but interesting for one shot use
194+
'phpdoc_to_return_type' => false, // Because experimental, but interesting for one shot use
179195
'phpdoc_trim' => true,
180196
'phpdoc_trim_consecutive_blank_line_separation' => true,
181197
'phpdoc_types' => true,
@@ -184,8 +200,7 @@
184200
'phpdoc_var_without_name' => true,
185201
'pow_to_exponentiation' => true,
186202
'protected_to_private' => true,
187-
//'psr0' => true,
188-
//'psr4' => true,
203+
'psr_autoloading' => true,
189204
'random_api_migration' => true,
190205
'return_assignment' => false, // Sometimes useful for clarity or debug
191206
'return_type_declaration' => true,
@@ -195,6 +210,7 @@
195210
'set_type_to_cast' => true,
196211
'short_scalar_cast' => true,
197212
'simple_to_complex_string_variable' => false, // Would differ from TypeScript without obvious advantages
213+
'simplified_if_return' => false, // Even if technically correct we prefer to be explicit
198214
'simplified_null_return' => false, // Even if technically correct we prefer to be explicit
199215
'single_blank_line_at_eof' => true,
200216
'single_blank_line_before_namespace' => true,
@@ -204,21 +220,27 @@
204220
'single_line_comment_style' => true,
205221
'single_line_throw' => false, // I don't see any reason for having a special case for Exception
206222
'single_quote' => true,
223+
'single_space_after_construct' => true,
207224
'single_trait_insert_per_statement' => true,
208225
'space_after_semicolon' => true,
209226
'standardize_increment' => true,
210227
'standardize_not_equals' => true,
211228
'static_lambda' => false, // Risky if we can't guarantee nobody use `bindTo()`
212229
'strict_comparison' => false, // No, too dangerous to change that
213230
'strict_param' => false, // No, too dangerous to change that
231+
'string_length_to_empty' => true,
214232
'string_line_ending' => true,
215233
'switch_case_semicolon_to_colon' => true,
216234
'switch_case_space' => true,
235+
'switch_continue_to_break' => true,
217236
'ternary_operator_spaces' => true,
237+
'ternary_to_elvis_operator' => true,
218238
'ternary_to_null_coalescing' => true,
219239
'trailing_comma_in_multiline' => true,
220240
'trim_array_spaces' => true,
241+
'types_spaces' => true,
221242
'unary_operator_spaces' => true,
243+
'use_arrow_functions' => true,
222244
'visibility_required' => ['elements' => ['property', 'method']], // not const
223245
'void_return' => true,
224246
'whitespace_after_comma_in_array' => true,

infra/LocaleGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ protected function getLocaleFolder(string $locale): string
208208
{
209209
$lastchar = substr($this->translationBaseFolder, -1);
210210
$dirsep = ($lastchar === '/' || $lastchar === '\\') ? '' : DIRECTORY_SEPARATOR;
211-
$localeFolder = $this->translationBaseFolder .
212-
$dirsep .
213-
str_replace('_', DIRECTORY_SEPARATOR, $locale);
211+
$localeFolder = $this->translationBaseFolder
212+
. $dirsep
213+
. str_replace('_', DIRECTORY_SEPARATOR, $locale);
214214
if (!file_exists($localeFolder) || !is_dir($localeFolder)) {
215215
mkdir($localeFolder, 7 * 64 + 7 * 8 + 7, true); // octal 777
216216
}

samples/Basic/13_Calculation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@
158158
for ($col = 'B'; $col != 'G'; ++$col) {
159159
for ($row = 14; $row <= 41; ++$row) {
160160
if (
161-
(($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue()) !== null) &&
162-
($formula[0] == '=')
161+
(($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue()) !== null)
162+
&& ($formula[0] == '=')
163163
) {
164164
$helper->log('Value of ' . $col . $row . ' [' . $formula . ']: ' . $spreadsheet->getActiveSheet()->getCell($col . $row)->getCalculatedValue());
165165
}

samples/Basic/13_CalculationCyclicFormulae.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
for ($row = 1; $row <= 2; ++$row) {
2424
for ($col = 'A'; $col != 'C'; ++$col) {
2525
if (
26-
(($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue()) !== null) &&
27-
($formula[0] == '=')
26+
(($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue()) !== null)
27+
&& ($formula[0] == '=')
2828
) {
2929
$helper->log('Value of ' . $col . $row . ' [' . $formula . ']: ' . $spreadsheet->getActiveSheet()->getCell($col . $row)->getCalculatedValue());
3030
}

samples/Basic/25_In_memory_image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
$helper->log('Generate an image');
3030
$gdImage = @imagecreatetruecolor(120, 20);
3131
if (!$gdImage) {
32-
die('Cannot Initialize new GD image stream');
32+
exit('Cannot Initialize new GD image stream');
3333
}
3434

3535
$textColor = imagecolorallocate($gdImage, 255, 255, 255);

samples/Wizards/NumberFormat/Accounting.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
if (isset($_POST['submit'])) {
8484
if (!is_numeric($_POST['number'])) {
8585
$helper->log('The Sample Number Value must be numeric');
86-
} elseif (!is_numeric($_POST['decimals']) || strpos($_POST['decimals'], '.') !== false || (int) $_POST['decimals'] < 0) {
86+
} elseif (!is_numeric($_POST['decimals']) || str_contains($_POST['decimals'], '.') || (int) $_POST['decimals'] < 0) {
8787
$helper->log('The Decimal Places value must be positive integer');
8888
} else {
8989
try {
@@ -93,11 +93,11 @@
9393
$helper->log('<hr /><b>Code:</b><br />');
9494
$helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
9595
$helper->log(
96-
"\$mask = Wizard\\Accounting('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::" .
97-
(isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR') .
98-
', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL') .
99-
', Wizard\Currency::' . (((bool) $_POST['spacing']) ? 'SYMBOL_WITH_SPACING' : 'SYMBOL_WITHOUT_SPACING') .
100-
');<br />'
96+
"\$mask = Wizard\\Accounting('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::"
97+
. (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR')
98+
. ', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL')
99+
. ', Wizard\Currency::' . (((bool) $_POST['spacing']) ? 'SYMBOL_WITH_SPACING' : 'SYMBOL_WITHOUT_SPACING')
100+
. ');<br />'
101101
);
102102
$helper->log('echo (string) $mask;');
103103
$helper->log('<hr /><b>Mask:</b><br />');

samples/Wizards/NumberFormat/Currency.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
if (isset($_POST['submit'])) {
8484
if (!is_numeric($_POST['number'])) {
8585
$helper->log('The Sample Number Value must be numeric');
86-
} elseif (!is_numeric($_POST['decimals']) || strpos($_POST['decimals'], '.') !== false || (int) $_POST['decimals'] < 0) {
86+
} elseif (!is_numeric($_POST['decimals']) || str_contains($_POST['decimals'], '.') || (int) $_POST['decimals'] < 0) {
8787
$helper->log('The Decimal Places value must be positive integer');
8888
} else {
8989
try {
@@ -93,11 +93,11 @@
9393
$helper->log('<hr /><b>Code:</b><br />');
9494
$helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
9595
$helper->log(
96-
"\$mask = Wizard\\Currency('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::" .
97-
(isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR') .
98-
', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL') .
99-
', Wizard\Currency::' . (((bool) $_POST['spacing']) ? 'SYMBOL_WITH_SPACING' : 'SYMBOL_WITHOUT_SPACING') .
100-
');<br />'
96+
"\$mask = Wizard\\Currency('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::"
97+
. (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR')
98+
. ', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL')
99+
. ', Wizard\Currency::' . (((bool) $_POST['spacing']) ? 'SYMBOL_WITH_SPACING' : 'SYMBOL_WITHOUT_SPACING')
100+
. ');<br />'
101101
);
102102
$helper->log('echo (string) $mask;');
103103
$helper->log('<hr /><b>Mask:</b><br />');

samples/Wizards/NumberFormat/Number.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
if (isset($_POST['submit'])) {
5050
if (!is_numeric($_POST['number'])) {
5151
$helper->log('The Sample Number Value must be numeric');
52-
} elseif (!is_numeric($_POST['decimals']) || strpos($_POST['decimals'], '.') !== false || (int) $_POST['decimals'] < 0) {
52+
} elseif (!is_numeric($_POST['decimals']) || str_contains($_POST['decimals'], '.') || (int) $_POST['decimals'] < 0) {
5353
$helper->log('The Decimal Places value must be positive integer');
5454
} else {
5555
try {
@@ -59,9 +59,9 @@
5959
$helper->log('<hr /><b>Code:</b><br />');
6060
$helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
6161
$helper->log(
62-
"\$mask = Wizard\\Number({$_POST['decimals']}, Wizard\\Number::" .
63-
(isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR') .
64-
');<br />'
62+
"\$mask = Wizard\\Number({$_POST['decimals']}, Wizard\\Number::"
63+
. (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR')
64+
. ');<br />'
6565
);
6666
$helper->log('echo (string) $mask;');
6767
$helper->log('<hr /><b>Mask:</b>');

samples/Wizards/NumberFormat/Percentage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
if (isset($_POST['submit'])) {
4444
if (!is_numeric($_POST['number'])) {
4545
$helper->log('The Sample Number Value must be numeric');
46-
} elseif (!is_numeric($_POST['decimals']) || strpos($_POST['decimals'], '.') !== false || (int) $_POST['decimals'] < 0) {
46+
} elseif (!is_numeric($_POST['decimals']) || str_contains($_POST['decimals'], '.') || (int) $_POST['decimals'] < 0) {
4747
$helper->log('The Decimal Places value must be positive integer');
4848
} else {
4949
try {

samples/Wizards/NumberFormat/Scientific.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
if (isset($_POST['submit'])) {
4444
if (!is_numeric($_POST['number'])) {
4545
$helper->log('The Sample Number Value must be numeric');
46-
} elseif (!is_numeric($_POST['decimals']) || strpos($_POST['decimals'], '.') !== false || (int) $_POST['decimals'] < 0) {
46+
} elseif (!is_numeric($_POST['decimals']) || str_contains($_POST['decimals'], '.') || (int) $_POST['decimals'] < 0) {
4747
$helper->log('The Decimal Places value must be positive integer');
4848
} else {
4949
try {

0 commit comments

Comments
 (0)