-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9626f57
commit c2d35a9
Showing
7 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
] | ||
); | ||
})(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters