Skip to content

Commit

Permalink
Apply php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Mar 9, 2023
1 parent 54ca304 commit c089a9c
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 48 deletions.
244 changes: 210 additions & 34 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$header = <<<EOF
This file is part of the guanguans/laravel-code-runner.
$header = <<<'header'
This file is part of the guanguans/laravel-code-runner.
(c) guanguans <ityaozm@gmail.com>
(c) guanguans <ityaozm@gmail.com>
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()
Expand All @@ -33,6 +33,7 @@
->append([
__DIR__.'/.php-cs-fixer.php',
__DIR__.'/rector.php',
__DIR__.'/tests.php',
])
->exclude([
'.github/',
Expand All @@ -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);
]);
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions config/code-runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ parameters:
- config
- routes
- src
excludePaths:
- src/CodeRunnerServiceProvider.php
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
Expand Down
6 changes: 3 additions & 3 deletions src/CodeHandlers/RemoveTokensCodeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public function handle(string $code, callable $next, int ...$removedTokens): str
{
$code = collect(token_get_all($code))->reduce(
/**
* @param string|array<int, string> $token
* @param array<int, string>|string $token
*/
function (string $carry, $token) use ($removedTokens): string {
if (is_string($token)) {
if (\is_string($token)) {
return $carry.$token;
}

Expand All @@ -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 '';
}

Expand Down
2 changes: 1 addition & 1 deletion src/CodeRunnerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion src/CodeRunners/TinkerCodeRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/CodeRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class CodeRunner extends Facade
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected static function getFacadeAccessor(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
6 changes: 4 additions & 2 deletions src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@

if (! function_exists('make')) {
/**
* @psalm-suppress MissingReturnType
*
* @psalm-param string|array<string, mixed> $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)));
}

Expand Down

0 comments on commit c089a9c

Please sign in to comment.