Skip to content

Commit

Permalink
chore: update coding-standards
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Sep 25, 2023
1 parent 87a6c1c commit b4e6ac0
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bin/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function arrayToString(array $array = null)
if (array_values($array) === $array) {
$string .= implode(', ', array_map([self::class, 'valueToString'], $array));
} else {
$string .= implode(', ', array_map(fn ($value, $key) => '\''.$key.'\' => '.self::valueToString($value), $array, array_keys($array)));
$string .= implode(', ', array_map(static fn ($value, $key) => '\''.$key.'\' => '.self::valueToString($value), $array, array_keys($array)));
}

$string .= ' ]';
Expand Down
12 changes: 6 additions & 6 deletions bin/doc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include sprintf('%s/../vendor/autoload.php', __DIR__);

include 'Utils.php';

$fixers = array_map(function (AbstractFixer $fixer) {
$fixers = array_map(static function (AbstractFixer $fixer) {
$samples = $fixer->getDefinition()->getCodeSamples();

return [
Expand All @@ -25,7 +25,7 @@ $fixers = array_map(function (AbstractFixer $fixer) {
'deprecated' => $fixer->isDeprecated(),
'replacement' => $fixer->getDeprecationReplacement(),
'options' => array_map(
function (FixerOptionInterface $option) {
static function (FixerOptionInterface $option) {
return [
'name' => $option->getName(),
'description' => $option->getDescription(),
Expand All @@ -39,7 +39,7 @@ $fixers = array_map(function (AbstractFixer $fixer) {
? $fixer->getConfigurationDefinition()->getOptions()
: []
),
'samples' => array_map(function (CodeSample $sample) use ($fixer) {
'samples' => array_map(static function (CodeSample $sample) use ($fixer) {
if ($fixer instanceof ConfigurableFixerInterface) {
$fixer->configure($sample->getConfiguration());
}
Expand All @@ -57,13 +57,13 @@ $fixers = array_map(function (AbstractFixer $fixer) {
}

while (strlen($line) < 80 + 1) {
$line = $line.' ';
$line .= ' ';
}

if (0 === $num) {
$line = $line.'// 80 chars';
$line .= '// 80 chars';
} else {
$line = $line.'//';
$line .= '//';
}

$diff[$num] = $line;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"php": "^8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.17",
"friendsofphp/php-cs-fixer": "^3.28",
"phpspec/phpspec": "^7.0",
"sebastian/diff": "^4.0",
"twig/twig": "^3.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ private function getMethodsNames(array $elements): array

private function getPropertiesNames(array $elements): array
{
$properties = array_filter($elements, fn ($element) => 'property' === $element['type']);
$properties = array_filter($elements, static fn ($element) => 'property' === $element['type']);

return array_map(fn ($element) => ltrim($element['propertyName'], '$'), $properties);
return array_map(static fn ($element) => ltrim($element['propertyName'], '$'), $properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private function formatComments(array $comments, string $indentation): string
array_pop($comments);
}

$comments = array_map(fn ($comment) => rtrim($indentation.' * '.ltrim($comment, ' /')), $comments);
$comments = array_map(static fn ($comment) => rtrim($indentation.' * '.ltrim($comment, ' /')), $comments);

$comments = implode("\n", $comments);
$comments = trim($comments, " \n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
$possible = array_merge($possible, array_keys($ends));
}

$possible = array_filter($possible, fn ($value) => null !== $value);
$possible = array_filter($possible, static fn ($value) => null !== $value);

if (empty($possible)) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/PedroTroller/CS/Fixer/Fixers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getIterator(): Generator
;

$files = array_map(
fn ($file) => $file->getPathname(),
static fn ($file) => $file->getPathname(),
iterator_to_array($finder)
);

Expand Down
8 changes: 3 additions & 5 deletions src/PedroTroller/CS/Fixer/Priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

final class Priority
{
private function __construct()
{
}
private function __construct() {}

/**
* @param array<int, mixed> $classes
Expand All @@ -18,7 +16,7 @@ private function __construct()
public static function before(...$classes)
{
$priorities = array_map(
fn ($class) => (new $class())->getPriority(),
static fn ($class) => (new $class())->getPriority(),
$classes
);

Expand All @@ -33,7 +31,7 @@ public static function before(...$classes)
public static function after(...$classes)
{
$priorities = array_map(
fn ($class) => (new $class())->getPriority(),
static fn ($class) => (new $class())->getPriority(),
$classes
);

Expand Down
10 changes: 5 additions & 5 deletions src/PedroTroller/CS/Fixer/RuleSetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,27 @@ private function migration($package, $version, $risky)
$rules = (new RuleSets())->getSetDefinitionNames();
$rules = array_combine($rules, $rules);

$rules = array_map(function ($name) {
$rules = array_map(static function ($name) {
preg_match('/^@([A-Za-z]+)(\d+)Migration(:risky|)$/', $name, $matches);

return $matches;
}, $rules);

$rules = array_filter($rules);

$rules = array_filter($rules, function ($versionAndRisky) use ($package) {
$rules = array_filter($rules, static function ($versionAndRisky) use ($package) {
[$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky;

return strtoupper($package) === strtoupper($rulePackage);
});

$rules = array_filter($rules, function ($versionAndRisky) use ($version) {
$rules = array_filter($rules, static function ($versionAndRisky) use ($version) {
[$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky;

return ((float) $ruleVersion / 10) <= $version;
});

$rules = array_filter($rules, function ($versionAndRisky) use ($risky) {
$rules = array_filter($rules, static function ($versionAndRisky) use ($risky) {
[$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky;

if ($risky) {
Expand All @@ -269,7 +269,7 @@ private function migration($package, $version, $risky)

return self::create(array_merge(
$this->rules,
array_map(fn () => true, $rules)
array_map(static fn () => true, $rules)
));
}
}
4 changes: 1 addition & 3 deletions src/PedroTroller/CS/Fixer/TokenSignatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ final class TokenSignatures
public const TYPINT_OPTIONAL = 10022;
public const TYPINT_DOUBLE_DOTS = 10025;

public function __construct()
{
}
public function __construct() {}
}
4 changes: 2 additions & 2 deletions tests/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function run(): void
$deprecations = [];

set_error_handler(
function ($type, $message, $file, $line) use (&$deprecations): void {
static function ($type, $message, $file, $line) use (&$deprecations): void {
$deprecations[$message][] = sprintf('%s at line %d', $file, $line);
$deprecations[$message] = array_unique($deprecations[$message]);

Expand All @@ -40,7 +40,7 @@ function ($type, $message, $file, $line) use (&$deprecations): void {
implode(
"\n\n",
array_map(
fn ($message, array $files) => sprintf("%s\n%s", $message, implode("\n", $files)),
static fn ($message, array $files) => sprintf("%s\n%s", $message, implode("\n", $files)),
array_keys($deprecations),
$deprecations
)
Expand Down
2 changes: 1 addition & 1 deletion tests/TokensAnalyzerIntegration/MethodArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function assertions(TokensAnalyzer $analyzer, Tokens $tokens): void
{
$methods = array_filter(
$analyzer->getClassyElements(),
fn ($element) => 'method' === $element['type']
static fn ($element) => 'method' === $element['type']
);

Assert::count($methods, 3);
Expand Down

0 comments on commit b4e6ac0

Please sign in to comment.