Skip to content
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

[QA] Add PHP-CS-Fixer #87

Merged
merged 2 commits into from
Oct 15, 2020
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ jobs:

- name: "checking coding standards ( codesniffer )"
run: "composer cs:check"

- name: "checking coding standards ( php-cs-fixer )"
run: "composer cs-fixer:check"
52 changes: 52 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

return PhpCsFixer\Config::create()
->setFinder(
\Symfony\Component\Finder\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
)
->setRiskyAllowed(true)
->setRules([
'align_multiline_comment' => true,
'array_indentation' => true,
'declare_strict_types' => true,
// Currently it is not possible to mark all classes as final (exceptions etc.)
// We can run this fixer periodically on the tests folder only.
// 'final_class' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
],
'list_syntax' => [
'syntax' => 'short',
],
'lowercase_constants' => true,
'multiline_comment_opening_closing' => true,
'native_function_casing' => true,
'no_empty_phpdoc' => true,
'no_leading_import_slash' => true,
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true,
],
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
],
'ordered_interfaces' => true,
'php_unit_test_annotation' => true,
'php_unit_test_case_static_method_calls' => [
'call_type' => 'static',
],
'single_import_per_statement' => true,
'single_trait_insert_per_statement' => true,
'static_lambda' => true,
'strict_comparison' => true,
'strict_param' => true,
])
;
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
"require": {
"php": "^7.4",
"ext-bcmath": "*",
"ext-mbstring": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-sodium": "*"
},
"require-dev": {
"vimeo/psalm": "dev-master",
"phpunit/phpunit": "^9.0",
"php-coveralls/php-coveralls": "^2.2",
"friendsofphp/php-cs-fixer": "^2.16",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "^3.5"
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "dev-master"
},
"autoload": {
"psr-4": {
Expand All @@ -39,19 +40,23 @@
"scripts": {
"cs:fix": "phpcbf",
"cs:check": "phpcs",
"cs-fixer:fix": "php-cs-fixer fix",
"cs-fixer:check": "php-cs-fixer fix --dry-run",
"type:check": "psalm",
"type:coverage": "psalm --shepherd",
"test:unit": "phpunit",
"code:coverage": "php-coveralls -v",
"security:analysis": "psalm --taint-analysis",
"check": [
"@cs-fixer:check",
"@cs:check",
"@type:check",
"@security:analysis",
"@test:unit"
]
},
"config": {
"process-timeout": 1200
"process-timeout": 1200,
"sort-packages": true
}
}
4 changes: 3 additions & 1 deletion src/Psl/Arr/contains_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Psl\Arr;

use function array_key_exists;

/**
* Returns true if the given array contains the key.
*
Expand All @@ -17,5 +19,5 @@
*/
function contains_key(array $array, $key): bool
{
return \array_key_exists($key, $array);
return array_key_exists($key, $array);
}
1 change: 0 additions & 1 deletion src/Psl/Arr/drop.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Psl\Arr;

use Generator;
use Psl;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Psl/Arr/first_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Psl\Arr;

use function array_key_first;

/**
* Get the first key of an array, if the array is empty, null will be returned.
*
Expand All @@ -17,5 +19,5 @@
*/
function first_key(array $array)
{
return \array_key_first($array);
return array_key_first($array);
}
1 change: 0 additions & 1 deletion src/Psl/Arr/group_by.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Psl\Arr;

use Psl;
use Psl\Str;
use Psl\Type;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Psl/Arr/keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Psl\Arr;

use function array_keys;

/**
* Return all the keys of an array.
*
Expand All @@ -18,5 +20,5 @@
*/
function keys(array $arr): array
{
return \array_keys($arr);
return array_keys($arr);
}
1 change: 0 additions & 1 deletion src/Psl/Arr/sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* @psalm-param array<Tk, Tv> $array
* @psalm-param (callable(Tv, Tv): int)|null $comparator
*
* @return array
*
* @psalm-return list<Tv>
*/
Expand Down
7 changes: 5 additions & 2 deletions src/Psl/Arr/sort_by.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Psl\Arr;

use function asort;
use function uasort;

/**
* Returns a new array sorted by some scalar property of each value of the given
* iterable, which is computed by the given function.
Expand Down Expand Up @@ -33,9 +36,9 @@ function sort_by(iterable $iterable, callable $scalar_func, ?callable $comparato
}

if (null !== $comparator) {
\uasort($order_by, $comparator);
uasort($order_by, $comparator);
} else {
\asort($order_by);
asort($order_by);
}

$result = [];
Expand Down
7 changes: 5 additions & 2 deletions src/Psl/Arr/sort_by_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Psl\Arr;

use function ksort;
use function uksort;

/**
* Returns a new array sorted by the keys of the given array. If the
* optional comparator function isn't provided, the keys will be sorted in
Expand All @@ -20,9 +23,9 @@
function sort_by_key(array $array, ?callable $comparator = null): array
{
if ($comparator) {
\uksort($array, $comparator);
uksort($array, $comparator);
} else {
\ksort($array);
ksort($array);
}

return $array;
Expand Down
7 changes: 5 additions & 2 deletions src/Psl/Arr/sort_with_keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Psl\Arr;

use function asort;
use function uasort;

/**
* Returns a new array sorted by the values of the given array. If the
* optional comparator function isn't provided, the values will be sorted in
Expand All @@ -20,9 +23,9 @@
function sort_with_keys(array $array, ?callable $comparator = null): array
{
if (null !== $comparator) {
\uasort($array, $comparator);
uasort($array, $comparator);
} else {
\asort($array);
asort($array);
}

return $array;
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Arr/sort_with_keys_by.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function sort_with_keys_by(iterable $iterable, callable $scalar_func, ?callable
* @psalm-param array{0: Ts, 1: Tv} $a
* @psalm-param array{0: Ts, 1: Tv} $b
*/
fn ($a, $b): int => $comparator($a[0], $b[0]);
static fn ($a, $b): int => $comparator($a[0], $b[0]);

/**
* @psalm-var array<Tk, array{0: Ts, 1: Tv}> $tuples
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/Arr/unique_by.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Psl\Arr;

use Psl;

/**
* Returns a new array in which each value appears exactly once, where the
* value's uniqueness is determined by transforming it to a scalar via the
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Collection/MutableVectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @extends VectorInterface<T>
* @extends MutableAccessibleCollectionInterface<int, T>
*/
interface MutableVectorInterface extends VectorInterface, MutableAccessibleCollectionInterface
interface MutableVectorInterface extends MutableAccessibleCollectionInterface, VectorInterface
{
/**
* Get an array copy of the current vector.
Expand Down
3 changes: 0 additions & 3 deletions src/Psl/DataStructure/PriorityQueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Psl\DataStructure;

use Psl;
use Countable;

/**
* @template T
*
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/DataStructure/QueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Psl\DataStructure;

use Psl;
use Countable;
use Psl;

/**
* An interface representing a queue data structure ( FIFO ).
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/DataStructure/StackInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Psl\DataStructure;

use Psl;
use Countable;
use Psl;

/**
* An interface representing a stack data structure ( LIFO ).
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/Env/get_vars.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Psl\Env;

use Psl;

use function getenv;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Psl/Env/set_current_dir.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/**
* Changes the current working directory to the specified path.
*
* @param string $directory
*
* @throws Psl\Exception\InvariantViolationException If the operation fails.
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/Env/temp_dir.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Psl\Env;

use Psl;

use function sys_get_temp_dir;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Psl/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Psl\Exception;

use Throwable;

/**
* @internal
*/
interface ExceptionInterface extends \Throwable
interface ExceptionInterface extends Throwable
{
}
4 changes: 1 addition & 3 deletions src/Psl/Internal/internal_encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
namespace Psl\Internal;

use Psl;
use Psl\Type;
use Psl\Exception;
use Psl\Type;

use function in_array;
use function mb_internal_encoding;
use function mb_list_encodings;

/**
* @psalm-pure
Expand Down
5 changes: 0 additions & 5 deletions src/Psl/Internal/is_encoding_valid.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

namespace Psl\Internal;

use Psl;
use Psl\Type;
use Psl\Exception;

use function in_array;
use function mb_internal_encoding;
use function mb_list_encodings;

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/Internal/type.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
/**
* @param mixed $value
*
* @return string
*
* @psalm-pure
*
* @codeCoverageIgnore
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Iter/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @implements SeekableIterator<Tk, Tv>
*/
final class Iterator implements SeekableIterator, Countable
final class Iterator implements Countable, SeekableIterator
{
/**
* @psalm-var Generator<Tk, Tv, mixed, mixed>
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/Iter/contains_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Psl\Iter;

use Psl\Arr;

/**
* Returns true if the given iterable contains the key.
*
Expand Down
Loading