Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ jobs:
run: tools/build.sh
- name: Version
run: test "$(bin/manticore-fmt version)" = "Manticore Fmt $(cat VERSION) (rules of PHP CS Fixer 3.95.27)"
- name: Format check (own code, .manticore-fmt.json)
run: bin/manticore-fmt check --diff
- name: fmt-test (round trip, invariants, rule cases)
run: tools/fmt-test.sh
- name: Goldens (output-tree hashes per rule set and corpus)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bin/
dist/
bench/work/
.DS_Store
.manticore-fmt.cache
4 changes: 4 additions & 0 deletions .manticore-fmt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rules": {"@PER-CS3x0": true},
"paths": ["src", "app", "tests/main.php"]
}
6 changes: 3 additions & 3 deletions src/Aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ public static function expand(string $name, mixed $value): ?array
$ctl = Rules::enum($name, $o, 'position_after_control_structures', ['next', 'same'], 'same');
$fn = Rules::enum($name, $o, 'position_after_functions_and_oop_constructs', ['next', 'same'], 'next');
$anon = Rules::enum($name, $o, 'position_after_anonymous_constructs', ['next', 'same'], 'same');
$pos = static fn (string $v): string => $v === 'next' ? 'next_line_unless_newline_at_signature_end' : 'same_line';
$pos = static fn(string $v): string => $v === 'next' ? 'next_line_unless_newline_at_signature_end' : 'same_line';
return [
['single_space_around_construct', ['constructs_contain_a_single_space' => [], 'constructs_followed_by_a_single_space' =>
['elseif', 'for', 'foreach', 'if', 'match', 'while', 'use_lambda'], 'constructs_preceded_by_a_single_space' => ['use_lambda']]],
['single_space_around_construct', ['constructs_contain_a_single_space' => [], 'constructs_followed_by_a_single_space'
=> ['elseif', 'for', 'foreach', 'if', 'match', 'while', 'use_lambda'], 'constructs_preceded_by_a_single_space' => ['use_lambda']]],
['control_structure_braces', true],
['control_structure_continuation_position', ['position' => $ctl === 'next' ? 'next_line' : 'same_line']],
['declare_parentheses', true],
Expand Down
2 changes: 1 addition & 1 deletion src/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private static function finish(Options $o, Config $cfg, array $results, int $tot
}
$bad = \array_merge($invalid, $failed);
if ($bad !== []) {
\usort($bad, static fn (Outcome $a, Outcome $b): int => \strcmp($a->path, $b->path));
\usort($bad, static fn(Outcome $a, Outcome $b): int => \strcmp($a->path, $b->path));
\fwrite(\STDERR, "\nFiles that were not fixed due to errors reported during " . ($invalid !== [] ? 'linting' : 'fixing') . ":\n");
$i = 0;
foreach ($bad as $b) {
Expand Down
15 changes: 8 additions & 7 deletions src/Doc/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ final class Annotation
/**
* @param Line[] $lines
*/
public function __construct(public array $lines, public int $start, public int $end, public ?NsContext $ns = null)
{
}
public function __construct(public array $lines, public int $start, public int $end, public ?NsContext $ns = null) {}

public function getTag(): Tag
{
Expand Down Expand Up @@ -65,8 +63,11 @@ public function getTypesContent(): ?string
$this->simpleTypes = true;
return $this->typesContent;
}
if (Preg::match('{^(?:\h*\*|/\*\*)[\h*]*@' . $name . '\h+' . TypeExpression::REGEX_TYPES . '(?:(?:[*\h\v]|\&?[\.\$\s]).*)?\r?$}is',
$this->getContent(), $m)) {
if (Preg::match(
'{^(?:\h*\*|/\*\*)[\h*]*@' . $name . '\h+' . TypeExpression::REGEX_TYPES . '(?:(?:[*\h\v]|\&?[\.\$\s]).*)?\r?$}is',
$this->getContent(),
$m,
)) {
$this->typesContent = (string) $m['types'];
}
}
Expand Down Expand Up @@ -114,8 +115,8 @@ public function getNormalizedTypes(): array
if ($t === null) {
return [];
}
$n = $t->mapTypes(static fn (TypeExpression $v): TypeExpression => new TypeExpression(\strtolower($v->toString()), null))
->sortTypes(static fn (TypeExpression $a, TypeExpression $b): int => $a->toString() <=> $b->toString());
$n = $t->mapTypes(static fn(TypeExpression $v): TypeExpression => new TypeExpression(\strtolower($v->toString()), null))
->sortTypes(static fn(TypeExpression $a, TypeExpression $b): int => $a->toString() <=> $b->toString());
return $n->getTypes();
}

Expand Down
4 changes: 1 addition & 3 deletions src/Doc/DoctrineToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
/** PhpCsFixer\Doctrine\Annotation\Token: a piece of a docblock as the Doctrine lexer sees it (T_NONE = plain text). */
final class DoctrineToken
{
public function __construct(public int $type = DoctrineTokens::T_NONE, public string $content = '', public int $position = 0)
{
}
public function __construct(public int $type = DoctrineTokens::T_NONE, public string $content = '', public int $position = 0) {}

public function isType(int $type): bool
{
Expand Down
4 changes: 1 addition & 3 deletions src/Doc/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ final class Line
/** bit 0: useful computed, bit 1: useful, bit 2: tag computed, bit 3: tag */
private int $memo = 0;

public function __construct(private string $content, private bool $ascii = false)
{
}
public function __construct(private string $content, private bool $ascii = false) {}

public function get(): string
{
Expand Down
3 changes: 1 addition & 2 deletions src/Doc/NsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public function __construct(
public string $ns = '',
public array $short = [],
public array $full = [],
) {
}
) {}
}
4 changes: 1 addition & 3 deletions src/Doc/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ final class Tag

private ?string $name = null;

public function __construct(public Line $line)
{
}
public function __construct(public Line $line) {}

public function getName(): string
{
Expand Down
12 changes: 7 additions & 5 deletions src/Doc/TypeExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class TypeExpression
public const REGEX_IDENTIFIER = '(?:(?!(?<!\*)\d)[^\x00-\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\x7f]++)';

public const REGEX_TYPES = '(?<types>(?x) # one or several types separated by `|` or `&`
'.self::REGEX_TYPE.'
' . self::REGEX_TYPE . '
(?:
\h*(?<glue>[|&])\h*
(?&type)
Expand Down Expand Up @@ -152,7 +152,7 @@ final class TypeExpression
|
(?<name> # full name, e.g.: `int`, `\DateTime`, `\Foo\Bar`, `positive-int`
\\\?+
(?<identifier>'.self::REGEX_IDENTIFIER.')
(?<identifier>' . self::REGEX_IDENTIFIER . ')
(?:[\\\\\-](?&identifier))*+
)
|
Expand Down Expand Up @@ -314,7 +314,7 @@ public function removeDuplicateTypes(): TypeExpression
$seen = [];
$parts = [];
foreach ($type->innerExpr as $e) {
$norm = $e->sortTypes(static fn (TypeExpression $a, TypeExpression $b): int => $a->value <=> $b->value)->value;
$norm = $e->sortTypes(static fn(TypeExpression $a, TypeExpression $b): int => $a->value <=> $b->value)->value;
if (!\in_array($norm, $seen, true)) {
$seen[] = $norm;
$parts[] = $e->value;
Expand Down Expand Up @@ -492,8 +492,10 @@ private function parse(): void
$this->parseCommaSeparatedInnerTypes(\strlen(self::cap($m, 'generic_name')) + \strlen(self::cap($m, 'generic_start')), self::cap($m, 'generic_types'));
} elseif (self::cap($m, 'callable') !== '' && self::capAt($m, 'callable') === 0) {
$this->add(0, self::cap($m, 'callable_name'));
$this->parseCallableTemplateInnerTypes(\strlen(self::cap($m, 'callable_name')) + \strlen(self::cap($m, 'callable_template_start')),
self::cap($m, 'callable_template_inners'));
$this->parseCallableTemplateInnerTypes(
\strlen(self::cap($m, 'callable_name')) + \strlen(self::cap($m, 'callable_template_start')),
self::cap($m, 'callable_template_inners'),
);
$this->parseCallableArgumentTypes(\strlen(self::cap($m, 'callable_name')) + \strlen(self::cap($m, 'callable_template'))
+ \strlen(self::cap($m, 'callable_start')), self::cap($m, 'callable_arguments'));
$ret = self::cap($m, 'callable_return');
Expand Down
4 changes: 1 addition & 3 deletions src/DoctrineAnnotationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ abstract class DoctrineAnnotationRule extends DocRule
private array $elements = [];

/** @param string[] $ignoredTags */
public function __construct(protected array $ignoredTags)
{
}
public function __construct(protected array $ignoredTags) {}

/** the list upstream ignores by default */
public const IGNORED = ['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial',
Expand Down
3 changes: 1 addition & 2 deletions src/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public function __construct(
public int $split = -1,
/** @var int[] more such offsets (a flat rule that left several) */
public array $splits = [],
) {
}
) {}
}
22 changes: 16 additions & 6 deletions src/ExtraRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ public static function make(string $name, string $lineEnding, array $opt = [], s
}
if ($name === 'numeric_literal_separator') {
Rules::only($name, $opt, ['override_existing', 'strategy']);
return new NumericLiteralSeparator(Rules::bool($name, $opt, 'override_existing', false),
Rules::enum($name, $opt, 'strategy', ['use_separator', 'no_separator'], 'use_separator') === 'use_separator');
return new NumericLiteralSeparator(
Rules::bool($name, $opt, 'override_existing', false),
Rules::enum($name, $opt, 'strategy', ['use_separator', 'no_separator'], 'use_separator') === 'use_separator',
);
}
if ($name === 'heredoc_indentation') {
Rules::only($name, $opt, ['indentation']);
Expand Down Expand Up @@ -136,8 +138,11 @@ public static function make(string $name, string $lineEnding, array $opt = [], s
}
if ($name === 'ordered_interfaces') {
Rules::only($name, $opt, ['order', 'direction', 'case_sensitive']);
return new OrderedInterfaces(Rules::enum($name, $opt, 'order', ['alpha', 'length'], 'alpha') === 'length',
Rules::enum($name, $opt, 'direction', ['ascend', 'descend'], 'ascend') === 'descend', Rules::bool($name, $opt, 'case_sensitive', false));
return new OrderedInterfaces(
Rules::enum($name, $opt, 'order', ['alpha', 'length'], 'alpha') === 'length',
Rules::enum($name, $opt, 'direction', ['ascend', 'descend'], 'ascend') === 'descend',
Rules::bool($name, $opt, 'case_sensitive', false),
);
}
if ($name === 'multiline_promoted_properties') {
Rules::only($name, $opt, ['keep_blank_lines', 'minimum_number_of_parameters']);
Expand Down Expand Up @@ -240,9 +245,14 @@ public static function make(string $name, string $lineEnding, array $opt = [], s
throw new \InvalidArgumentException("$name: Provided RegEx is not valid.");
}
}
return new HeaderComment($header, $validator, Rules::enum($name, $opt, 'comment_type', ['PHPDoc', 'comment'], 'comment') === 'PHPDoc',
return new HeaderComment(
$header,
$validator,
Rules::enum($name, $opt, 'comment_type', ['PHPDoc', 'comment'], 'comment') === 'PHPDoc',
Rules::enum($name, $opt, 'location', ['after_open', 'after_declare_strict'], 'after_declare_strict') === 'after_open',
Rules::enum($name, $opt, 'separate', ['both', 'top', 'bottom', 'none'], 'both'), $lineEnding);
Rules::enum($name, $opt, 'separate', ['both', 'top', 'bottom', 'none'], 'both'),
$lineEnding,
);
}
return null;
}
Expand Down
4 changes: 1 addition & 3 deletions src/FlatAttributeElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
/** One attribute of a `#[A, B(1)]` group as AttributeAnalyzer::collectAttributes reports it: item range [start, end] (flat indexes) and the name as written. */
final class FlatAttributeElement
{
public function __construct(public int $start, public int $end, public string $name)
{
}
public function __construct(public int $start, public int $end, public string $name) {}
}
4 changes: 1 addition & 3 deletions src/FlatAttributeGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
final class FlatAttributeGroup
{
/** @param FlatAttributeElement[] $attributes */
public function __construct(public int $start, public int $end, public int $open, public int $close, public array $attributes)
{
}
public function __construct(public int $start, public int $end, public int $open, public int $close, public array $attributes) {}
}
2 changes: 1 addition & 1 deletion src/FlatAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ private static function namespaceAt(FlatTokens $t, int $at): array
}
return ['', 0, $t->count()];
}
}
}
8 changes: 2 additions & 6 deletions src/GapRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public function isFileRule(): bool
return false;
}

public function fixFile(Source $s): void
{
}
public function fixFile(Source $s): void {}

/** An EditRule: fixFile may record token edits (Source::edit), the Engine rebuilds the Source after it. */
public function isEditRule(): bool
Expand All @@ -88,9 +86,7 @@ public function isEditRule(): bool
}

/** The path of the file the next prepare() / fixFile() run is about (a rule that depends on it, psr_autoloading, keeps it); '' = no file */
public function forFile(string $path): void
{
}
public function forFile(string $path): void {}

/** A rule that works on the raw file before it is lexed (encoding: a BOM); the Cli applies it in priority order. */
public function preParse(string $code): string
Expand Down
4 changes: 1 addition & 3 deletions src/Outcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ final class Outcome
/** peak resident bytes of the worker that formatted the file (0 when run in-process) */
public int $peak = 0;

public function __construct(public string $path, public int $status)
{
}
public function __construct(public string $path, public int $status) {}

public function toWire(): string
{
Expand Down
8 changes: 4 additions & 4 deletions src/PhpdocToTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public function __construct(bool $scalarTypes, bool $unionTypes, array $typesMap
$this->reserved[$w] = true;
}
$tpl = \strtoupper($this->template());
foreach (\explode(' ', $this->constant('FATAL_ALONE_'.$tpl)) as $w) {
foreach (\explode(' ', $this->constant('FATAL_ALONE_' . $tpl)) as $w) {
if ($w !== '') {
$this->fatal[$w] = true;
}
}
foreach (\explode(' ', $this->constant('ALONE_'.$tpl)) as $w) {
foreach (\explode(' ', $this->constant('ALONE_' . $tpl)) as $w) {
$this->alone[$w] = true;
}
foreach (\explode(' ', $this->constant('UNION_'.$tpl)) as $w) {
foreach (\explode(' ', $this->constant('UNION_' . $tpl)) as $w) {
$this->union[$w] = true;
}
}
Expand All @@ -67,7 +67,7 @@ abstract protected function isSkippedType(string $type): bool;

private function constant(string $name): string
{
return (string) \constant(TypeSyntax::class.'::'.$name);
return (string) \constant(TypeSyntax::class . '::' . $name);
}

/** the tag whose docblock a file needs to be changed at all */
Expand Down
2 changes: 1 addition & 1 deletion src/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function run(array $files, int $workers, Processor $proc, ?Progres
$size[$i] = (int) @\filesize($f);
}
$order = \array_keys($size);
\usort($order, static fn (int $a, int $b): int => $size[$b] <=> $size[$a] ?: $a <=> $b);
\usort($order, static fn(int $a, int $b): int => $size[$b] <=> $size[$a] ?: $a <=> $b);
/** @var int[][] $share */
$share = [];
/** @var int[] $load */
Expand Down
4 changes: 1 addition & 3 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ final class Processor
* @param bool $diff fill Outcome::$diff
* @param bool $applied fill Outcome::$applied (runs the rules one at a time)
*/
public function __construct(private array $rules, private bool $dry, private bool $diff, private bool $applied, private ?Cache $cache = null)
{
}
public function __construct(private array $rules, private bool $dry, private bool $diff, private bool $applied, private ?Cache $cache = null) {}

public function file(string $path): Outcome
{
Expand Down
4 changes: 1 addition & 3 deletions src/Progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class Progress
private int $errors = 0;
private float $last = 0.0;

public function __construct(private int $total, private bool $color, private float $t0, private int $width = 0)
{
}
public function __construct(private int $total, private bool $color, private float $t0, private int $width = 0) {}

public function start(): void
{
Expand Down
11 changes: 9 additions & 2 deletions src/Reporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ private static function txt(array $changed, bool $dry, bool $withFixers, int $fi
}
$out .= "\n";
}
$sum = \sprintf("%s %d of %d %s in %.3f seconds, %.2f MB memory used", $dry ? 'Found' : 'Fixed', $i, $filesCount,
$dry ? 'files that can be fixed' : 'files', $seconds, $mb);
$sum = \sprintf(
"%s %d of %d %s in %.3f seconds, %.2f MB memory used",
$dry ? 'Found' : 'Fixed',
$i,
$filesCount,
$dry ? 'files that can be fixed' : 'files',
$seconds,
$mb,
);
return $out . "\n" . Ansi::paint($color, $i > 0 ? Ansi::YELLOW : Ansi::GREEN, $sum) . "\n";
}

Expand Down
Loading
Loading