Skip to content

Replace PHP-CS-Fixer with ECS #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.2
tools: composer

- name: Get composer cache directory
Expand All @@ -33,5 +33,5 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist

- name: PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix --dry-run -v
- name: ECS
run: vendor/bin/ecs
2 changes: 1 addition & 1 deletion .php-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.4
7.1
2 changes: 0 additions & 2 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

declare(strict_types=1);

require_once dirname(__DIR__).'/vendor/autoload.php';

function getCode(SplFileInfo $file): string
{
$code = php_strip_whitespace($file->getRealPath());
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"symfony/property-access": "^2.7 | ^3.0 | ^4.0 | ^5.0"
},
"require-dev": {
"phpdocumentor/reflection-docblock": "*",
"phpdocumentor/reflection-docblock": "^4.3 || 5.2",
"phpstan/phpdoc-parser": "*",
"phpunit/phpunit": "^7.3 || ^8.4",
"phpstan/phpstan": "^0.12",
"friendsofphp/php-cs-fixer": "^2.12"
"phpstan/phpstan": "*",
"symplify/easy-coding-standard": ">=10.0,<= 13.0"
}
}
77 changes: 77 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SolidWorx Lodash-PHP project.
*
* @author Pierre du Plessis <open-source@solidworx.co>
* @copyright Copyright (c) 2017
*/

use PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer;
use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer;
use PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer;
use PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer;
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
use PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer;
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\LanguageConstruct\ExplicitIndirectVariableFixer;
use PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer;
use PhpCsFixer\Fixer\Operator\NewWithBracesFixer;
use PhpCsFixer\Fixer\Operator\StandardizeIncrementFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer;
use PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
__FILE__,
]);

$ecsConfig->sets([
SetList::PSR_12,
SetList::SPACES,
SetList::DOCBLOCK,
SetList::COMMENTS,
SetList::PHPUNIT,
SetList::NAMESPACES,
SetList::CLEAN_CODE,
]);

$ecsConfig->rules([
PhpUnitMethodCasingFixer::class,
FunctionToConstantFixer::class,
ExplicitStringVariableFixer::class,
ExplicitIndirectVariableFixer::class,
NewWithBracesFixer::class,
StandardizeIncrementFixer::class,
SelfAccessorFixer::class,
MagicConstantCasingFixer::class,
NoUselessElseFixer::class,
SingleQuoteFixer::class,
// VoidReturnFixer::class,
]);

$header = <<<'EOF'
This file is part of the SolidWorx Lodash-PHP project.

@author Pierre du Plessis <open-source@solidworx.co>
@copyright Copyright (c) 2017
EOF;

$ecsConfig->ruleWithConfiguration(SingleClassElementPerStatementFixer::class, ['elements' => ['const', 'property']]);
$ecsConfig->ruleWithConfiguration(ClassDefinitionFixer::class, ['single_line' => \true]);
$ecsConfig->ruleWithConfiguration(OrderedImportsFixer::class, ['imports_order' => ['const', 'class', 'function']]);
$ecsConfig->ruleWithConfiguration(HeaderCommentFixer::class, [
'comment_type' => 'comment',
'header' => \trim($header),
'location' => 'after_declare_strict',
'separate' => 'both',
]);
};
5 changes: 2 additions & 3 deletions src/Array/differenceBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*
* @param array $array The array to inspect.
* @param array<int, mixed> ...$values The values to exclude.
* @param callable $iteratee The iteratee invoked per element.
*
* @return array Returns the new array of filtered values.
*
Expand All @@ -38,11 +37,11 @@
*/
function differenceBy(array $array, ...$values): array
{
if (!$array) {
if (! $array) {
return [];
}

if (!\is_callable(\end($values))) {
if (! \is_callable(\end($values))) {
return difference($array, ...$values);
}

Expand Down
5 changes: 2 additions & 3 deletions src/Array/differenceWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*
* @param array<int, mixed> $array The array to inspect.
* @param array ...$values The values to exclude.
* @param callable $comparator The comparator invoked per element.
*
* @return array Returns the new array of filtered values.
*
Expand All @@ -41,11 +40,11 @@
*/
function differenceWith(array $array, ...$values): array
{
if (!$array) {
if (! $array) {
return [];
}

if (!\is_callable(\end($values))) {
if (! \is_callable(\end($values))) {
return difference($array, ...$values);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Array/findIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
function findIndex(array $array, $predicate, int $fromIndex = null): int
{
$length = \count($array);
if (!$length) {
if (! $length) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Array/fromPairs.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
function fromPairs(array $pairs): \stdClass
{
if (!\count($pairs)) {
if (! \count($pairs)) {
return new \stdClass();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Array/indexOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function indexOf(array $array, $value, int $fromIndex = null): int
$array = \array_reverse($array, false);
$inc = false;
}
};
}

foreach ($array as $v) {
if (isEqual($value, $v)) {
Expand Down
2 changes: 0 additions & 2 deletions src/Array/intersection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*
* @category Array
*
* @param array ...$arrays
*
* @return array the new array of intersecting values.
*
* @example
Expand Down
1 change: 0 additions & 1 deletion src/Array/intersectionBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* @category Array
*
* @param array<int, mixed> ...$arrays
* @param callable $iteratee The iteratee invoked per element.
*
* @return array the new array of intersecting values.
* @example
Expand Down
3 changes: 1 addition & 2 deletions src/Array/intersectionWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* @category Array
*
* @param array ...$arrays
* @param callable $comparator The comparator invoked per element.
*
* @return array the new array of intersecting values.
*
Expand All @@ -40,7 +39,7 @@ function intersectionWith(...$arrays /*, callable $comparator = null*/): array
$copy = $arrays;
$comparator = \array_pop($arrays);

if (!\is_callable($comparator)) {
if (! \is_callable($comparator)) {
$arrays = $copy;
$comparator = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Array/lastIndexOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function lastIndexOf(array $array, $value, int $fromIndex = null): int
if (null !== $fromIndex) {
$index = $fromIndex > 0 ? $fromIndex : \count($array) - 1;
$array = \array_slice($array, 0, -$fromIndex + 1);
};
}

foreach (\array_reverse($array, false) as $v) {
if (isEqual($value, $v)) {
Expand Down
4 changes: 1 addition & 3 deletions src/Array/pull.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
* @param array $array The array to modify.
* @param array<int, string> $values The values to remove.
*
* @return array
*
* @example
* <code>
* $array = ['a', 'b', 'c', 'a', 'b', 'c']
Expand All @@ -38,7 +36,7 @@
function pull(array &$array, ...$values): array
{
$array = \array_filter($array, function ($val) use ($values) {
return !\in_array($val, $values, true);
return ! \in_array($val, $values, true);
});

$array = \array_values($array); // Re-index array
Expand Down
2 changes: 1 addition & 1 deletion src/Array/pullAt.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function pullAt(array &$array, $indexes): array
$pulled[] = $val;
}

return !$inArray;
return ! $inArray;
}, \ARRAY_FILTER_USE_BOTH);

$array = \array_values($array);
Expand Down
2 changes: 1 addition & 1 deletion src/Array/remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function remove(array &$array, callable $predicate): array
$resultArray[] = $val;
}

return !$result;
return ! $result;
}, \ARRAY_FILTER_USE_BOTH);

$array = \array_values($array); // Re-index array
Expand Down
1 change: 0 additions & 1 deletion src/Array/unionBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* @category Array
*
* @param array<int, mixed> ...$arrays The arrays to inspect.
* @param callable $iteratee The iteratee invoked per element.
*
* @return array the new array of combined values.
*
Expand Down
7 changes: 3 additions & 4 deletions src/Array/unionWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* @category Array
*
* @param array<int, mixed> ...$arrays The arrays to inspect.
* @param callable $comparator The comparator invoked per element.
*
* @return array the new array of combined values.
*
Expand All @@ -38,13 +37,13 @@
* // => [['x' => 1, 'y' => 2], ['x' => 2, 'y' => 1], ['x' => 1, 'y' => 1]]
* </code>
*/
function unionWith(... $arrays): array
function unionWith(...$arrays): array
{
/** @var callable $comparator */
$comparator = \array_pop($arrays);

if (!\is_callable($comparator)) {
throw new \InvalidArgumentException(__FUNCTION__.' expects the last value passed to be callable');
if (! \is_callable($comparator)) {
throw new \InvalidArgumentException(__FUNCTION__ . ' expects the last value passed to be callable');
}

return baseUniq(baseFlatten($arrays, 1, '\is_array', true), null, $comparator);
Expand Down
2 changes: 1 addition & 1 deletion src/Array/unzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
function unzip(array $array): array
{
if (!\count($array)) {
if (! \count($array)) {
return [];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Array/unzipWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
*/
function unzipWith(array $array, ?callable $iteratee = null): array
{
if (!\count($array)) {
if (! \count($array)) {
return [];
}

$result = unzip($array);
if (!is_callable($iteratee)) {
if (! is_callable($iteratee)) {
return $result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Array/zipObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
function zipObject(array $props = [], array $values = [])
{
$result = new \stdClass;
$result = new \stdClass();
$index = -1;
$length = \count($props);
$props = \array_values($props);
Expand Down
2 changes: 1 addition & 1 deletion src/Array/zipObjectDeep.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
function zipObjectDeep(array $props = [], array $values = []): \stdClass
{
$result = new \stdClass;
$result = new \stdClass();
$index = -1;
$length = \count($props);
$props = \array_values($props);
Expand Down
1 change: 0 additions & 1 deletion src/Array/zipWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* @category Array
*
* @param array<int, array|callable> ...$arrays The arrays to process.
* @param callable $iteratee The function to combine grouped values.
*
* @return array the new array of grouped elements.
*
Expand Down
4 changes: 2 additions & 2 deletions src/CacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* This file is part of the SolidWorx Lodash-PHP project.
*
* @author Pierre du Plessis <open-source@solidworx.co>
* @copyright Copyright (c) 2018
* @copyright Copyright (c) 2017
*/

namespace _;

interface CacheInterface
{
public function set($key, $value): CacheInterface;
public function set($key, $value): self;

public function get($key);

Expand Down
2 changes: 1 addition & 1 deletion src/Collection/countBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
function countBy(iterable $collection, callable $iteratee): array
{
return createAggregator(function ($result, $key, $value) {
if (!isset($result[$value])) {
if (! isset($result[$value])) {
$result[$value] = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Collection/every.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function every(iterable $collection, $predicate): bool
$iteratee = baseIteratee($predicate);

foreach ($collection as $key => $value) {
if (!$iteratee($value, $key, $collection)) {
if (! $iteratee($value, $key, $collection)) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/groupBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
function groupBy(iterable $collection, $iteratee): array
{
return createAggregator(function ($result, $value, $key) {
if (!isset($result[$key])) {
if (! isset($result[$key])) {
$result[$key] = [];
}

Expand Down
Loading