Skip to content

Commit

Permalink
feat: remove support of php 7.3, add test run for php 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Apr 27, 2022
1 parent 04a84a1 commit 46783e4
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 48 deletions.
42 changes: 28 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ version: 2.1
orbs:
node: circleci/[email protected]

composer_with_lowest_dependencies: &composer_with_lowest_dependencies
install_composer: &install_composer
run: |
apt-get update
apt-get -y install git zip
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
composer_update_with_lowest_dependencies: &composer_update_with_lowest_dependencies
run: |
composer update --prefer-lowest --prefer-stable
composer: &composer
composer_update: &composer_update
run: |
composer update
Expand All @@ -30,43 +40,47 @@ jobs:
php-version:
type: string
docker:
- image: "circleci/php:<< parameters.php-version >>"
- image: "php:<< parameters.php-version >>"
steps:
- checkout
- <<: *composer
- <<: *install_composer
- <<: *composer_update
- <<: *tests

tests-with-future-mode:
parameters:
php-version:
type: string
docker:
- image: "circleci/php:<< parameters.php-version >>"
- image: "php:<< parameters.php-version >>"
steps:
- checkout
- <<: *composer
- <<: *install_composer
- <<: *composer_update
- <<: *tests_with_future_mode

tests-with-lowest-dependencies:
parameters:
php-version:
type: string
docker:
- image: "circleci/php:<< parameters.php-version >>"
- image: "php:<< parameters.php-version >>"
steps:
- checkout
- <<: *composer_with_lowest_dependencies
- <<: *install_composer
- <<: *composer_update_with_lowest_dependencies
- <<: *tests

documentation:
parameters:
php-version:
type: string
docker:
- image: "circleci/php:<< parameters.php-version >>"
- image: "php:<< parameters.php-version >>"
steps:
- checkout
- <<: *composer
- <<: *install_composer
- <<: *composer_update
- run: bin/doc > README.new.md
- run: cmp --silent README.md README.new.md || cmp README.md README.new.md || (echo "Documentation is outdated. Run 'bin/doc > README.md'" && exit 1)

Expand All @@ -93,19 +107,19 @@ workflows:
- documentation:
matrix:
parameters:
php-version: ["8.0"]
php-version: ["8.1"]
- tests:
matrix:
parameters:
php-version: ["7.3", "7.4", "8.0"]
php-version: ["7.4", "8.0", "8.1"]
- tests-with-future-mode:
matrix:
parameters:
php-version: ["7.3", "7.4", "8.0"]
php-version: ["7.4", "8.0", "8.1"]
- tests-with-lowest-dependencies:
matrix:
parameters:
php-version: ["7.3", "7.4", "8.0"]
php-version: ["7.4", "8.0", "8.1"]
- release-test
- release:
requires:
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
->setRules(
RuleSetFactory::create()
->phpCsFixer(true)
->php(7.3, true)
->php(7.4, true)
->pedrotroller(true)
->enable('ordered_imports')
->enable('ordered_interfaces')
Expand Down
4 changes: 1 addition & 3 deletions bin/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +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(function ($value, $key) {
return '\''.$key.'\' => '.static::valueToString($value);
}, $array, array_keys($array)));
$string .= implode(', ', array_map(fn ($value, $key) => '\''.$key.'\' => '.static::valueToString($value), $array, array_keys($array)));
}

$string .= ' ]';
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "PHP-CS-FIXER : my custom fixers",
"license": "MIT",
"require": {
"php": "^7.3 || ^8.0",
"friendsofphp/php-cs-fixer": "^3.0"
"php": "^7.4 || ^8.0",
"friendsofphp/php-cs-fixer": "^3.7"
},
"require-dev": {
"phpspec/phpspec": "^7.0",
Expand Down
4 changes: 1 addition & 3 deletions src/PedroTroller/CS/Fixer/AbstractFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public function getDefinition(): FixerDefinitionInterface
return new FixerDefinition(
$this->getDocumentation(),
array_map(
function (array $configutation = null) {
return new CodeSample($this->getSampleCode(), $configutation);
},
fn (array $configutation = null) => new CodeSample($this->getSampleCode(), $configutation),
$this->getSampleConfigurations()
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,8 @@ private function getMethodsNames(array $elements): array

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

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

$comments = array_map(function ($comment) use ($indentation) {
return rtrim($indentation.' * '.ltrim($comment, ' /'));
}, $comments);
$comments = array_map(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, function ($value) { return null !== $value; });
$possible = array_filter($possible, fn ($value) => null !== $value);

if (empty($possible)) {
continue;
Expand Down
7 changes: 3 additions & 4 deletions src/PedroTroller/CS/Fixer/Fixers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PedroTroller\CS\Fixer;

use Generator;
use IteratorAggregate;
use PhpCsFixer\Fixer\FixerInterface;
use ReflectionClass;
Expand All @@ -14,17 +15,15 @@ final class Fixers implements IteratorAggregate
/**
* {@inheritdoc}
*/
public function getIterator(): \Generator
public function getIterator(): Generator
{
$finder = Finder::create()
->in(__DIR__)
->name('*.php')
;

$files = array_map(
function ($file) {
return $file->getPathname();
},
fn ($file) => $file->getPathname(),
iterator_to_array($finder)
);

Expand Down
8 changes: 2 additions & 6 deletions src/PedroTroller/CS/Fixer/Priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ private function __construct()
public static function before(...$classes)
{
$priorities = array_map(
function ($class) {
return (new $class())->getPriority();
},
fn ($class) => (new $class())->getPriority(),
$classes
);

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

Expand Down
2 changes: 1 addition & 1 deletion src/PedroTroller/CS/Fixer/RuleSetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private function migration($package, $version, $risky)

return self::create(array_merge(
$this->rules,
array_map(function () { return true; }, $rules)
array_map(fn () => true, $rules)
));
}
}
4 changes: 1 addition & 3 deletions tests/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ function ($type, $message, $file, $line) use (&$deprecations): void {
implode(
"\n\n",
array_map(
function ($message, array $files) {
return sprintf("%s\n%s", $message, implode("\n", $files));
},
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(),
function ($element) { return 'method' === $element['type']; }
fn ($element) => 'method' === $element['type']
);

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

0 comments on commit 46783e4

Please sign in to comment.