Skip to content

Commit

Permalink
Tuning of php-cs-fixer configuration (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilario-pierbattista authored Apr 5, 2021
1 parent 58888b1 commit 91366ea
Show file tree
Hide file tree
Showing 43 changed files with 150 additions and 150 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: CI

on: [pull_request, push]
on:
pull_request: ~
push:
branches:
- master

jobs:
tests:
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Static analysis

on: [pull_request, push]
on:
pull_request: ~
push:
branches:
- master

jobs:
job:
Expand All @@ -10,7 +14,7 @@ jobs:
- description: Validate composer.json
script: composer validate
- description: Code style
script: make cs-fix
script: make cs-check
- description: PSalm
script: make psalm
- description: Type assertions
Expand Down
29 changes: 29 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

$rulesProvider = new Facile\CodingStandards\Rules\CompositeRulesProvider([
new Facile\CodingStandards\Rules\DefaultRulesProvider(),
new Facile\CodingStandards\Rules\RiskyRulesProvider(),
new Facile\CodingStandards\Rules\ArrayRulesProvider([
'class_attributes_separation' => false,
'declare_strict_types' => true,
'indentation_type' => true,
'phpdoc_to_comment' => false,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_align' => true,
'nullable_type_declaration_for_default_null_value' => true,
'lambda_not_used_import' => true,
'phpdoc_add_missing_param_annotation' => true
]),
]);

$finder = PhpCsFixer\Finder::create();
$autoloadPathProvider = new Facile\CodingStandards\AutoloadPathProvider();
$finder->in($autoloadPathProvider->getPaths());

$config = new PhpCsFixer\Config();
$config->setRules($rulesProvider->getRules());
$config->setRiskyAllowed(true);
$config->setUsingCache(false);
$config->setFinder($finder);

return $config;
37 changes: 0 additions & 37 deletions .php_cs.dist

This file was deleted.

18 changes: 9 additions & 9 deletions src/Codecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public static function associativeArray(array $props): Codec
* @template T
*
* @param non-empty-array<string, Codec> $props
* @param callable(...mixed):T $factory
* @param class-string<T> $fqcn
* @param callable(...mixed):T $factory
* @param class-string<T> $fqcn
*
* @return Codec<T, mixed, T>
*/
Expand All @@ -145,19 +145,19 @@ public static function classFromArray(
* @template E
* @template OE
*
* @param Codec<A, IA, mixed> $a
* @param Codec<B, A, OB> $b
* @param Codec<A, IA, mixed> $a
* @param Codec<B, A, OB> $b
* @param Codec<C, B, OC> | null $c
* @param Codec<D, C, OD> | null $d
* @param Codec<E, D, OE> | null $e
*
* // TODO must add type assertions
*
* @return (func_num_args() is 2 ? Codec<B, IA, OB>
* : (func_num_args() is 3 ? Codec<C, IA, OC>
* : (func_num_args() is 4 ? Codec<D, IA, OD>
* : (func_num_args() is 5 ? Codec<E, IA, OC> : Codec)
* )))
* : (func_num_args() is 3 ? Codec<C, IA, OC>
* : (func_num_args() is 4 ? Codec<D, IA, OD>
* : (func_num_args() is 5 ? Codec<E, IA, OC> : Codec)
* )))
*/
public static function pipe(
Codec $a,
Expand Down Expand Up @@ -185,7 +185,7 @@ public static function pipe(
public static function union(Codec $a, Codec $b, Codec ...$others): Codec
{
// Order is not important, unions should be commutatives
return array_reduce(
return \array_reduce(
$others,
static function (Codec $carry, Codec $current): Codec {
return new UnionType($current, $carry);
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Arrays/ListRefiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(Refiner $item)

public function is($u): bool
{
if (! is_array($u)) {
if (! \is_array($u)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Arrays/ListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(Codec $itemCodec)

public function validate($i, Context $context): Validation
{
if (! is_array($i)) {
if (! \is_array($i)) {
return Validation::failure(
$i,
$context->appendEntries(
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Arrays/MapRefiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class MapRefiner implements Refiner
*/
public function is($u): bool
{
return is_array($u);
return \is_array($u);
}
}
10 changes: 5 additions & 5 deletions src/Internal/Combinators/ClassFromArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ class ClassFromArray extends Type

/**
* @param non-empty-array<array-key, Codec> $props
* @param callable(...mixed):T $builder
* @param class-string<T> $fqcn
* @param callable(...mixed):T $builder
* @param class-string<T> $fqcn
*/
public function __construct(
array $props,
callable $builder,
string $fqcn
) {
parent::__construct(
sprintf('%s(%s)', $fqcn, nameFromProps($props)),
\sprintf('%s(%s)', $fqcn, nameFromProps($props)),
new InstanceOfRefiner($fqcn),
Encode::identity()
);
Expand All @@ -53,9 +53,9 @@ public function validate($i, Context $context): Validation
$validations = [];

foreach ($this->props as $k => $codec) {
$keyName = is_string($k) ? $k : sprintf('[%d]', $k);
$keyName = \is_string($k) ? $k : \sprintf('[%d]', $k);
/** @var mixed $value */
$value = array_key_exists($k, $i) ? $i[$k] : new Undefined();
$value = \array_key_exists($k, $i) ? $i[$k] : new Undefined();

$validations[] = $codec->validate($value, $context->appendEntries(new ContextEntry($keyName, $codec, $value)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Combinators/ComposeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ComposeType extends Type

/**
* @param Codec<A, IA, OA> $a
* @param Codec<B, A, OB> $b
* @param Codec<B, A, OB> $b
*/
public function __construct(
Codec $a,
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Combinators/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
Codec $a,
Codec $b
) {
$name = sprintf(
$name = \sprintf(
'%s | %s',
$a->getName(),
$b->getName()
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Experimental/AssociativeArrayRefiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(array $props)

public function is($u): bool
{
if (! is_array($u)) {
if (! \is_array($u)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Internal/PreconditionFailureExcepion.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PreconditionFailureExcepion extends \LogicException
public static function create(string $expectedType, $given): self
{
return new self(
sprintf(
\sprintf(
'Bad codec composition: expecting input to be of type "%s", given "%s"',
$expectedType,
typeof($given)
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Primitives/BoolRefiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class BoolRefiner implements Refiner
{
public function is($u): bool
{
return is_bool($u);
return \is_bool($u);
}
}
2 changes: 1 addition & 1 deletion src/Internal/Primitives/FloatRefiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class FloatRefiner implements Refiner
{
public function is($u): bool
{
return is_float($u);
return \is_float($u);
}
}
2 changes: 1 addition & 1 deletion src/Internal/Primitives/InstanceOfRefiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function __construct(string $fqcn)
*/
public function is($u): bool
{
return is_a($u, $this->fqcn);
return \is_a($u, $this->fqcn);
}
}
2 changes: 1 addition & 1 deletion src/Internal/Primitives/IntRefiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class IntRefiner implements Refiner
{
public function is($u): bool
{
return is_int($u);
return \is_int($u);
}
}
4 changes: 2 additions & 2 deletions src/Internal/Primitives/LiteralType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public function validate($i, Context $context): Validation
*/
private static function literalName($x): string
{
if (is_string($x)) {
if (\is_string($x)) {
return "'$x'";
}

if (is_bool($x)) {
if (\is_bool($x)) {
return $x ? 'true' : 'false';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Primitives/StringRefiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class StringRefiner implements Refiner
{
public function is($u): bool
{
return is_string($u);
return \is_string($u);
}
}
2 changes: 1 addition & 1 deletion src/Internal/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class Type implements Codec
private $refine;

/**
* @param Refiner<A> $refine
* @param Refiner<A> $refine
* @param Encode<A, O> $encode
*/
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Useful/DateTimeFromIsoStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct()

public function validate($i, Context $context): Validation
{
$r = \DateTime::createFromFormat(DATE_ATOM, $i);
$r = \DateTime::createFromFormat(\DATE_ATOM, $i);

if ($r === false) {
return Validation::failure($i, $context);
Expand Down
4 changes: 2 additions & 2 deletions src/Internal/Useful/IntFromStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public function __construct()

public function validate($i, Context $context): Validation
{
return is_numeric($i)
return \is_numeric($i)
? Validation::success((int) $i)
: Validation::failure($i, $context);
}

public function forceCheckPrecondition($i)
{
if (! is_string($i)) {
if (! \is_string($i)) {
throw PreconditionFailureExcepion::create('string', $i);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Internal/Useful/RegexType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RegexType extends Type
public function __construct(string $regex)
{
parent::__construct(
sprintf('regex(%s)', $regex),
\sprintf('regex(%s)', $regex),
new MapRefiner(),
Encode::identity()
);
Expand All @@ -32,7 +32,7 @@ public function __construct(string $regex)
public function validate($i, Context $context): Validation
{
$matches = [];
if (preg_match($this->regex, $i, $matches) === false) {
if (\preg_match($this->regex, $i, $matches) === false) {
return Validation::failure($i, $context);
}

Expand All @@ -47,7 +47,7 @@ public function validate($i, Context $context): Validation
*/
public function forceCheckPrecondition($i)
{
if (! is_string($i)) {
if (! \is_string($i)) {
throw PreconditionFailureExcepion::create('string', $i);
}

Expand Down
18 changes: 9 additions & 9 deletions src/Internal/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
*/
function nameFromProps(array $props): string
{
return sprintf(
return \sprintf(
'{%s}',
implode(
\implode(
', ',
array_map(
\array_map(
static function (Codec $t, $k): string {
return sprintf(
return \sprintf(
'%s: %s',
is_string($k) ? $k : sprintf('[%d]', $k),
\is_string($k) ? $k : \sprintf('[%d]', $k),
$t->getName()
);
},
$props,
array_keys($props)
\array_keys($props)
)
)
);
Expand All @@ -35,9 +35,9 @@ static function (Codec $t, $k): string {
*/
function typeof($x): string
{
if (is_object($x)) {
return get_class($x);
if (\is_object($x)) {
return \get_class($x);
}

return gettype($x);
return \gettype($x);
}
Loading

0 comments on commit 91366ea

Please sign in to comment.