Skip to content

Commit

Permalink
Merge pull request #38 from mkhrystunov/final-update-php-cs-fixer
Browse files Browse the repository at this point in the history
Added suppport for php 8.2
  • Loading branch information
mSprunskas authored Jan 19, 2024
2 parents b1c1e43 + b31c1b8 commit 7c1aee9
Show file tree
Hide file tree
Showing 40 changed files with 361 additions and 205 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ matrix:
env: COMPOSER_ARGS=""
- php: "7.4"
env: COMPOSER_ARGS=""
- php: "8.2"
env: COMPOSER_ARGS=""

- php: "7.0"
env: COMPOSER_ARGS="--prefer-lowest"
Expand All @@ -29,6 +31,8 @@ matrix:
env: COMPOSER_ARGS="--prefer-lowest"
- php: "7.4"
env: COMPOSER_ARGS="--prefer-lowest"
- php: "8.2"
env: COMPOSER_ARGS="--prefer-lowest"

cache:
directories:
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ Semantic Versioning is maintained only for the following:
The fixers themselves can change their behavior on any update.
New fixers could be added with minor releases, this would require changes in configuration if migration mode is used.

## 2.5.0

### Added

- added support for php 8.2

### Changed

- `php-cs-fixer` is updated to `2.19` version, including binary `paysera-php-cs-fixer` that's distributed with this
library.

### Removed

- Removed unused dependency `gecko-packages/gecko-php-unit`

## 2.4.2

### Changed
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"description": "PHP CS Fixer config for Paysera conventions",
"type": "library",
"require": {
"php": "^7.0",
"php": "^7.0 || ^8.2",
"doctrine/inflector": "^1.0"
},
"require-dev": {
"gecko-packages/gecko-php-unit": "^2.0",
"phpunit/phpunit": "^6.0",
"friendsofphp/php-cs-fixer": "2.16.3"
"phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"friendsofphp/php-cs-fixer": "2.19",
"sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 15 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php">

<testsuites>
Expand All @@ -17,14 +17,20 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<groups>
<exclude>
<group>legacy</group>
</exclude>
</groups>

<coverage>
<include>
<directory>./</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>

</phpunit>
2 changes: 1 addition & 1 deletion src/Config/PayseraConventionsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function enableMigrationMode(array $rules)
return $this;
}

public function getRules()
public function getRules(): array
{
$rules = parent::getRules();
if ($this->migrationModeRules === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/IgnorableFixerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getDefinition()
<?php // @php-cs-fixer-ignore my_test_fixer'

PHP
),
)
]
);

Expand Down
24 changes: 15 additions & 9 deletions src/Fixer/PSR1/ClassConstantUpperCaseFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ public function getDefinition()
return new FixerDefinition(
'Ensures that constant names are all uppercase with underscores.',
[
new CodeSample('
<?php
class invalid_className
{
const class_constantLongName = 1;
const classconstant = 2;
}
'),
]
new CodeSample(<<<'PHP'
<?php
class invalid_className
{
const class_constantLongName = 1;
const classconstant = 2;
}

PHP
),
],
null,
null,
null,
'Paysera recommendation.'
);
}

Expand Down
18 changes: 12 additions & 6 deletions src/Fixer/PSR1/ClassNameStudlyCapsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ final class ClassNameStudlyCapsFixer extends AbstractFixer
public function getDefinition()
{
return new FixerDefinition(
'Ensures classes are in StudlyCaps, and the first letter is capitalised',
'Ensures classes are in StudlyCaps, and the first letter is capitalised.',
[
new CodeSample('
<?php
class invalid_className {}
'),
]
new CodeSample(<<<'PHP'
<?php
class invalid_className {}

PHP
),
],
null,
null,
null,
'Paysera recommendation.'
);
}

Expand Down
57 changes: 34 additions & 23 deletions src/Fixer/PSR1/FileSideEffectsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,35 @@ public function __construct()
public function getDefinition()
{
return new FixerDefinition(
'
Ensures a file declare new symbols and causes no other side effects,
or executes logic with side effects, but not both.
',
<<<'TEXT'
Ensures a file declare new symbols and causes no other side effects,
or executes logic with side effects, but not both.
TEXT
,
[
new CodeSample('
<?php
// side effect: change ini settings
ini_set("error_reporting", E_ALL);
// side effect: loads a file
include "file.php";
// declaration
function foo()
{
// function body
$a = 1;
var_dump($a);
}
'),
]
new CodeSample(<<<'PHP'
<?php
// side effect: change ini settings
ini_set("error_reporting", E_ALL);
// side effect: loads a file
include "file.php";
// declaration
function foo()
{
// function body
$a = 1;
var_dump($a);
}

PHP
),
],
null,
null,
null,
'Paysera recommendation.'
);
}

Expand Down Expand Up @@ -121,8 +128,12 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens)

if ($sideEffects > 0 && $symbols > 0) {
if (!$tokens[$count - 1]->isGivenKind(T_COMMENT)) {
$tokens->insertAt($count, new Token([T_COMMENT, self::CONVENTION]));
$tokens->insertAt($count, new Token([T_WHITESPACE, "\n"]));
$tokens->insertSlices([
$count => [
new Token([T_WHITESPACE, "\n"]),
new Token([T_COMMENT, self::CONVENTION]),
],
]);
}
break;
}
Expand Down
22 changes: 14 additions & 8 deletions src/Fixer/PSR1/FunctionNameCamelCaseFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ public function getDefinition()
return new FixerDefinition(
'Ensures function names are defined using camel case.',
[
new CodeSample('
<?php
class Sample
{
private function invalid_function_name(){}
}
'),
]
new CodeSample(<<<'PHP'
<?php
class Sample
{
private function invalid_function_name(){}
}

PHP
),
],
null,
null,
null,
'Paysera recommendation.'
);
}

Expand Down
32 changes: 27 additions & 5 deletions src/Fixer/PSR2/LineLengthFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,29 @@ public function getDefinition()
return new FixerDefinition(
'Checks all lines in the file, and throws warnings if they are over hard and soft limits.',
[
new CodeSample('
<?php
echo "something"."something"."something"."something"."something"."something"."some"."until here ->";
'),
]
new CodeSample(<<<'PHP'
<?php
echo "something"."something"."something"."something"."something"."something"."something"."something"."some"."until here ->";

PHP
),
new CodeSample(<<<'PHP'
<?php
echo "something"."something"."something"."something"."some"."until here ->";

PHP
,
[
'limits' => [
'soft_limit' => 60,
'hard_limit' => 40,
],
])
],
null,
null,
null,
'Paysera recommendation.'
);
}

Expand Down Expand Up @@ -162,6 +180,10 @@ protected function createConfigurationDefinition()

$limits = $limits
->setAllowedTypes(['array', 'bool'])
->setDefault([
'soft_limit' => self::DEFAULT_SOFT_LIMIT,
'hard_limit' => self::DEFAULT_HARD_LIMIT,
])
->getOption()
;

Expand Down
14 changes: 9 additions & 5 deletions src/Fixer/PhpBasic/Basic/GlobalsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ private function isGlobalFound(Tokens $tokens, $endIndex)
*/
private function addGlobalUsageWarning(Tokens $tokens, $key, $tokenIndex)
{
$tokens->insertAt($tokenIndex + 1, new Token([T_WHITESPACE, ' ']));
$tokens->insertAt($tokenIndex + 2, new Token([
T_COMMENT,
'// TODO: "' . $tokens[$key]->getContent() . '" - ' . self::CONVENTION,
]));
$tokens->insertSlices([
$tokenIndex + 1 => [
new Token([T_WHITESPACE, ' ']),
new Token([
T_COMMENT,
'// TODO: "' . $tokens[$key]->getContent() . '" - ' . self::CONVENTION,
]),
],
]);
}
}
11 changes: 6 additions & 5 deletions src/Fixer/PhpBasic/Basic/SingleClassPerFileFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens)
}

if ($classCount > 1 && !$tokens[$tokenCount - 1]->isGivenKind(T_COMMENT)) {
$tokens->insertAt(
$tokenCount,
new Token([T_COMMENT, '// TODO: "' . $tokens[$key]->getContent() . '" - ' . self::CONVENTION])
);
$tokens->insertAt($tokenCount, new Token([T_WHITESPACE, "\n"]));
$tokens->insertSlices([
$tokenCount => [
new Token([T_WHITESPACE, "\n"]),
new Token([T_COMMENT, '// TODO: "' . $tokens[$key]->getContent() . '" - ' . self::CONVENTION]),
],
]);
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/PhpBasic/CodeStyle/ChainedMethodCallsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ private function validateMethodSplits(Tokens $tokens, $startIndex, $endIndex, $i
$tokens[$i]->isGivenKind(T_OBJECT_OPERATOR)
&& $tokens[$i - 1]->equals(')')
) {
$tokens->insertAt($i, new Token([T_WHITESPACE, $indent]));
$tokens->insertSlices([$i => [new Token([T_WHITESPACE, $indent])]]);
}
}

if (!$tokens[$i - 1]->isWhitespace() && strpos($tokens[$i - 2]->getContent(), "\n") === false) {
$tokens->insertAt($i, new Token([
$tokens->insertSlices([$i => [new Token([
T_WHITESPACE,
preg_replace('/' . preg_quote($this->whitespacesConfig->getIndent(), '/') . '/', '', $indent, 1),
]));
])]]);
}

return $i;
Expand Down
8 changes: 6 additions & 2 deletions src/Fixer/PhpBasic/CodeStyle/ClassNamingFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,12 @@ private function insertComment(Tokens $tokens, $insertIndex, $className)
{
$comment = '// TODO: "' . $className . '" - ' . self::CONVENTION;
if (!$tokens[$tokens->getPrevNonWhitespace($insertIndex)]->isGivenKind(T_COMMENT)) {
$tokens->insertAt($insertIndex + 1, new Token([T_WHITESPACE, $tokens[$insertIndex]->getContent()]));
$tokens->insertAt($insertIndex + 1, new Token([T_COMMENT, $comment]));
$tokens->insertSlices([
$insertIndex + 1 => [
new Token([T_COMMENT, $comment]),
new Token([T_WHITESPACE, $tokens[$insertIndex]->getContent()]),
],
]);
}
}
}
Loading

0 comments on commit 7c1aee9

Please sign in to comment.