diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index e45a7ff..406eab7 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -13,13 +13,13 @@ use PhpCsFixer\Config; use PhpCsFixer\Finder; -$header = << + (c) guanguans -This source file is subject to the MIT license that is bundled. -EOF; + This source file is subject to the MIT license that is bundled. + header; /** @noinspection PhpParamsInspection */ $finder = Finder::create() @@ -33,6 +33,7 @@ ->append([ __DIR__.'/.php-cs-fixer.php', __DIR__.'/rector.php', + __DIR__.'/tests.php', ]) ->exclude([ '.github/', @@ -52,43 +53,218 @@ ->ignoreVCS(true); return (new Config()) + ->setFinder($finder) + ->setRiskyAllowed(true) + ->setUsingCache(false) + ->setCacheFile(__DIR__.'/build/.php-cs-fixer.cache') ->setRules([ - '@DoctrineAnnotation' => true, - '@PHP80Migration:risky' => true, + // '@PHP70Migration' => true, + // '@PHP70Migration:risky' => true, + // '@PHP71Migration' => true, + // '@PHP71Migration:risky' => true, + // '@PHP73Migration' => true, + '@PHP74Migration' => true, + '@PHP74Migration:risky' => true, + // '@PHP80Migration' => true, + // '@PHP80Migration:risky' => true, + // '@PHP81Migration' => true, + // '@PHP82Migration' => true, + + // '@PHPUnit75Migration:risky' => true, '@PHPUnit84Migration:risky' => true, - '@PSR12:risky' => true, - '@Symfony' => true, + // '@PHPUnit100Migration:risky' => true, + + // '@DoctrineAnnotation' => true, + '@PhpCsFixer' => true, + '@PhpCsFixer:risky' => true, + + // alias + 'mb_str_functions' => true, + + // array_notation + + // basic + 'curly_braces_position' => [ + 'control_structures_opening_brace' => 'same_line', + 'functions_opening_brace' => 'next_line_unless_newline_at_signature_end', + 'anonymous_functions_opening_brace' => 'same_line', + 'classes_opening_brace' => 'next_line_unless_newline_at_signature_end', + 'anonymous_classes_opening_brace' => 'same_line', + 'allow_single_line_empty_anonymous_classes' => true, + 'allow_single_line_anonymous_functions' => true, + ], + 'no_multiple_statements_per_line' => true, + + // casing + // cast_notation + + // class_notation + 'final_class' => false, + 'final_internal_class' => false, + 'final_public_method_for_abstract_class' => true, + 'ordered_class_elements' => [ + 'order' => [ + 'use_trait', + 'case', + + 'constant_public', + 'constant_protected', + 'constant_private', + + 'property_public', + 'property_protected', + 'property_private', + + 'construct', + 'destruct', + 'magic', + 'phpunit', + + 'method_public', + 'method_protected', + 'method_private', + ], + 'sort_algorithm' => 'none', + ], + 'ordered_interfaces' => [ + 'order' => 'alpha', + 'direction' => 'ascend', + ], + 'self_static_accessor' => true, + + // class_usage + 'date_time_immutable' => true, + + // comment 'header_comment' => [ 'header' => $header, 'comment_type' => 'PHPDoc', + 'location' => 'after_declare_strict', + 'separate' => 'both', ], - 'blank_line_before_statement' => [ - 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], + + // constant_notation + + // control_structure + 'control_structure_braces' => true, + 'control_structure_continuation_position' => [ + // 'position' => 'same_line', ], - 'comment_to_phpdoc' => [ - 'ignored_tags' => [], + 'empty_loop_condition' => [ + // 'style' => 'for', ], - 'declare_strict_types' => true, - 'method_argument_space' => [ - 'on_multiline' => 'ensure_fully_multiline', + 'simplified_if_return' => true, + + // doctrine_annotation + + // function_notation + 'date_time_create_from_format_call' => true, + 'nullable_type_declaration_for_default_null_value' => [ + 'use_nullable_type_declaration' => true, + ], + 'phpdoc_to_param_type' => [ + 'scalar_types' => true, + ], + // 'phpdoc_to_property_type' => [ + // 'scalar_types' => true, + // ], + 'phpdoc_to_return_type' => [ + 'scalar_types' => true, + ], + 'regular_callable_call' => true, + 'single_line_throw' => false, + // 'static_lambda' => true, + + // import + 'group_import' => false, + + // language_construct + 'declare_parentheses' => true, + + // list_notation + + // namespace_notation + 'no_blank_lines_before_namespace' => false, + + // naming + + // operator + 'no_useless_concat_operator' => [ + 'juggle_simple_strings' => true, ], 'not_operator_with_successor_space' => true, - 'no_useless_return' => true, - 'no_useless_else' => true, - 'is_null' => true, - 'return_assignment' => true, - 'multiline_comment_opening_closing' => true, - 'align_multiline_comment' => [ - 'comment_type' => 'phpdocs_only', - ], - 'phpdoc_to_comment' => [], - 'phpdoc_var_annotation_correct_order' => true, - 'php_unit_construct' => [ - 'assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame'], - ], - 'array_indentation' => true, - 'method_chaining_indentation' => true, + + // php_tag + + // php_unit + 'php_unit_size_class' => [ + 'group' => 'small', + ], + 'php_unit_test_case_static_method_calls' => [ + 'call_type' => 'this', + 'methods' => [], + ], + + // phpdoc + 'general_phpdoc_annotation_remove' => [ + 'annotations' => [ + 'package', + 'subpackage', + ], + 'case_sensitive' => false, + ], + 'phpdoc_line_span' => [ + 'const' => null, + 'property' => null, + 'method' => 'multi', + ], + 'phpdoc_no_empty_return' => false, + 'phpdoc_summary' => false, + 'phpdoc_tag_casing' => [ + 'tags' => [ + 'inheritDoc', + ], + ], + 'phpdoc_to_comment' => [ + // 'ignored_tags' => [], + ], + + // return_notation + 'simplified_null_return' => true, + + // semicolon + 'multiline_whitespace_before_semicolons' => [ + 'strategy' => 'no_multi_line', + ], + + // strict + 'declare_strict_types' => true, + + // string_notation + 'explicit_string_variable' => false, + + // whitespace + 'blank_line_before_statement' => [ + 'statements' => [ + 'break', + 'case', + 'continue', + 'declare', + 'default', + 'exit', + 'goto', + 'include', + 'include_once', + 'phpdoc', + 'require', + 'require_once', + 'return', + 'switch', + 'throw', + 'try', + 'yield', + 'yield_from', + ], + ], 'statement_indentation' => true, - ]) - ->setRiskyAllowed(true) - ->setFinder($finder); + ]); diff --git a/composer.json b/composer.json index 0271697..0f3d043 100644 --- a/composer.json +++ b/composer.json @@ -182,7 +182,7 @@ "psalm-baseline": "@psalm --update-baseline", "rector": "./vendor/bin/rector --clear-cache --ansi -v", "rector-dry-run": "@rector --dry-run", - "style-fix": "./vendor/bin/php-cs-fixer fix --using-cache=no --config=.php-cs-fixer.php --ansi", + "style-fix": "./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --ansi -v", "style-lint": "@style-fix --dry-run --diff", "test": "@pest", "test-coverage": "@pest-coverage" diff --git a/config/code-runner.php b/config/code-runner.php index 69d513c..aa2bfd4 100644 --- a/config/code-runner.php +++ b/config/code-runner.php @@ -35,10 +35,10 @@ sprintf( '%s:%s,%s,%s,%s', Guanguans\LaravelCodeRunner\CodeHandlers\RemoveTokensCodeHandler::class, - T_COMMENT, - T_DOC_COMMENT, - T_OPEN_TAG, - T_CLOSE_TAG + \T_COMMENT, + \T_DOC_COMMENT, + \T_OPEN_TAG, + \T_CLOSE_TAG ), // Guanguans\LaravelCodeRunner\CodeHandlers\PrefixAutoloadFilesCodeHandler::class, ], diff --git a/phpstan.neon b/phpstan.neon index c8e3556..ad09db2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,6 +7,8 @@ parameters: - config - routes - src + excludePaths: + - src/CodeRunnerServiceProvider.php tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true diff --git a/src/CodeHandlers/RemoveTokensCodeHandler.php b/src/CodeHandlers/RemoveTokensCodeHandler.php index 04e5a82..9609230 100644 --- a/src/CodeHandlers/RemoveTokensCodeHandler.php +++ b/src/CodeHandlers/RemoveTokensCodeHandler.php @@ -18,10 +18,10 @@ public function handle(string $code, callable $next, int ...$removedTokens): str { $code = collect(token_get_all($code))->reduce( /** - * @param string|array $token + * @param array|string $token */ function (string $carry, $token) use ($removedTokens): string { - if (is_string($token)) { + if (\is_string($token)) { return $carry.$token; } @@ -36,7 +36,7 @@ function (string $carry, $token) use ($removedTokens): string { protected function ignoreToken(array $token, array $removedTokens): string { [$id, $text] = $token; - if (in_array($id, $removedTokens, true)) { + if (\in_array($id, $removedTokens, true)) { return ''; } diff --git a/src/CodeRunnerServiceProvider.php b/src/CodeRunnerServiceProvider.php index ae7247b..696e08f 100644 --- a/src/CodeRunnerServiceProvider.php +++ b/src/CodeRunnerServiceProvider.php @@ -116,7 +116,7 @@ protected function addSectionToAboutCommand(): void 'readme', 'reference', ]) - ->filter(static fn ($value): bool => is_string($value) && $value) + ->filter(static fn ($value): bool => \is_string($value) && $value) ->mapWithKeys(static fn ($value, $key) => [Str::headline($key) => $value]) ->toArray(); }); diff --git a/src/CodeRunners/TinkerCodeRunner.php b/src/CodeRunners/TinkerCodeRunner.php index 5c45db1..ae80bdb 100644 --- a/src/CodeRunners/TinkerCodeRunner.php +++ b/src/CodeRunners/TinkerCodeRunner.php @@ -54,7 +54,7 @@ protected function createShell(BufferedOutput $bufferedOutput, ?string $configFi 'updateCheck' => 'never', 'configFile' => $configFile, ]); - $configuration->setHistoryFile(defined('PHP_WINDOWS_VERSION_BUILD') ? 'null' : '/dev/null'); + $configuration->setHistoryFile(\defined('PHP_WINDOWS_VERSION_BUILD') ? 'null' : '/dev/null'); $configuration->getPresenter()->addCasters([ Collection::class => 'Laravel\Tinker\TinkerCaster::castCollection', Model::class => 'Laravel\Tinker\TinkerCaster::castModel', diff --git a/src/Facades/CodeRunner.php b/src/Facades/CodeRunner.php index f5e3328..bf0495e 100644 --- a/src/Facades/CodeRunner.php +++ b/src/Facades/CodeRunner.php @@ -26,7 +26,7 @@ class CodeRunner extends Facade { /** - * {@inheritdoc} + * {@inheritDoc} */ protected static function getFacadeAccessor(): string { diff --git a/src/Http/Middleware/Authorize.php b/src/Http/Middleware/Authorize.php index f212dd4..df22c8d 100644 --- a/src/Http/Middleware/Authorize.php +++ b/src/Http/Middleware/Authorize.php @@ -21,7 +21,7 @@ class Authorize /** * Handle the incoming request. * - * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response + * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response * * @throws \Symfony\Component\HttpKernel\Exception\HttpException */ diff --git a/src/Support/helpers.php b/src/Support/helpers.php index b550390..034d85d 100644 --- a/src/Support/helpers.php +++ b/src/Support/helpers.php @@ -14,16 +14,18 @@ if (! function_exists('make')) { /** + * @psalm-suppress MissingReturnType + * * @psalm-param string|array $abstract * - * @return mixed + * @param mixed $abstract * * @throws \InvalidArgumentException * @throws \Illuminate\Contracts\Container\BindingResolutionException */ function make($abstract, array $parameters = []) { - if (! in_array(gettype($abstract), ['string', 'array'])) { + if (! in_array(gettype($abstract), ['string', 'array'], true)) { throw new InvalidArgumentException(sprintf('Invalid argument type(string/array): %s.', gettype($abstract))); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 98347bb..8e22581 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -22,6 +22,13 @@ use Livewire\LivewireServiceProvider; use Spatie\Snapshots\MatchesSnapshots; +/** + * @internal + * + * @coversNothing + * + * @small + */ class TestCase extends \Orchestra\Testbench\TestCase { use ArraySubsetAsserts; @@ -73,6 +80,8 @@ protected function finish(): void } /** + * @param mixed $app + * * @return class-string[] */ protected function getPackageProviders($app): array