Skip to content

Commit c089a9c

Browse files
committed
Apply php-cs-fixer
1 parent 54ca304 commit c089a9c

File tree

11 files changed

+237
-48
lines changed

11 files changed

+237
-48
lines changed

.php-cs-fixer.php

Lines changed: 210 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
use PhpCsFixer\Config;
1414
use PhpCsFixer\Finder;
1515

16-
$header = <<<EOF
17-
This file is part of the guanguans/laravel-code-runner.
16+
$header = <<<'header'
17+
This file is part of the guanguans/laravel-code-runner.
1818
19-
(c) guanguans <ityaozm@gmail.com>
19+
(c) guanguans <ityaozm@gmail.com>
2020
21-
This source file is subject to the MIT license that is bundled.
22-
EOF;
21+
This source file is subject to the MIT license that is bundled.
22+
header;
2323

2424
/** @noinspection PhpParamsInspection */
2525
$finder = Finder::create()
@@ -33,6 +33,7 @@
3333
->append([
3434
__DIR__.'/.php-cs-fixer.php',
3535
__DIR__.'/rector.php',
36+
__DIR__.'/tests.php',
3637
])
3738
->exclude([
3839
'.github/',
@@ -52,43 +53,218 @@
5253
->ignoreVCS(true);
5354

5455
return (new Config())
56+
->setFinder($finder)
57+
->setRiskyAllowed(true)
58+
->setUsingCache(false)
59+
->setCacheFile(__DIR__.'/build/.php-cs-fixer.cache')
5560
->setRules([
56-
'@DoctrineAnnotation' => true,
57-
'@PHP80Migration:risky' => true,
61+
// '@PHP70Migration' => true,
62+
// '@PHP70Migration:risky' => true,
63+
// '@PHP71Migration' => true,
64+
// '@PHP71Migration:risky' => true,
65+
// '@PHP73Migration' => true,
66+
'@PHP74Migration' => true,
67+
'@PHP74Migration:risky' => true,
68+
// '@PHP80Migration' => true,
69+
// '@PHP80Migration:risky' => true,
70+
// '@PHP81Migration' => true,
71+
// '@PHP82Migration' => true,
72+
73+
// '@PHPUnit75Migration:risky' => true,
5874
'@PHPUnit84Migration:risky' => true,
59-
'@PSR12:risky' => true,
60-
'@Symfony' => true,
75+
// '@PHPUnit100Migration:risky' => true,
76+
77+
// '@DoctrineAnnotation' => true,
78+
'@PhpCsFixer' => true,
79+
'@PhpCsFixer:risky' => true,
80+
81+
// alias
82+
'mb_str_functions' => true,
83+
84+
// array_notation
85+
86+
// basic
87+
'curly_braces_position' => [
88+
'control_structures_opening_brace' => 'same_line',
89+
'functions_opening_brace' => 'next_line_unless_newline_at_signature_end',
90+
'anonymous_functions_opening_brace' => 'same_line',
91+
'classes_opening_brace' => 'next_line_unless_newline_at_signature_end',
92+
'anonymous_classes_opening_brace' => 'same_line',
93+
'allow_single_line_empty_anonymous_classes' => true,
94+
'allow_single_line_anonymous_functions' => true,
95+
],
96+
'no_multiple_statements_per_line' => true,
97+
98+
// casing
99+
// cast_notation
100+
101+
// class_notation
102+
'final_class' => false,
103+
'final_internal_class' => false,
104+
'final_public_method_for_abstract_class' => true,
105+
'ordered_class_elements' => [
106+
'order' => [
107+
'use_trait',
108+
'case',
109+
110+
'constant_public',
111+
'constant_protected',
112+
'constant_private',
113+
114+
'property_public',
115+
'property_protected',
116+
'property_private',
117+
118+
'construct',
119+
'destruct',
120+
'magic',
121+
'phpunit',
122+
123+
'method_public',
124+
'method_protected',
125+
'method_private',
126+
],
127+
'sort_algorithm' => 'none',
128+
],
129+
'ordered_interfaces' => [
130+
'order' => 'alpha',
131+
'direction' => 'ascend',
132+
],
133+
'self_static_accessor' => true,
134+
135+
// class_usage
136+
'date_time_immutable' => true,
137+
138+
// comment
61139
'header_comment' => [
62140
'header' => $header,
63141
'comment_type' => 'PHPDoc',
142+
'location' => 'after_declare_strict',
143+
'separate' => 'both',
64144
],
65-
'blank_line_before_statement' => [
66-
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
145+
146+
// constant_notation
147+
148+
// control_structure
149+
'control_structure_braces' => true,
150+
'control_structure_continuation_position' => [
151+
// 'position' => 'same_line',
67152
],
68-
'comment_to_phpdoc' => [
69-
'ignored_tags' => [],
153+
'empty_loop_condition' => [
154+
// 'style' => 'for',
70155
],
71-
'declare_strict_types' => true,
72-
'method_argument_space' => [
73-
'on_multiline' => 'ensure_fully_multiline',
156+
'simplified_if_return' => true,
157+
158+
// doctrine_annotation
159+
160+
// function_notation
161+
'date_time_create_from_format_call' => true,
162+
'nullable_type_declaration_for_default_null_value' => [
163+
'use_nullable_type_declaration' => true,
164+
],
165+
'phpdoc_to_param_type' => [
166+
'scalar_types' => true,
167+
],
168+
// 'phpdoc_to_property_type' => [
169+
// 'scalar_types' => true,
170+
// ],
171+
'phpdoc_to_return_type' => [
172+
'scalar_types' => true,
173+
],
174+
'regular_callable_call' => true,
175+
'single_line_throw' => false,
176+
// 'static_lambda' => true,
177+
178+
// import
179+
'group_import' => false,
180+
181+
// language_construct
182+
'declare_parentheses' => true,
183+
184+
// list_notation
185+
186+
// namespace_notation
187+
'no_blank_lines_before_namespace' => false,
188+
189+
// naming
190+
191+
// operator
192+
'no_useless_concat_operator' => [
193+
'juggle_simple_strings' => true,
74194
],
75195
'not_operator_with_successor_space' => true,
76-
'no_useless_return' => true,
77-
'no_useless_else' => true,
78-
'is_null' => true,
79-
'return_assignment' => true,
80-
'multiline_comment_opening_closing' => true,
81-
'align_multiline_comment' => [
82-
'comment_type' => 'phpdocs_only',
83-
],
84-
'phpdoc_to_comment' => [],
85-
'phpdoc_var_annotation_correct_order' => true,
86-
'php_unit_construct' => [
87-
'assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame'],
88-
],
89-
'array_indentation' => true,
90-
'method_chaining_indentation' => true,
196+
197+
// php_tag
198+
199+
// php_unit
200+
'php_unit_size_class' => [
201+
'group' => 'small',
202+
],
203+
'php_unit_test_case_static_method_calls' => [
204+
'call_type' => 'this',
205+
'methods' => [],
206+
],
207+
208+
// phpdoc
209+
'general_phpdoc_annotation_remove' => [
210+
'annotations' => [
211+
'package',
212+
'subpackage',
213+
],
214+
'case_sensitive' => false,
215+
],
216+
'phpdoc_line_span' => [
217+
'const' => null,
218+
'property' => null,
219+
'method' => 'multi',
220+
],
221+
'phpdoc_no_empty_return' => false,
222+
'phpdoc_summary' => false,
223+
'phpdoc_tag_casing' => [
224+
'tags' => [
225+
'inheritDoc',
226+
],
227+
],
228+
'phpdoc_to_comment' => [
229+
// 'ignored_tags' => [],
230+
],
231+
232+
// return_notation
233+
'simplified_null_return' => true,
234+
235+
// semicolon
236+
'multiline_whitespace_before_semicolons' => [
237+
'strategy' => 'no_multi_line',
238+
],
239+
240+
// strict
241+
'declare_strict_types' => true,
242+
243+
// string_notation
244+
'explicit_string_variable' => false,
245+
246+
// whitespace
247+
'blank_line_before_statement' => [
248+
'statements' => [
249+
'break',
250+
'case',
251+
'continue',
252+
'declare',
253+
'default',
254+
'exit',
255+
'goto',
256+
'include',
257+
'include_once',
258+
'phpdoc',
259+
'require',
260+
'require_once',
261+
'return',
262+
'switch',
263+
'throw',
264+
'try',
265+
'yield',
266+
'yield_from',
267+
],
268+
],
91269
'statement_indentation' => true,
92-
])
93-
->setRiskyAllowed(true)
94-
->setFinder($finder);
270+
]);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
"psalm-baseline": "@psalm --update-baseline",
183183
"rector": "./vendor/bin/rector --clear-cache --ansi -v",
184184
"rector-dry-run": "@rector --dry-run",
185-
"style-fix": "./vendor/bin/php-cs-fixer fix --using-cache=no --config=.php-cs-fixer.php --ansi",
185+
"style-fix": "./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --ansi -v",
186186
"style-lint": "@style-fix --dry-run --diff",
187187
"test": "@pest",
188188
"test-coverage": "@pest-coverage"

config/code-runner.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
sprintf(
3636
'%s:%s,%s,%s,%s',
3737
Guanguans\LaravelCodeRunner\CodeHandlers\RemoveTokensCodeHandler::class,
38-
T_COMMENT,
39-
T_DOC_COMMENT,
40-
T_OPEN_TAG,
41-
T_CLOSE_TAG
38+
\T_COMMENT,
39+
\T_DOC_COMMENT,
40+
\T_OPEN_TAG,
41+
\T_CLOSE_TAG
4242
),
4343
// Guanguans\LaravelCodeRunner\CodeHandlers\PrefixAutoloadFilesCodeHandler::class,
4444
],

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ parameters:
77
- config
88
- routes
99
- src
10+
excludePaths:
11+
- src/CodeRunnerServiceProvider.php
1012
tmpDir: build/phpstan
1113
checkOctaneCompatibility: true
1214
checkModelProperties: true

src/CodeHandlers/RemoveTokensCodeHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public function handle(string $code, callable $next, int ...$removedTokens): str
1818
{
1919
$code = collect(token_get_all($code))->reduce(
2020
/**
21-
* @param string|array<int, string> $token
21+
* @param array<int, string>|string $token
2222
*/
2323
function (string $carry, $token) use ($removedTokens): string {
24-
if (is_string($token)) {
24+
if (\is_string($token)) {
2525
return $carry.$token;
2626
}
2727

@@ -36,7 +36,7 @@ function (string $carry, $token) use ($removedTokens): string {
3636
protected function ignoreToken(array $token, array $removedTokens): string
3737
{
3838
[$id, $text] = $token;
39-
if (in_array($id, $removedTokens, true)) {
39+
if (\in_array($id, $removedTokens, true)) {
4040
return '';
4141
}
4242

src/CodeRunnerServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function addSectionToAboutCommand(): void
116116
'readme',
117117
'reference',
118118
])
119-
->filter(static fn ($value): bool => is_string($value) && $value)
119+
->filter(static fn ($value): bool => \is_string($value) && $value)
120120
->mapWithKeys(static fn ($value, $key) => [Str::headline($key) => $value])
121121
->toArray();
122122
});

src/CodeRunners/TinkerCodeRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function createShell(BufferedOutput $bufferedOutput, ?string $configFi
5454
'updateCheck' => 'never',
5555
'configFile' => $configFile,
5656
]);
57-
$configuration->setHistoryFile(defined('PHP_WINDOWS_VERSION_BUILD') ? 'null' : '/dev/null');
57+
$configuration->setHistoryFile(\defined('PHP_WINDOWS_VERSION_BUILD') ? 'null' : '/dev/null');
5858
$configuration->getPresenter()->addCasters([
5959
Collection::class => 'Laravel\Tinker\TinkerCaster::castCollection',
6060
Model::class => 'Laravel\Tinker\TinkerCaster::castModel',

src/Facades/CodeRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class CodeRunner extends Facade
2727
{
2828
/**
29-
* {@inheritdoc}
29+
* {@inheritDoc}
3030
*/
3131
protected static function getFacadeAccessor(): string
3232
{

src/Http/Middleware/Authorize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Authorize
2121
/**
2222
* Handle the incoming request.
2323
*
24-
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
24+
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
2525
*
2626
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
2727
*/

src/Support/helpers.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414

1515
if (! function_exists('make')) {
1616
/**
17+
* @psalm-suppress MissingReturnType
18+
*
1719
* @psalm-param string|array<string, mixed> $abstract
1820
*
19-
* @return mixed
21+
* @param mixed $abstract
2022
*
2123
* @throws \InvalidArgumentException
2224
* @throws \Illuminate\Contracts\Container\BindingResolutionException
2325
*/
2426
function make($abstract, array $parameters = [])
2527
{
26-
if (! in_array(gettype($abstract), ['string', 'array'])) {
28+
if (! in_array(gettype($abstract), ['string', 'array'], true)) {
2729
throw new InvalidArgumentException(sprintf('Invalid argument type(string/array): %s.', gettype($abstract)));
2830
}
2931

0 commit comments

Comments
 (0)