Skip to content

Commit

Permalink
fixup! Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
MortalFlesh committed Apr 5, 2022
1 parent 9626f57 commit c2d35a9
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 0 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
"@analyze",
"@test"
],
"cs": [
"vendor/bin/ecs check -c data/ecs.php data/ --ansi"
],
"cs-fix": [
"vendor/bin/ecs check -c data/ecs.php data/ --ansi --fix"
],
"analyze": [
"vendor/bin/ecs check src/ tests/ ecs.php ecs-7.4.php --ansi",
"vendor/bin/ecs check-markdown README.md --ansi",
Expand Down
87 changes: 87 additions & 0 deletions data/ValueObject/Name.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php declare(strict_types=1);

namespace ValueObject;

class Name
{
/** @var string */
private $first;
private ?string $middle = null;
private string $last;
/** @var mixed */
private $additional = null;
/** @var string|int */
private $age;

/** @param string|int $age */
public static function create(
string $first,
string $last,
$age
): self {
return new self(
$first,
null,
$last,
$age
);
}

/** @param string|int $age */
public function __construct(string $first, ?string $middle, string $last, $age)
{
$this->first = $first;
$this->middle = $middle;
$this->last = $last;
$this->age = $age;
}

/** @return string|int */
public function getAge()
{
return $this->age;
}

/** @param mixed $additional */
public function setAdditional($additional): void
{
$this->additional = $additional;
}

/** @return mixed */
public function getAdditional()
{
return $this->additional;
}

public function foo(): string
{
switch ($this->first) {
case 'Ondra':
return 'Ondřej';
default:
return $this->first;
}
}

public function asArray(): array
{
$values = [
$this->first,
];

$middleValue = $this->middle !== null ? new Value($this->middle) : null;
$values[] = $middleValue !== null ? $middleValue->getValue() : null;

$values[] = $this->last;

return $values;
}

public function __toString(): string
{
return $this->middle
? sprintf('%s %s', $this->first, $this->last)
: sprintf('%s %s %s', $this->first, $this->middle, $this->last);
}
}
18 changes: 18 additions & 0 deletions data/ValueObject/Value.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace ValueObject;

class Value
{
private string $value;

public function __construct(string $value)
{
$this->value = $value;
}

public function getValue(): string
{
return $this->value;
}
}
10 changes: 10 additions & 0 deletions data/ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/../ecs.php');
//$containerConfigurator->import(__DIR__ . '/../ecs-7.4.php');
$containerConfigurator->import(__DIR__ . '/../ecs-8.0.php');
$containerConfigurator->import(__DIR__ . '/../ecs-8.1.php');
};
73 changes: 73 additions & 0 deletions ecs-8.0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php declare(strict_types=1);

use SlevomatCodingStandard\Sniffs\Functions\RequireTrailingCommaInCallSniff;
use Symplify\EasyCodingStandard\ValueObject\Option;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToPropertyTypeFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use SlevomatCodingStandard\Sniffs\Classes\RequireConstructorPropertyPromotionSniff;
use SlevomatCodingStandard\Sniffs\ControlStructures\RequireNullSafeObjectOperatorSniff;
use SlevomatCodingStandard\Sniffs\Functions\RequireTrailingCommaInDeclarationSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

(function () use ($services): void {
// promote constructor properties
// @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5956
$services->set(RequireConstructorPropertyPromotionSniff::class);

// switch -> match
// @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5894

// interface \Stringable
// @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/6235
// it is more for a phpstan rule than cs rule - since it need a class hierarchy to solve this

// mixed param/return
$services->set(NoSuperfluousPhpdocTagsFixer::class)
->call(
'configure',
[
[
'allow_mixed' => false, // allow `@mixed` annotations to be preserved
'allow_unused_params' => false, // whether param annotation without actual signature is allowed
'remove_inheritdoc' => true, // remove @inheritDoc tags
],
]
);
// Takes `@var` annotation of non-mixed types and adjusts accordingly the property signature.
$services->set(PhpdocToPropertyTypeFixer::class);
// Takes `@param` annotations of non-mixed types and adjusts accordingly the function signature.
$services->set(PhpdocToParamTypeFixer::class);
// Takes `@return` annotation of non-mixed types and adjusts accordingly the function signature.
$services->set(PhpdocToReturnTypeFixer::class);
$services->set(ReturnTypeHintSniff::class);

// php docs annotation -> attributes #[...]

// union types
$services->set(UnionTypeHintFormatSniff::class);

// trailing comma
$services->set(RequireTrailingCommaInDeclarationSniff::class);
$services->set(RequireTrailingCommaInCallSniff::class);

// null-safe operator
$services->set(RequireNullSafeObjectOperatorSniff::class);
})();

$parameters = $containerConfigurator->parameters();
(function () use ($parameters): void {
$parameters->set(
Option::SKIP,
[
ReturnTypeHintSniff::class . '.' . ReturnTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION => null,
]
);
})();
};
10 changes: 10 additions & 0 deletions ecs-8.1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);

use PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToPropertyTypeFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
};
1 change: 1 addition & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@
'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.ParamNotFirst' => null,
'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.SpacingBeforeTags' => null,
'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.TagValueIndent' => null,
'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.Empty' => null,

// Skip unwanted rules from ArrayDeclarationSniff
'PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.CloseBraceNotAligned' => null,
Expand Down

0 comments on commit c2d35a9

Please sign in to comment.