Skip to content

Commit

Permalink
Update php-cs-fixer config
Browse files Browse the repository at this point in the history
The existing configuration is not compatible with current php-cs-fixer
anymore. Explicitly specify a version and use the @psr12 config,
which has a reasonably small diff.
  • Loading branch information
nikic committed Jan 2, 2025
1 parent f46ad45 commit 225fa50
Show file tree
Hide file tree
Showing 41 changed files with 422 additions and 553 deletions.
157 changes: 11 additions & 146 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,154 +8,19 @@
EOF;

$finder = PhpCsFixer\Finder::create()
->name('.php_cs')
->exclude('vendor')
->exclude('.git')
->name('.php_cs')
->exclude('vendor')
->exclude('.git')
->in(__DIR__);

return PhpCsFixer\Config::create()
->setIndent(' ')
->setLineEnding("\n")
return (new PhpCsFixer\Config())
->setIndent(' ')
->setLineEnding("\n")
->setRules([
'header_comment' => [
'comment_type' => 'PHPDoc',
'header' => $header,
],
'align_multiline_comment' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => true,
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_return' => true,
'blank_line_before_statement' => true,
'braces' => true,
'cast_spaces' => true,
'class_attributes_separation' => true,
'class_definition' => true,
'compact_nullable_typehint' => true,
'concat_space' => true,
'declare_strict_types' => true,
'elseif' => true,
'encoding' => true,
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'final_internal_class' => true,
'fully_qualified_strict_types' => true,
'full_opening_tag' => true,
'function_declaration' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'implode_call' => true,
'include' => true,
'increment_style' => true,
'indentation_type' => true,
'is_null' => true,
'line_ending' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'logical_operators' => true,
'lowercase_cast' => true,
'lowercase_constants' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'magic_method_casing' => true,
'method_argument_space' => true,
'method_chaining_indentation' => true,
'modernize_types_casting' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => true,
'native_constant_invocation' => true,
'native_function_casing' => true,
'new_with_braces' => true,
'no_alternative_syntax' => true,
'no_binary_string' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_blank_lines_before_namespace' => true,
'no_break_comment' => true,
'no_closing_tag' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_multiline_whitespace_before_semicolons' => true,
'no_short_bool_cast' => true,
'no_short_echo_tag' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_spaces_inside_parenthesis' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_unset_on_property' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'non_printable_character' => true,
'normalize_index_brace' => true,
'not_operator_with_successor_space' => true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => true,
'phpdoc_indent' => true,
'phpdoc_inline_tag' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_to_return_type' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'return_assignment' => true,
'return_type_declaration' => true,
'self_accessor' => true,
'semicolon_after_instruction' => true,
'set_type_to_cast' => true,
'short_scalar_cast' => true,
'simplified_null_return' => true,
'single_blank_line_at_eof' => true,
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_increment' => true,
'standardize_not_equals' => true,
'static_lambda' => true,
'strict_comparison' => true,
'strict_param' => true,
'string_line_ending' => true,
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'ternary_to_null_coalescing' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'visibility_required' => true,
'void_return' => true,
'whitespace_after_comma_in_array' => true,
'@PSR12' => true,
'header_comment' => [
'comment_type' => 'PHPDoc',
'header' => $header,
],
])
->setFinder($finder);
2 changes: 1 addition & 1 deletion demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use PhpParser\ParserFactory;

require __DIR__.'/vendor/autoload.php';
require __DIR__ . '/vendor/autoload.php';

$graphviz = false;
list($fileName, $code) = getCode($argc, $argv);
Expand Down
6 changes: 3 additions & 3 deletions lib/PHPCfg/Assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

class Assertion
{
const MODE_NONE = 0;
public const MODE_NONE = 0;

const MODE_UNION = 1;
public const MODE_UNION = 1;

const MODE_INTERSECTION = 2;
public const MODE_INTERSECTION = 2;

public $mode = self::MODE_NONE;

Expand Down
4 changes: 2 additions & 2 deletions lib/PHPCfg/AstVisitor/LoopResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function resolveStack(Node $node, array $stack)
if ($node->num instanceof LNumber) {
$num = $node->num->value - 1;
if ($num >= count($stack)) {
throw new \LogicException('Too high of a count for '.$node->getType());
throw new \LogicException('Too high of a count for ' . $node->getType());
}
$loc = array_slice($stack, -1 * $num, 1);

Expand All @@ -86,6 +86,6 @@ protected function resolveStack(Node $node, array $stack)

protected function makeLabel()
{
return 'compiled_label_'.mt_rand(0, mt_getrandmax()).'_'.self::$labelCounter++;
return 'compiled_label_' . mt_rand(0, mt_getrandmax()) . '_' . self::$labelCounter++;
}
}
10 changes: 5 additions & 5 deletions lib/PHPCfg/AstVisitor/MagicStringResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function enterNode(Node $node)
if ($node instanceof Node\Stmt\Function_) {
$this->functionStack[] = $node->namespacedName->toString();
} elseif ($node instanceof Node\Stmt\ClassMethod) {
$this->methodStack[] = end($this->classStack).'::'.$node->name;
$this->methodStack[] = end($this->classStack) . '::' . $node->name;
} elseif ($node instanceof Node\Name) {
switch (strtolower($node->toString())) {
case 'self':
Expand Down Expand Up @@ -91,7 +91,7 @@ public function leaveNode(Node $node)
assert(end($this->functionStack) === $node->namespacedName->toString());
array_pop($this->functionStack);
} elseif ($node instanceof Node\Stmt\ClassMethod) {
assert(end($this->methodStack) === end($this->classStack).'::'.$node->name);
assert(end($this->methodStack) === end($this->classStack) . '::' . $node->name);
array_pop($this->methodStack);
}
}
Expand All @@ -117,12 +117,12 @@ function ($match) {
$type = $match[2];
$type = preg_replace('((?<=^|\|)((?i:self)|\$this)(?=\[|$|\|))', end($this->classStack), $type);

return '@'.$match[1].' '.$type;
return '@' . $match[1] . ' ' . $type;
},
$comment->getText()
$comment->getText(),
),
$comment->getLine(),
$comment->getFilePos()
$comment->getFilePos(),
);

$node->setDocComment($comment);
Expand Down
16 changes: 8 additions & 8 deletions lib/PHPCfg/AstVisitor/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ class NameResolver extends NameResolverParent
'resource',
'callable',
];

protected $anonymousClasses = 0;

public function enterNode(Node $node)
{
parent::enterNode($node);

if ($node instanceof Node\Stmt\Class_ && is_null($node->name)) {
$anonymousName = "{anonymousClass}#".++$this->anonymousClasses;
$anonymousName = "{anonymousClass}#" . ++$this->anonymousClasses;
$node->name = new \PhpParser\Node\Identifier($anonymousName);
$node->namespacedName = new \PhpParser\Node\Name($anonymousName);
}

$comment = $node->getDocComment();
if ($comment) {
$regex = '(@(param|return|var|type)\\h+(\\S+))';
Expand All @@ -67,10 +67,10 @@ function ($match) {

return "@{$match[1]} {$type}";
},
$comment->getText()
$comment->getText(),
),
$comment->getStartLine(),
$comment->getStartFilePos()
$comment->getStartFilePos(),
);

$node->setDocComment($comment);
Expand All @@ -86,10 +86,10 @@ protected function parseTypeDecl($type)
return implode('&', array_map([$this, 'parseTypeDecl'], explode('&', $type)));
}
if (substr($type, 0, 1) === '?') {
return '?'.$this->parseTypeDecl(substr($type, 1));
return '?' . $this->parseTypeDecl(substr($type, 1));
}
if (substr($type, -2) === '[]') {
return $this->parseTypeDecl(substr($type, 0, -2)).'[]';
return $this->parseTypeDecl(substr($type, 0, -2)) . '[]';
}
if (substr($type, 0, 1) === '$') {
// Variables aren't types
Expand Down
18 changes: 9 additions & 9 deletions lib/PHPCfg/Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ class Func extends Op
{
/* Constants for the $flags property.
* The first six flags match PhpParser Class_ flags. */
const FLAG_PUBLIC = 0x01;
public const FLAG_PUBLIC = 0x01;

const FLAG_PROTECTED = 0x02;
public const FLAG_PROTECTED = 0x02;

const FLAG_PRIVATE = 0x04;
public const FLAG_PRIVATE = 0x04;

const FLAG_STATIC = 0x08;
public const FLAG_STATIC = 0x08;

const FLAG_ABSTRACT = 0x10;
public const FLAG_ABSTRACT = 0x10;

const FLAG_FINAL = 0x20;
public const FLAG_FINAL = 0x20;

const FLAG_RETURNS_REF = 0x40;
public const FLAG_RETURNS_REF = 0x40;

const FLAG_CLOSURE = 0x80;
public const FLAG_CLOSURE = 0x80;

/** @var string */
public $name;
Expand Down Expand Up @@ -68,7 +68,7 @@ public function __construct(string $name, int $flags, Op\Type $returnType, ?Oper
public function getScopedName()
{
if (null !== $this->class) {
return $this->class->value.'::'.$this->name;
return $this->class->value . '::' . $this->name;
}

return $this->name;
Expand Down
9 changes: 6 additions & 3 deletions lib/PHPCfg/Op.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ public function getAttributes(): array
return $this->attributes;
}

public function getVariableNames(): array {
public function getVariableNames(): array
{
return [];
}

public function getSubBlocks(): array {
public function getSubBlocks(): array
{
return [];
}

Expand All @@ -84,7 +86,8 @@ protected function addReadRefs(Operand ...$op): array
return $result;
}

protected function addReadRef(Operand $op): Operand {
protected function addReadRef(Operand $op): Operand
{
return $op->addUsage($this);
}

Expand Down
1 change: 0 additions & 1 deletion lib/PHPCfg/Op/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

abstract class Expr extends Op
{

public Operand $result;

protected array $writeVariables = ['result'];
Expand Down
2 changes: 1 addition & 1 deletion lib/PHPCfg/Op/Expr/ArrayDimFetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(Operand $var, ?Operand $dim = null, array $attribute
} else {
$this->dim = null;
}

}

public function getVariableNames(): array
Expand Down
3 changes: 2 additions & 1 deletion lib/PHPCfg/Op/Expr/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function getVariableNames(): array
return ['useVars', 'result'];
}

public function getFunc(): Func {
public function getFunc(): Func
{
return $this->func;
}
}
Loading

0 comments on commit 225fa50

Please sign in to comment.