diff --git a/.circleci/config.yml b/.circleci/config.yml index f4c8625..a38433d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -93,19 +93,19 @@ workflows: - documentation: matrix: parameters: - php-version: ["7.4"] + php-version: ["8.0"] - tests: matrix: parameters: - php-version: ["7.2", "7.3", "7.4"] + php-version: ["7.3", "7.4", "8.0"] - tests-with-future-mode: matrix: parameters: - php-version: ["7.2", "7.3", "7.4"] + php-version: ["7.3", "7.4", "8.0"] - tests-with-lowest-dependencies: matrix: parameters: - php-version: ["7.2", "7.3", "7.4"] + php-version: ["7.3", "7.4", "8.0"] - release-test - release: requires: diff --git a/.github/semantic.yml b/.github/semantic.yml index dc25441..fd37cb6 100644 --- a/.github/semantic.yml +++ b/.github/semantic.yml @@ -2,7 +2,6 @@ titleAndCommits: true types: - - "BREAKING CHANGE" - feat - fix - docs diff --git a/.gitignore b/.gitignore index d1e7c15..f796c8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -.php_cs.cache -composer.lock -node_modules -vendor +/.php-cs-fixer.cache +/.php-cs-fixer.php +/composer.lock +/node_modules/ +/vendor/ diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 80% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 35353f3..f5b453c 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -5,24 +5,26 @@ use PedroTroller\CS\Fixer\Fixers; use PedroTroller\CS\Fixer\RuleSetFactory; -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) ->setRiskyAllowed(true) ->setRules( RuleSetFactory::create() ->phpCsFixer(true) - ->php(7.2, true) + ->php(7.3, true) ->pedrotroller(true) ->enable('ordered_imports') ->enable('ordered_interfaces') ->enable('align_multiline_comment') ->enable('array_indentation') ->enable('no_superfluous_phpdoc_tags') + ->enable('simplified_null_return') ->enable('binary_operator_spaces', [ 'operators' => [ '=' => 'align_single_space_minimal', '=>' => 'align_single_space_minimal', ], ]) + ->disable('simplified_null_return') ->getRules() ) ->setUsingCache(false) @@ -30,6 +32,6 @@ ->setFinder( PhpCsFixer\Finder::create() ->in(__DIR__) - ->append([__FILE__]) + ->append([__FILE__, __DIR__.'/bin/doc']) ) ; diff --git a/.releaserc b/.releaserc index bf9f4e0..1c4fde0 100644 --- a/.releaserc +++ b/.releaserc @@ -3,15 +3,13 @@ plugins: - - '@semantic-release/commit-analyzer' - releaseRules: - - type: BREAKING CHANGE - release: major - - type: feat - release: minor - - type: fix - release: patch - - scope: deps - release: minor - - scope: deps-dev - release: false + - type: feat + release: minor + - type: fix + release: patch + - scope: deps + release: minor + - scope: deps-dev + release: false - '@semantic-release/release-notes-generator' - '@semantic-release/github' diff --git a/README.md b/README.md index b7aa8d4..6b9648a 100644 --- a/README.md +++ b/README.md @@ -385,7 +385,7 @@ Prohibited functions MUST BE commented on as prohibited ### Available options - `functions` (*optional*): The function names to be marked how prohibited - - default: `var_dump`, `dump` + - default: `var_dump`, `dump`, `die` - `comment` (*optional*): The prohibition message to put in the comment - default: `@TODO remove this line` @@ -517,7 +517,7 @@ If the declaration of a method is too long, the arguments of this method MUST BE - `max-length` (*optional*): The maximum number of characters allowed with splitting the arguments into several lines - default: `120` - - `automatic-argument-merge` (*optional*): If both conditions are met (the line is not too long and there are not too many arguments), then the arguments are put back inline. + - `automatic-argument-merge` (*optional*): If both conditions are met (the line is not too long and there are not too many arguments), then the arguments are put back inline - default: `true` ### Configuration examples @@ -828,146 +828,6 @@ return $config; // ``` -## PedroTroller/single_line_comment - -PHP comments on a single line MUST BE reduced or expanded (according to the specified strategy) - -**DEPRECATED** -replaced by `single_line_comment_style`. - - -### Available options - - - `action` (*optional*): The strategy to be applied - - allowed: `expanded`, `collapsed` - - default: `expanded` - - - `types` (*optional*): The types of comments on which the strategy should be applied - - default: `@var`, `@return`, `@param` - -### Configuration examples - -```php -// .php_cs.dist -setRules( - [ - // ... - 'PedroTroller/single_line_comment' => [ 'action' => 'expanded' ], - // ... - ] -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` -**OR** using my [rule list builder](doc/rule-set-factory.md). -```php -// .php_cs.dist -setRules( - PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/single_line_comment', [ 'action' => 'expanded' ]) - ->getRules() -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` - -### Configuration examples - -```php -// .php_cs.dist -setRules( - [ - // ... - 'PedroTroller/single_line_comment' => [ 'action' => 'collapsed' ], - // ... - ] -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` -**OR** using my [rule list builder](doc/rule-set-factory.md). -```php -// .php_cs.dist -setRules( - PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/single_line_comment', [ 'action' => 'collapsed' ]) - ->getRules() -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` - - -## PedroTroller/useless_comment - -Comments that do not provide more precision than the definition of a method MUST BE deleted - -**DEPRECATED** -replaced by `no_superfluous_phpdoc_tags`. - -### Configuration examples - -```php -// .php_cs.dist -setRules( - [ - // ... - 'PedroTroller/useless_comment' => true, - // ... - ] -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` -**OR** using my [rule list builder](doc/rule-set-factory.md). -```php -// .php_cs.dist -setRules( - PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/useless_comment') - ->getRules() -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` - - ## PedroTroller/useless_code_after_return All `return` that are not accessible (i.e. following another `return`) MUST BE deleted @@ -1209,276 +1069,6 @@ return $config; // ``` -## PedroTroller/ordered_spec_elements - -The methods of the phpspec specification classes MUST BE sorted (let, letGo, its_*, it_*, getMatchers and the rest of the methods) - -**DEPRECATED** -replaced by `PedroTroller/phpspec`. - - -### Available options - - - `instanceof` (*optional*): Parent classes of your spec classes. - - default: `PhpSpec\ObjectBehavior` - -### Configuration examples - -```php -// .php_cs.dist -setRules( - [ - // ... - 'PedroTroller/ordered_spec_elements' => true, - // ... - ] -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` -**OR** using my [rule list builder](doc/rule-set-factory.md). -```php -// .php_cs.dist -setRules( - PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/ordered_spec_elements') - ->getRules() -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` - -### Configuration examples - -```php -// .php_cs.dist -setRules( - [ - // ... - 'PedroTroller/ordered_spec_elements' => [ 'instanceof' => [ 'PhpSpec\ObjectBehavior' ] ], - // ... - ] -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` -**OR** using my [rule list builder](doc/rule-set-factory.md). -```php -// .php_cs.dist -setRules( - PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/ordered_spec_elements', [ 'instanceof' => [ 'PhpSpec\ObjectBehavior' ] ]) - ->getRules() -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` - - -## PedroTroller/phpspec_scenario_return_type_declaration - -Phpspec scenario functions MUST NOT have a return type declaration. - -**DEPRECATED** -replaced by `PedroTroller/phpspec`. - - -### Available options - - - `instanceof` (*optional*): Parent classes of your spec classes. - - default: `PhpSpec\ObjectBehavior` - -### Configuration examples - -```php -// .php_cs.dist -setRules( - [ - // ... - 'PedroTroller/phpspec_scenario_return_type_declaration' => true, - // ... - ] -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` -**OR** using my [rule list builder](doc/rule-set-factory.md). -```php -// .php_cs.dist -setRules( - PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/phpspec_scenario_return_type_declaration') - ->getRules() -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` - -### Configuration examples - -```php -// .php_cs.dist -setRules( - [ - // ... - 'PedroTroller/phpspec_scenario_return_type_declaration' => [ 'instanceof' => [ 'PhpSpec\ObjectBehavior' ] ], - // ... - ] -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` -**OR** using my [rule list builder](doc/rule-set-factory.md). -```php -// .php_cs.dist -setRules( - PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/phpspec_scenario_return_type_declaration', [ 'instanceof' => [ 'PhpSpec\ObjectBehavior' ] ]) - ->getRules() -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` - - -## PedroTroller/phpspec_scenario_scope - -Phpspec scenario functions MUST NOT have a scope. - -**DEPRECATED** -replaced by `PedroTroller/phpspec`. - - -### Available options - - - `instanceof` (*optional*): Parent classes of your spec classes. - - default: `PhpSpec\ObjectBehavior` - -### Configuration examples - -```php -// .php_cs.dist -setRules( - [ - // ... - 'PedroTroller/phpspec_scenario_scope' => true, - // ... - ] -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` -**OR** using my [rule list builder](doc/rule-set-factory.md). -```php -// .php_cs.dist -setRules( - PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/phpspec_scenario_scope') - ->getRules() -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` - -### Configuration examples - -```php -// .php_cs.dist -setRules( - [ - // ... - 'PedroTroller/phpspec_scenario_scope' => [ 'instanceof' => [ 'PhpSpec\ObjectBehavior' ] ], - // ... - ] -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` -**OR** using my [rule list builder](doc/rule-set-factory.md). -```php -// .php_cs.dist -setRules( - PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/phpspec_scenario_scope', [ 'instanceof' => [ 'PhpSpec\ObjectBehavior' ] ]) - ->getRules() -); -$config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); -// ... - -return $config; -``` - - ## PedroTroller/phpspec Phpspec scenario functions MUST NOT have a return type declaration. @@ -1668,4 +1258,4 @@ composer tests ```bash bin/doc > README.md -``` +``` \ No newline at end of file diff --git a/bin/doc b/bin/doc index cf1ac3e..93f44af 100755 --- a/bin/doc +++ b/bin/doc @@ -2,14 +2,16 @@ $fixer->isDeprecated(), 'replacement' => $fixer->getDeprecationReplacement(), - 'options' => array_map( + 'options' => array_map( function (FixerOptionInterface $option) { return [ - 'name' => $option->getName(), - 'description' => $option->getDescription(), - 'required' => false === $option->hasDefault(), + 'name' => $option->getName(), + 'description' => $option->getDescription(), + 'required' => false === $option->hasDefault(), 'allowedValues' => $option->getAllowedValues(), - 'allowedTypes' => $option->getAllowedTypes(), - 'defaultValue' => $option->getDefault(), + 'allowedTypes' => $option->getAllowedTypes(), + 'defaultValue' => $option->getDefault(), ]; }, - $fixer instanceof ConfigurationDefinitionFixerInterface - ? $fixer->getConfigurationDefinition() ->getOptions() + $fixer instanceof ConfigurableFixerInterface + ? $fixer->getConfigurationDefinition()->getOptions() : [] ), - 'samples' => array_map(function (CodeSample $sample) use ($fixer) { + 'samples' => array_map(function (CodeSample $sample) use ($fixer) { if ($fixer instanceof ConfigurableFixerInterface) { $fixer->configure($sample->getConfiguration()); } @@ -74,13 +76,13 @@ $fixers = array_map(function (AbstractFixer $fixer) { 'diff' => implode("\n", $diff), 'configuration' => $sample->getConfiguration() ? Utils::arrayToString($sample->getConfiguration()) - : null, + : [], ]; }, $samples), ]; }, iterator_to_array(new PedroTroller\CS\Fixer\Fixers())); -$loader = new Twig_Loader_Filesystem(__DIR__); -$twig = new Twig_Environment($loader); +$loader = new FilesystemLoader([__DIR__]); +$twig = new Environment($loader); echo $twig->render('doc.twig', ['fixers' => json_decode(json_encode($fixers))]); diff --git a/bin/doc.twig b/bin/doc.twig index 98101f4..a48c273 100644 --- a/bin/doc.twig +++ b/bin/doc.twig @@ -131,4 +131,4 @@ composer tests ```bash bin/doc > README.md -``` +``` \ No newline at end of file diff --git a/composer.json b/composer.json index 9822864..dc059bc 100644 --- a/composer.json +++ b/composer.json @@ -3,13 +3,13 @@ "description": "PHP-CS-FIXER : my custom fixers", "license": "MIT", "require": { - "php": ">=7.2", - "friendsofphp/php-cs-fixer": "^2.18" + "php": "^7.3 || ^8.0", + "friendsofphp/php-cs-fixer": "^3.0" }, "require-dev": { - "phpspec/phpspec": "^6.1", - "twig/twig": "^2.11.3", - "webmozart/assert": "^1.3.0" + "phpspec/phpspec": "^7.0", + "twig/twig": "^3.3", + "webmozart/assert": "^1.10" }, "autoload": { "psr-4": { @@ -27,7 +27,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "3.x-dev" } }, "minimum-stability": "dev", diff --git a/spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php b/spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php index 7e2799f..2324e0d 100644 --- a/spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php +++ b/spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php @@ -78,14 +78,12 @@ function it_adds_a_php_version_support() { $this->php(5.6)->getRules()->shouldReturn([ '@PHP54Migration' => true, - '@PHP56Migration' => true, 'array_syntax' => ['syntax' => 'short'], 'list_syntax' => ['syntax' => 'long'], ]); $this->php(5.6, true)->getRules()->shouldReturn([ '@PHP54Migration' => true, - '@PHP56Migration' => true, '@PHP56Migration:risky' => true, 'array_syntax' => ['syntax' => 'short'], 'list_syntax' => ['syntax' => 'long'], @@ -93,7 +91,6 @@ function it_adds_a_php_version_support() $this->php(7.0)->getRules()->shouldReturn([ '@PHP54Migration' => true, - '@PHP56Migration' => true, '@PHP70Migration' => true, 'array_syntax' => ['syntax' => 'short'], 'list_syntax' => ['syntax' => 'long'], @@ -101,7 +98,6 @@ function it_adds_a_php_version_support() $this->php(7.0, true)->getRules()->shouldReturn([ '@PHP54Migration' => true, - '@PHP56Migration' => true, '@PHP56Migration:risky' => true, '@PHP70Migration' => true, '@PHP70Migration:risky' => true, @@ -111,7 +107,6 @@ function it_adds_a_php_version_support() $this->php(7.1)->getRules()->shouldReturn([ '@PHP54Migration' => true, - '@PHP56Migration' => true, '@PHP70Migration' => true, '@PHP71Migration' => true, 'array_syntax' => ['syntax' => 'short'], @@ -120,7 +115,6 @@ function it_adds_a_php_version_support() $this->php(7.1, true)->getRules()->shouldReturn([ '@PHP54Migration' => true, - '@PHP56Migration' => true, '@PHP56Migration:risky' => true, '@PHP70Migration' => true, '@PHP70Migration:risky' => true, @@ -132,7 +126,6 @@ function it_adds_a_php_version_support() $this->php(7.2)->getRules()->shouldReturn([ '@PHP54Migration' => true, - '@PHP56Migration' => true, '@PHP70Migration' => true, '@PHP71Migration' => true, 'array_syntax' => ['syntax' => 'short'], @@ -141,7 +134,6 @@ function it_adds_a_php_version_support() $this->php(7.2, true)->getRules()->shouldReturn([ '@PHP54Migration' => true, - '@PHP56Migration' => true, '@PHP56Migration:risky' => true, '@PHP70Migration' => true, '@PHP70Migration:risky' => true, @@ -156,7 +148,6 @@ function it_can_also_parse_versions_as_string() { $this->php('5.6.2')->getRules()->shouldReturn([ '@PHP54Migration' => true, - '@PHP56Migration' => true, 'array_syntax' => ['syntax' => 'short'], 'list_syntax' => ['syntax' => 'long'], ]); diff --git a/src/PedroTroller/CS/Fixer/AbstractFixer.php b/src/PedroTroller/CS/Fixer/AbstractFixer.php index 10183e7..221d20b 100644 --- a/src/PedroTroller/CS/Fixer/AbstractFixer.php +++ b/src/PedroTroller/CS/Fixer/AbstractFixer.php @@ -7,6 +7,7 @@ use PhpCsFixer\AbstractFixer as PhpCsFixer; use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -14,18 +15,13 @@ abstract class AbstractFixer extends PhpCsFixer { /** * @param Tokens $tokens - * - * @return bool */ - public function isCandidate(Tokens $tokens) + public function isCandidate(Tokens $tokens): bool { return true; } - /** - * {@inheritdoc} - */ - public function getName() + public function getName(): string { return sprintf('PedroTroller/%s', parent::getName()); } @@ -33,27 +29,18 @@ public function getName() /** * @return array */ - public function getSampleConfigurations() + public function getSampleConfigurations(): array { return [ [], ]; } - /** - * @return string - */ - abstract public function getSampleCode(); + abstract public function getSampleCode(): string; - /** - * @return string - */ - abstract public function getDocumentation(); + abstract public function getDocumentation(): string; - /** - * {@inheritdoc} - */ - public function getDefinition() + public function getDefinition(): FixerDefinitionInterface { return new FixerDefinition( $this->getDocumentation(), @@ -66,45 +53,33 @@ function (array $configutation = null) { ); } - /** - * @return bool - */ - public function isDeprecated() + public function isDeprecated(): bool { return false; } - /** - * @return null|string - */ - public function getDeprecationReplacement() + public function getDeprecationReplacement(): ?string { + return null; } - /** - * @return TokensAnalyzer - */ - protected function analyze(Tokens $tokens) + protected function analyze(Tokens $tokens): TokensAnalyzer { return new TokensAnalyzer($tokens); } /** * @param string|string[] $fqcn - * - * @return bool */ - protected function hasUseStatements(Tokens $tokens, $fqcn) + protected function hasUseStatements(Tokens $tokens, $fqcn): bool { return null !== $this->getUseStatements($tokens, $fqcn); } /** * @param string|string[] $fqcn - * - * @return null|array */ - protected function getUseStatements(Tokens $tokens, $fqcn) + protected function getUseStatements(Tokens $tokens, $fqcn): ?array { if (false === \is_array($fqcn)) { $fqcn = explode('\\', $fqcn); @@ -123,10 +98,8 @@ protected function getUseStatements(Tokens $tokens, $fqcn) /** * @param string|string[] $fqcn - * - * @return bool */ - protected function extendsClass(Tokens $tokens, $fqcn) + protected function extendsClass(Tokens $tokens, $fqcn): bool { if (false === \is_array($fqcn)) { $fqcn = explode('\\', $fqcn); @@ -146,10 +119,8 @@ protected function extendsClass(Tokens $tokens, $fqcn) /** * @param string|string[] $fqcn - * - * @return bool */ - protected function implementsInterface(Tokens $tokens, $fqcn) + protected function implementsInterface(Tokens $tokens, $fqcn): bool { if (false === \is_array($fqcn)) { $fqcn = explode('\\', $fqcn); @@ -168,9 +139,9 @@ protected function implementsInterface(Tokens $tokens, $fqcn) } /** - * @return Token[] + * @return array */ - protected function getComments(Tokens $tokens) + protected function getComments(Tokens $tokens): array { $comments = []; diff --git a/src/PedroTroller/CS/Fixer/AbstractOrderedClassElementsFixer.php b/src/PedroTroller/CS/Fixer/AbstractOrderedClassElementsFixer.php index 17bc1b7..4209dad 100644 --- a/src/PedroTroller/CS/Fixer/AbstractOrderedClassElementsFixer.php +++ b/src/PedroTroller/CS/Fixer/AbstractOrderedClassElementsFixer.php @@ -10,9 +10,6 @@ abstract class AbstractOrderedClassElementsFixer extends AbstractFixer { - /** - * {@inheritdoc} - */ protected function applyFix(SplFileInfo $file, Tokens $tokens): void { for ($i = 1, $count = $tokens->count(); $i < $count; ++$i) { @@ -43,7 +40,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void * * @return array[] */ - abstract protected function sortElements(array $elements); + abstract protected function sortElements(array $elements): array; /** * @param int $startIndex diff --git a/src/PedroTroller/CS/Fixer/Behat/OrderBehatStepsFixer.php b/src/PedroTroller/CS/Fixer/Behat/OrderBehatStepsFixer.php index 00405c4..ea44517 100644 --- a/src/PedroTroller/CS/Fixer/Behat/OrderBehatStepsFixer.php +++ b/src/PedroTroller/CS/Fixer/Behat/OrderBehatStepsFixer.php @@ -7,14 +7,15 @@ use PedroTroller\CS\Fixer\AbstractOrderedClassElementsFixer; use PedroTroller\CS\Fixer\Priority; use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer; -use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\Tokenizer\Tokens; -final class OrderBehatStepsFixer extends AbstractOrderedClassElementsFixer implements ConfigurationDefinitionFixerInterface +final class OrderBehatStepsFixer extends AbstractOrderedClassElementsFixer implements ConfigurableFixerInterface { - const ANNOTATION_PRIORITIES = [ + public const ANNOTATION_PRIORITIES = [ '@BeforeSuite', '@AfterSuite', '@BeforeScenario', @@ -26,15 +27,15 @@ final class OrderBehatStepsFixer extends AbstractOrderedClassElementsFixer imple '@Then', ]; - public function getSampleConfigurations() + public function getSampleConfigurations(): array { return [ - null, + [], ['instanceof' => ['Behat\Behat\Context\Context']], ]; } - public function isCandidate(Tokens $tokens) + public function isCandidate(Tokens $tokens): bool { foreach ($this->configuration['instanceof'] as $parent) { if ($this->extendsClass($tokens, $parent)) { @@ -49,92 +50,83 @@ public function isCandidate(Tokens $tokens) return false; } - /** - * {@inheritdoc} - */ - public function getSampleCode() + public function getSampleCode(): string { return <<<'SPEC' -kernel = $kernel; - } + public function __construct(KernelInterface $kernel) + { + $this->kernel = $kernel; + } - /** - * @Then the response should be received - */ - public function theResponseShouldBeReceived() - { - // ... - } + /** + * @Then the response should be received + */ + public function theResponseShouldBeReceived() + { + // ... + } - /** - * @When a demo scenario sends a request to :path - */ - public function aDemoScenarioSendsARequestTo($path) - { - // ... - } + /** + * @When a demo scenario sends a request to :path + */ + public function aDemoScenarioSendsARequestTo($path) + { + // ... + } - /** - * @Given I am on the homepage - */ - public function iAmOnTheHomepage() - { - // ... - } + /** + * @Given I am on the homepage + */ + public function iAmOnTheHomepage() + { + // ... + } - /** - * @BeforeScenario - */ - public function reset() - { - // ... - } -} -SPEC; + /** + * @BeforeScenario + */ + public function reset() + { + // ... + } + } + SPEC; } - /** - * {@inheritdoc} - */ - public function getPriority() + public function getPriority(): int { return Priority::before(OrderedClassElementsFixer::class); } - public function getDocumentation() + public function getDocumentation(): string { return 'Step definition methods in Behat contexts MUST BE ordered by annotation and method name.'; } - /** - * {@inheritdoc} - */ - protected function createConfigurationDefinition() + public function getConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ (new FixerOptionBuilder('instanceof', 'Parent class or interface of your behat context classes.')) @@ -143,10 +135,7 @@ protected function createConfigurationDefinition() ]); } - /** - * {@inheritdoc} - */ - protected function sortElements(array $elements) + protected function sortElements(array $elements): array { $ordered = []; diff --git a/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php b/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php index 1ef4ddb..9535b31 100644 --- a/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php +++ b/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php @@ -12,116 +12,101 @@ final class OrderedWithGetterAndSetterFirstFixer extends AbstractOrderedClassElementsFixer { - /** - * {@inheritdoc} - */ - public function isCandidate(Tokens $tokens) + public function isCandidate(Tokens $tokens): bool { return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds()); } - /** - * {@inheritdoc} - */ - public function getPriority() + public function getPriority(): int { return Priority::before(OrderedClassElementsFixer::class); } - /** - * {@inheritdoc} - */ - public function getDocumentation() + public function getDocumentation(): string { return 'Class/interface/trait methods MUST BE ordered (accessors at the beginning of the class, ordered following properties order).'; } - /** - * {@inheritdoc} - */ - public function getSampleCode() + public function getSampleCode(): string { return <<<'PHP' - $value) { - $this->$key = $value; - } - } + $value) { + $this->$key = $value; + } + } - public function setFirstName($firstName) - { - $this->firstName = $firstName; - } + public function setFirstName($firstName) + { + $this->firstName = $firstName; + } - public function setName($name) - { - $this->name = $name; - } + public function setName($name) + { + $this->name = $name; + } - public function isEnabled() - { - return $this->enabled; - } + public function isEnabled() + { + return $this->enabled; + } - public function getName() - { - return $this->name; - } + public function getName() + { + return $this->name; + } - public function getIdentifier() - { - return $this->identifier; - } + public function getIdentifier() + { + return $this->identifier; + } - public function getFirstName() - { - return $this->firstName; - } + public function getFirstName() + { + return $this->firstName; + } - public function enable() - { - $this->enabled = true; - } + public function enable() + { + $this->enabled = true; + } - public function disable() - { - $this->enabled = false; - } -} -PHP; + public function disable() + { + $this->enabled = false; + } + } + PHP; } - /** - * {@inheritdoc} - */ - protected function sortElements(array $elements) + protected function sortElements(array $elements): array { $methods = $this->getMethodsNames($elements); $portions = []; @@ -162,7 +147,7 @@ protected function sortElements(array $elements) return $result; } - private function getMethodsNames(array $elements) + private function getMethodsNames(array $elements): array { $methods = []; @@ -177,7 +162,7 @@ private function getMethodsNames(array $elements) return $methods; } - private function getPropertiesNames(array $elements) + private function getPropertiesNames(array $elements): array { $properties = array_filter($elements, function ($element) { return 'property' === $element['type']; diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/ExceptionsPunctuationFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/ExceptionsPunctuationFixer.php index 12dee50..c2a0add 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/ExceptionsPunctuationFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/ExceptionsPunctuationFixer.php @@ -11,50 +11,38 @@ final class ExceptionsPunctuationFixer extends AbstractFixer { - /** - * {@inheritdoc} - */ - public function isCandidate(Tokens $tokens) + public function isCandidate(Tokens $tokens): bool { return $tokens->isTokenKindFound(T_THROW); } - /** - * {@inheritdoc} - */ - public function isRisky() + public function isRisky(): bool { return true; } - /** - * {@inheritdoc} - */ - public function getSampleCode() + public function getSampleCode(): string { return <<<'PHP' -
Risky: will change the exception message.'; } @@ -148,10 +136,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void } } - /** - * @return Token - */ - private function cleanupMessage(Token $token) + private function cleanupMessage(Token $token): Token { $content = $token->getContent(); $chars = str_split($content); diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php index e799c71..a75f975 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php @@ -5,47 +5,42 @@ namespace PedroTroller\CS\Fixer\CodingStyle; use PedroTroller\CS\Fixer\AbstractFixer; -use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use SplFileInfo; -final class ForbiddenFunctionsFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface +final class ForbiddenFunctionsFixer extends AbstractFixer implements ConfigurableFixerInterface { - /** - * {@inheritdoc} - */ - public function getSampleCode() + public function getSampleCode(): string { return <<<'PHP' -dump($this); + $this->dump($this); - return var_export($this); - } + return var_export($this); + } - public function dump($data) - { - parent::dump($this); + public function dump($data) + { + parent::dump($this); - return serialize($data); - } -} -PHP; + return serialize($data); + } + } + PHP; } - /** - * {@inheritdoc} - */ - public function getSampleConfigurations() + public function getSampleConfigurations(): array { return [ ['comment' => 'YOLO'], @@ -53,14 +48,23 @@ public function getSampleConfigurations() ]; } - /** - * {@inheritdoc} - */ - public function getDocumentation() + public function getDocumentation(): string { return 'Prohibited functions MUST BE commented on as prohibited'; } + public function getConfigurationDefinition(): FixerConfigurationResolverInterface + { + return new FixerConfigurationResolver([ + (new FixerOptionBuilder('functions', 'The function names to be marked how prohibited')) + ->setDefault(['var_dump', 'dump', 'die']) + ->getOption(), + (new FixerOptionBuilder('comment', 'The prohibition message to put in the comment')) + ->setDefault('@TODO remove this line') + ->getOption(), + ]); + } + protected function applyFix(SplFileInfo $file, Tokens $tokens): void { $calls = []; @@ -86,19 +90,4 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void } } } - - /** - * {@inheritdoc} - */ - protected function createConfigurationDefinition() - { - return new FixerConfigurationResolver([ - (new FixerOptionBuilder('functions', 'The function names to be marked how prohibited')) - ->setDefault(['var_dump', 'dump']) - ->getOption(), - (new FixerOptionBuilder('comment', 'The prohibition message to put in the comment')) - ->setDefault('@TODO remove this line') - ->getOption(), - ]); - } } diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php index 909e2f5..4a76f8c 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php @@ -7,30 +7,25 @@ use PedroTroller\CS\Fixer\AbstractFixer; use PedroTroller\CS\Fixer\Priority; use PhpCsFixer\Fixer\Basic\BracesFixer; -use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use SplFileInfo; -final class LineBreakBetweenMethodArgumentsFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface +final class LineBreakBetweenMethodArgumentsFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface { - private const T_TYPEHINT_SEMI_COLON = 10025; + public const T_TYPEHINT_SEMI_COLON = 10025; - /** - * {@inheritdoc} - */ - public function getPriority() + public function getPriority(): int { return Priority::after(BracesFixer::class); } - /** - * {@inheritdoc} - */ - public function getSampleConfigurations() + public function getSampleConfigurations(): array { return [ [ @@ -46,49 +41,55 @@ public function getSampleConfigurations() ]; } - /** - * {@inheritdoc} - */ - public function getDocumentation() + public function getDocumentation(): string { return 'If the declaration of a method is too long, the arguments of this method MUST BE separated (one argument per line)'; } - /** - * {@inheritdoc} - */ - public function getSampleCode() + public function getSampleCode(): string { return <<<'SPEC' -setDefault(3) + ->getOption(), + (new FixerOptionBuilder('max-length', 'The maximum number of characters allowed with splitting the arguments into several lines')) + ->setDefault(120) + ->getOption(), + (new FixerOptionBuilder('automatic-argument-merge', 'If both conditions are met (the line is not too long and there are not too many arguments), then the arguments are put back inline')) + ->setDefault(true) + ->getOption(), + ]); } - /** - * {@inheritdoc} - */ protected function applyFix(SplFileInfo $file, Tokens $tokens): void { $functions = []; @@ -147,24 +148,6 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void } } - /** - * {@inheritdoc} - */ - protected function createConfigurationDefinition() - { - return new FixerConfigurationResolver([ - (new FixerOptionBuilder('max-args', 'The maximum number of arguments allowed with splitting the arguments into several lines (use `false` to disable this feature)')) - ->setDefault(3) - ->getOption(), - (new FixerOptionBuilder('max-length', 'The maximum number of characters allowed with splitting the arguments into several lines')) - ->setDefault(120) - ->getOption(), - (new FixerOptionBuilder('automatic-argument-merge', 'If both conditions are met (the line is not too long and there are not too many arguments), then the arguments are put back inline.')) - ->setDefault(true) - ->getOption(), - ]); - } - private function splitArgs(Tokens $tokens, $index): void { $this->mergeArgs($tokens, $index); diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenStatementsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenStatementsFixer.php index 9053056..699e7e0 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenStatementsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenStatementsFixer.php @@ -23,45 +23,39 @@ final class LineBreakBetweenStatementsFixer extends AbstractFixer T_WHILE => 'common', ]; - /** - * {@inheritdoc} - */ - public function getSampleCode() + public function getSampleCode(): string { return <<<'PHP' -name = $name; - } + /** + * @param string $name + */ + public function __construct($name) + { + $this->name = $name; + } - // Get the name - // - // @return string - public function getName() - { - return $this->name; - } + // Get the name + // + // @return string + public function getName() + { + return $this->name; + } - // Get the value - // @return null | string - public function getValue() - { - return $this->value; - } + // Get the value + // @return null | string + public function getValue() + { + return $this->value; + } - // Set the value + // Set the value - // @param string $value - public function setValue($value) - { - $this->value = $value; - } -} -PHP; + // @param string $value + public function setValue($value) + { + $this->value = $value; + } + } + PHP; } - /** - * {@inheritdoc} - */ - public function getDocumentation() + public function getDocumentation(): string { return 'Classy elements (method, property, ...) comments MUST BE a PhpDoc block'; } - public function getPriority() + public function getPriority(): int { return Priority::after(SingleLineCommentStyleFixer::class); } - /** - * {@inheritdoc} - */ protected function applyFix(SplFileInfo $file, Tokens $tokens): void { $elements = $this->analyze($tokens)->getClassyElements(); @@ -144,11 +135,8 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void /** * @param string[] $comments - * @param int $indentation - * - * @return string */ - private function formatComments(array $comments, $indentation) + private function formatComments(array $comments, string $indentation): string { $comments = array_map('trim', $comments); diff --git a/src/PedroTroller/CS/Fixer/Comment/SingleLineCommentFixer.php b/src/PedroTroller/CS/Fixer/Comment/SingleLineCommentFixer.php deleted file mode 100644 index cac7bb7..0000000 --- a/src/PedroTroller/CS/Fixer/Comment/SingleLineCommentFixer.php +++ /dev/null @@ -1,151 +0,0 @@ - 'expanded'], - ['action' => 'collapsed'], - ]; - } - - /** - * {@inheritdoc} - */ - public function getDocumentation() - { - return 'PHP comments on a single line MUST BE reduced or expanded (according to the specified strategy)'; - } - - /** - * {@inheritdoc} - */ - public function getSampleCode() - { - return <<<'PHP' -getName(); - } - - /** - * {@inheritdoc} - */ - protected function applyFix(SplFileInfo $file, Tokens $tokens): void - { - $this->{$this->configuration['action'].'Comment'}($tokens); - } - - /** - * {@inheritdoc} - */ - protected function createConfigurationDefinition() - { - return new FixerConfigurationResolver([ - (new FixerOptionBuilder('action', 'The strategy to be applied')) - ->setAllowedValues(['expanded', 'collapsed']) - ->setDefault('expanded') - ->getOption(), - (new FixerOptionBuilder('types', 'The types of comments on which the strategy should be applied')) - ->setDefault(['@var', '@return', '@param']) - ->getOption(), - ]); - } - - private function expandedComment(Tokens $tokens): void - { - foreach ($this->getComments($tokens) as $index => $token) { - $space = ''; - if (null !== $prev = $tokens->getPrevTokenOfKind($index, [[T_WHITESPACE]])) { - $spaces = explode("\n", $tokens[$prev]->getContent()); - $space = end($spaces); - } - - foreach ($this->configuration['types'] as $variable) { - $regex = sprintf(self::EXPAND_REGEX, $variable); - $replace = sprintf("/**\n%s * %s $2\n%s */", $space, $variable, $space); - $comment = preg_replace($regex, $replace, $token->getContent()); - $tokens[$index] = new Token([T_COMMENT, $comment]); - } - } - } - - private function collapsedComment(Tokens $tokens): void - { - foreach ($this->getComments($tokens) as $index => $token) { - foreach ($this->configuration['types'] as $variable) { - $regex = sprintf(self::COLLAPSE_REGEX, $variable); - $replace = sprintf('$1/** %s $3 */', $variable); - $comment = preg_replace($regex, $replace, $token->getContent()); - $tokens[$index] = new Token([T_COMMENT, $comment]); - } - } - } -} diff --git a/src/PedroTroller/CS/Fixer/Comment/UselessCommentFixer.php b/src/PedroTroller/CS/Fixer/Comment/UselessCommentFixer.php deleted file mode 100644 index ca657d9..0000000 --- a/src/PedroTroller/CS/Fixer/Comment/UselessCommentFixer.php +++ /dev/null @@ -1,203 +0,0 @@ -name; - } -} -PHP; - } - - /** - * {@inheritdoc} - */ - public function isDeprecated() - { - return true; - } - - /** - * {@inheritdoc} - */ - public function getDeprecationReplacement() - { - return 'no_superfluous_phpdoc_tags'; - } - - /** - * {@inheritdoc} - */ - protected function applyFix(SplFileInfo $file, Tokens $tokens): void - { - foreach ($this->analyze($tokens)->getClassyElements() as $index => $element) { - if ('method' !== $element['type']) { - continue; - } - - $comment = $this->getFunctionComment($index, $tokens); - - if (null === $comment) { - continue; - } - - $uselessComments = $this->getUselessComments($index, $tokens); - $commentText = $tokens[$comment]->getContent(); - $lines = explode("\n", $commentText); - $changed = false; - $previous = null; - - foreach ($lines as $index => $line) { - if (false === \array_key_exists($index, $lines)) { - continue; - } - - $text = trim(ltrim(trim($line), '/*')); - - $matches = array_filter($uselessComments, function ($pattern) use ($text) { - return 1 === preg_match($pattern, $text); - }); - - if (false === empty($matches)) { - unset($lines[$index]); - $changed = true; - - if (null !== $previous) { - $next = $index + 1; - - if (\array_key_exists($next, $lines) && empty(trim($lines[$previous], '/* ')) && empty(trim($lines[$next], '/* ')) && '*/' !== trim($lines[$next])) { - unset($lines[$next]); - } - } - } else { - $previous = $index; - } - } - - if (false === $changed) { - continue; - } - - $commentText = implode("\n", $lines); - - if (empty(trim($commentText, "/* \n"))) { - $tokens->clearAt($comment); - $tokens->removeTrailingWhitespace($comment); - } else { - $tokens[$comment] = new Token([ - T_COMMENT, - preg_replace('/ *\* *\n( *)\*\//', '$1*/', $commentText), - ]); - } - } - } - - /** - * @param int $index - * - * @return null|int - */ - private function getFunctionComment($index, Tokens $tokens) - { - $previous = $index; - - do { - $previous = $tokens->getPrevNonWhitespace($previous); - - if (null === $previous) { - return; - } - } while ($tokens[$previous]->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_ABSTRACT, T_STATIC])); - - if ($tokens[$previous]->isComment()) { - return $previous; - } - } - - private function getUselessComments($index, Tokens $tokens) - { - $arguments = $this->analyze($tokens)->getMethodArguments($index) ?: []; - $return = $this->analyze($tokens)->getReturnedType($index); - $useless = []; - - foreach ($arguments as $argument) { - if (null === $argument['type']) { - $useless[] = sprintf('/^@param +\%s/', $argument['name']); - } elseif ($argument['nullable']) { - $useless[] = sprintf('/^@param +%s\|null +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']); - $useless[] = sprintf('/^@param +null\|%s +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']); - $useless[] = sprintf('/^@param +%s \| null +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']); - $useless[] = sprintf('/^@param +null \| %s +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']); - } else { - $useless[] = sprintf('/^@param +%s +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']); - } - } - - if (null === $return) { - $useless[] = '/^@return null$/'; - } elseif (false === \is_array($return)) { - $useless[] = sprintf('/^@return +%s$/', str_replace('\\', '\\\\', $return)); - } else { - $return = array_map(function ($value) { return null === $value ? 'null' : $value; }, $return); - - $useless[] = sprintf('/^@return +%s$/', str_replace('\\', '\\\\', implode('|', $return))); - $useless[] = sprintf('/^@return +%s$/', str_replace('\\', '\\\\', implode(' | ', $return))); - $useless[] = sprintf('/^@return +%s$/', str_replace('\\', '\\\\', implode('|', array_reverse($return)))); - $useless[] = sprintf('/^@return +%s$/', str_replace('\\', '\\\\', implode(' | ', array_reverse($return)))); - } - - return $useless; - } -} diff --git a/src/PedroTroller/CS/Fixer/DeadCode/UselessCodeAfterReturnFixer.php b/src/PedroTroller/CS/Fixer/DeadCode/UselessCodeAfterReturnFixer.php index b0e15c2..90e2a8b 100644 --- a/src/PedroTroller/CS/Fixer/DeadCode/UselessCodeAfterReturnFixer.php +++ b/src/PedroTroller/CS/Fixer/DeadCode/UselessCodeAfterReturnFixer.php @@ -10,70 +10,61 @@ final class UselessCodeAfterReturnFixer extends AbstractFixer { - /** - * {@inheritdoc} - */ - public function getDocumentation() + public function getDocumentation(): string { return 'All `return` that are not accessible (i.e. following another `return`) MUST BE deleted'; } - /** - * {@inheritdoc} - */ - public function getSampleCode() + public function getSampleCode(): string { return <<<'PHP' -setName('foo'); - - return $this; - } - - /** - * Get the name - * - * @return string|null - */ - public function getName() - { - switch ($this->status) { - case 1: - return $this->name; - break; - default: - return $this; - return $this; - } - } - - /** - * @return callable - */ - public function buildCallable() - { - return function () { return true; return false; }; - } -} -PHP; + setName('foo'); + + return $this; + } + + /** + * Get the name + * + * @return string|null + */ + public function getName() + { + switch ($this->status) { + case 1: + return $this->name; + break; + default: + return $this; + return $this; + } + } + + /** + * @return callable + */ + public function buildCallable() + { + return function () { return true; return false; }; + } + } + PHP; } - /** - * {@inheritdoc} - */ protected function applyFix(SplFileInfo $file, Tokens $tokens): void { $returns = $tokens->findGivenKind(T_RETURN); @@ -92,6 +83,12 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void $possible = array_merge($possible, array_keys($ends)); } + $possible = array_filter($possible, function ($value) { return null !== $value; }); + + if (empty($possible)) { + continue; + } + $end = $tokens->getPrevMeaningfulToken(min($possible)); if (($start + 1) > $end) { diff --git a/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php b/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php index 9bcdc93..94bc5e2 100644 --- a/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php +++ b/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php @@ -5,16 +5,17 @@ namespace PedroTroller\CS\Fixer; use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer; -use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer; use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use SplFileInfo; -final class DoctrineMigrationsFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface +final class DoctrineMigrationsFixer extends AbstractFixer implements ConfigurableFixerInterface { /** * @var string[] @@ -25,18 +26,15 @@ final class DoctrineMigrationsFixer extends AbstractFixer implements Configurati 'this down() migration is auto-generated, please modify it to your needs', ]; - public function getSampleConfigurations() + public function getSampleConfigurations(): array { return [ - null, + [], ['instanceof' => ['Doctrine\Migrations\AbstractMigration']], ]; } - /** - * {@inheritdoc} - */ - public function isCandidate(Tokens $tokens) + public function isCandidate(Tokens $tokens): bool { foreach ($this->configuration['instanceof'] as $parent) { if ($this->extendsClass($tokens, $parent)) { @@ -51,64 +49,58 @@ public function isCandidate(Tokens $tokens) return false; } - /** - * {@inheritdoc} - */ - public function getSampleCode() + public function getSampleCode(): string { return <<<'SPEC' -abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); + public function up(Schema $schema) + { + // this up() migration is auto-generated, please modify it to your needs + $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); - } + $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); + } - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); + public function down(Schema $schema) + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('DROP TABLE admin'); - } -} -SPEC; + $this->addSql('DROP TABLE admin'); + } + } + SPEC; } - public function getDocumentation() + public function getDocumentation(): string { return 'Unnecessary empty methods (`getDescription()`, `up()`, `down()`) and comments MUST BE removed from Doctrine migrations'; } - public function getPriority() + public function getPriority(): int { return Priority::before(ClassAttributesSeparationFixer::class, NoEmptyPhpdocFixer::class, NoExtraBlankLinesFixer::class); } - /** - * {@inheritdoc} - */ - protected function createConfigurationDefinition() + public function getConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ (new FixerOptionBuilder('instanceof', 'The parent class of which Doctrine migrations extend')) @@ -117,9 +109,6 @@ protected function createConfigurationDefinition() ]); } - /** - * {@inheritdoc} - */ protected function applyFix(SplFileInfo $file, Tokens $tokens): void { $this->removeUselessGetDocumentation($tokens); diff --git a/src/PedroTroller/CS/Fixer/Fixers.php b/src/PedroTroller/CS/Fixer/Fixers.php index 19b524a..7130e0c 100644 --- a/src/PedroTroller/CS/Fixer/Fixers.php +++ b/src/PedroTroller/CS/Fixer/Fixers.php @@ -16,8 +16,7 @@ final class Fixers implements IteratorAggregate */ public function getIterator() { - $finder = new Finder(); - $finder + $finder = Finder::create() ->in(__DIR__) ->name('*.php') ; diff --git a/src/PedroTroller/CS/Fixer/Phpspec/OrderedSpecElementsFixer.php b/src/PedroTroller/CS/Fixer/Phpspec/OrderedSpecElementsFixer.php deleted file mode 100644 index 5133908..0000000 --- a/src/PedroTroller/CS/Fixer/Phpspec/OrderedSpecElementsFixer.php +++ /dev/null @@ -1,196 +0,0 @@ - ['PhpSpec\ObjectBehavior']], - ]; - } - - /** - * {@inheritdoc} - */ - public function isCandidate(Tokens $tokens) - { - foreach ($this->configuration['instanceof'] as $parent) { - if ($this->extendsClass($tokens, $parent)) { - return true; - } - - if ($this->implementsInterface($tokens, $parent)) { - return true; - } - } - - return false; - } - - /** - * {@inheritdoc} - */ - public function getDocumentation() - { - return 'The methods of the phpspec specification classes MUST BE sorted (let, letGo, its_*, it_*, getMatchers and the rest of the methods)'; - } - - /** - * {@inheritdoc} - */ - public function isDeprecated() - { - return true; - } - - public function getDeprecationReplacement() - { - return (new PhpspecFixer())->getName(); - } - - /** - * {@inheritdoc} - */ - public function getSampleCode() - { - return <<<'SPEC' -setDefault(['PhpSpec\ObjectBehavior']) - ->getOption(), - ]); - } - - /** - * {@inheritdoc} - */ - protected function sortElements(array $elements) - { - $ordered = array_merge( - array_values($this->filterElementsByMethodName('let', $elements)), - array_values($this->filterElementsByMethodName('letGo', $elements)), - array_values($this->filterElementsByMethodName('it_is_initializable', $elements)), - array_values($this->filterElementsByMethodName('^(?!it_is_initializable)(it_|its_).+?$', $elements)), - array_values($this->filterElementsByMethodName('getMatchers', $elements)) - ); - - foreach ($this->filterElementsByType('method', $elements) as $element) { - if (\in_array($element, $ordered, true)) { - continue; - } - - $ordered[] = $element; - } - - foreach ($elements as $element) { - if (\in_array($element, $ordered, true)) { - continue; - } - - array_unshift($ordered, $element); - } - - return $ordered; - } - - /** - * @param string $regex - * - * @return array - */ - private function filterElementsByMethodName($regex, array $elements) - { - $filter = []; - - foreach ($this->filterElementsByType('method', $elements) as $index => $method) { - if (0 !== preg_match(sprintf('/^%s$/', $regex), $method['methodName'])) { - $filter[$index] = $method; - } - } - - return $filter; - } - - /** - * @param string $type - * - * @return array - */ - private function filterElementsByType($type, array $elements) - { - $filter = []; - - foreach ($elements as $index => $element) { - if ($type !== $element['type']) { - continue; - } - - $filter[$index] = $element; - } - - return $filter; - } -} diff --git a/src/PedroTroller/CS/Fixer/Phpspec/PhpspecScenarioReturnTypeDeclarationFixer.php b/src/PedroTroller/CS/Fixer/Phpspec/PhpspecScenarioReturnTypeDeclarationFixer.php deleted file mode 100644 index 48e8e36..0000000 --- a/src/PedroTroller/CS/Fixer/Phpspec/PhpspecScenarioReturnTypeDeclarationFixer.php +++ /dev/null @@ -1,174 +0,0 @@ - ['PhpSpec\ObjectBehavior']], - ]; - } - - /** - * {@inheritdoc} - */ - public function isCandidate(Tokens $tokens) - { - if (\PHP_VERSION_ID < 70100) { - return false; - } - - foreach ($this->configuration['instanceof'] as $parent) { - if ($this->extendsClass($tokens, $parent)) { - return true; - } - - if ($this->implementsInterface($tokens, $parent)) { - return true; - } - } - - return false; - } - - /** - * {@inheritdoc} - */ - public function getDocumentation() - { - return 'Phpspec scenario functions MUST NOT have a return type declaration.'; - } - - /** - * {@inheritdoc} - */ - public function isDeprecated() - { - return true; - } - - /** - * {@inheritdoc} - */ - public function getDeprecationReplacement() - { - return (new PhpspecFixer())->getName(); - } - - /** - * {@inheritdoc} - */ - public function getSampleCode() - { - return <<<'SPEC' -setDefault(['PhpSpec\ObjectBehavior']) - ->getOption(), - ]); - } - - /** - * {@inheritdoc} - */ - protected function applyFix(SplFileInfo $file, Tokens $tokens): void - { - foreach ($tokens as $index => $token) { - if (T_FUNCTION !== $token->getId()) { - continue; - } - - $functionNameIndex = $tokens->getNextMeaningfulToken($index); - - if (null === $functionNameIndex) { - continue; - } - - $functionName = $tokens[$functionNameIndex]; - - if (T_STRING !== $functionName->getId()) { - continue; - } - - if (0 === preg_match('/^(let(Go)?|it_.+|its_.+)$/', $functionName->getContent())) { - continue; - } - - $openBraceIndex = $tokens->getNextTokenOfKind($index, ['(']); - $closeBraceIndex = $this->analyze($tokens)->getClosingParenthesis($openBraceIndex); - $openCurlyBracket = $tokens->getNextTokenOfKind($index, ['{']); - $returnDeclaration = $this->analyze($tokens)->getReturnedType($index); - - if (null === $returnDeclaration || null === $closeBraceIndex || null === $openCurlyBracket) { - continue; - } - - if ($closeBraceIndex >= $openCurlyBracket - 1) { - continue; - } - - $tokens->clearRange($closeBraceIndex + 1, $openCurlyBracket - 1); - $tokens->insertAt($openCurlyBracket, new Token(' ')); - } - } -} diff --git a/src/PedroTroller/CS/Fixer/Phpspec/PhpspecScenarioScopeFixer.php b/src/PedroTroller/CS/Fixer/Phpspec/PhpspecScenarioScopeFixer.php deleted file mode 100644 index ec9ee14..0000000 --- a/src/PedroTroller/CS/Fixer/Phpspec/PhpspecScenarioScopeFixer.php +++ /dev/null @@ -1,160 +0,0 @@ - ['PhpSpec\ObjectBehavior']], - ]; - } - - /** - * {@inheritdoc} - */ - public function isCandidate(Tokens $tokens) - { - foreach ($this->configuration['instanceof'] as $parent) { - if ($this->extendsClass($tokens, $parent)) { - return true; - } - - if ($this->implementsInterface($tokens, $parent)) { - return true; - } - } - - return false; - } - - /** - * {@inheritdoc} - */ - public function getDocumentation() - { - return 'Phpspec scenario functions MUST NOT have a scope.'; - } - - /** - * {@inheritdoc} - */ - public function isDeprecated() - { - return true; - } - - /** - * {@inheritdoc} - */ - public function getDeprecationReplacement() - { - return (new PhpspecFixer())->getName(); - } - - /** - * {@inheritdoc} - */ - public function getSampleCode() - { - return <<<'SPEC' -setDefault(['PhpSpec\ObjectBehavior']) - ->getOption(), - ]); - } - - /** - * {@inheritdoc} - */ - protected function applyFix(SplFileInfo $file, Tokens $tokens): void - { - foreach ($tokens as $index => $token) { - if (T_FUNCTION !== $token->getId()) { - continue; - } - - $nextIndex = $tokens->getNextMeaningfulToken($index); - $next = $tokens[$nextIndex]; - $previousIndex = $tokens->getPrevMeaningfulToken($index); - $previous = $tokens[$previousIndex]; - - if (null === $nextIndex || null === $previousIndex) { - continue; - } - - if (T_STRING !== $next->getId()) { - continue; - } - - if (0 === preg_match('/^(let(Go)?|it_.+|its_.+)$/', $next->getContent())) { - continue; - } - - if (T_PUBLIC === $previous->getId()) { - $tokens[$previousIndex] = new Token(''); - $tokens->removeTrailingWhitespace($previousIndex); - } - } - } -} diff --git a/src/PedroTroller/CS/Fixer/PhpspecFixer.php b/src/PedroTroller/CS/Fixer/PhpspecFixer.php index b6f3bfc..40e5fbc 100644 --- a/src/PedroTroller/CS/Fixer/PhpspecFixer.php +++ b/src/PedroTroller/CS/Fixer/PhpspecFixer.php @@ -5,28 +5,26 @@ namespace PedroTroller\CS\Fixer; use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer; -use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use SplFileInfo; -final class PhpspecFixer extends AbstractOrderedClassElementsFixer implements ConfigurationDefinitionFixerInterface +final class PhpspecFixer extends AbstractOrderedClassElementsFixer implements ConfigurableFixerInterface { - public function getSampleConfigurations() + public function getSampleConfigurations(): array { return [ - null, + [], ['instanceof' => ['PhpSpec\ObjectBehavior']], ]; } - /** - * {@inheritdoc} - */ - public function isCandidate(Tokens $tokens) + public function isCandidate(Tokens $tokens): bool { foreach ($this->configuration['instanceof'] as $parent) { if ($this->extendsClass($tokens, $parent)) { @@ -41,49 +39,46 @@ public function isCandidate(Tokens $tokens) return false; } - /** - * {@inheritdoc} - */ - public function getSampleCode() + public function getSampleCode(): string { return <<<'SPEC' -filterElementsByType('construct', $elements)), @@ -236,12 +222,7 @@ private function removeReturn(SplFileInfo $file, Tokens $tokens): void } } - /** - * @param string $regex - * - * @return array - */ - private function filterElementsByMethodName($regex, array $elements) + private function filterElementsByMethodName(string $regex, array $elements): array { $filter = []; @@ -254,12 +235,7 @@ private function filterElementsByMethodName($regex, array $elements) return $filter; } - /** - * @param string $type - * - * @return array - */ - private function filterElementsByType($type, array $elements) + private function filterElementsByType(string $type, array $elements): array { $filter = []; diff --git a/src/PedroTroller/CS/Fixer/RuleSetFactory.php b/src/PedroTroller/CS/Fixer/RuleSetFactory.php index fc2a496..f911104 100644 --- a/src/PedroTroller/CS/Fixer/RuleSetFactory.php +++ b/src/PedroTroller/CS/Fixer/RuleSetFactory.php @@ -4,7 +4,7 @@ namespace PedroTroller\CS\Fixer; -use PhpCsFixer\RuleSet; +use PhpCsFixer\RuleSet\RuleSets; final class RuleSetFactory { @@ -229,7 +229,7 @@ public function disable($name) */ private function migration($package, $version, $risky) { - $rules = (new RuleSet())->getSetDefinitionNames(); + $rules = (new RuleSets())->getSetDefinitionNames(); $rules = array_combine($rules, $rules); $rules = array_map(function ($name) { diff --git a/src/PedroTroller/CS/Fixer/TokensAnalyzer.php b/src/PedroTroller/CS/Fixer/TokensAnalyzer.php index 71f244b..0c4506a 100644 --- a/src/PedroTroller/CS/Fixer/TokensAnalyzer.php +++ b/src/PedroTroller/CS/Fixer/TokensAnalyzer.php @@ -116,7 +116,7 @@ public function getNextComma($index) $index = $this->tokens->getNextMeaningfulToken($index); if (null === $index) { - return; + return null; } switch (true) { @@ -136,7 +136,7 @@ public function getNextComma($index) break; case $this->tokens[$index]->equals(';'): - return; + return null; } } while (false === $this->tokens[$index]->equals(',')); @@ -154,7 +154,7 @@ public function getNextSemiColon($index) $index = $this->tokens->getNextMeaningfulToken($index); if (null === $index) { - return; + return null; } switch (true) { @@ -196,17 +196,17 @@ public function getReturnedType($index) $next = $this->tokens->getNextMeaningfulToken($closeParenthesis); if (null === $next) { - return; + return null; } if (false === $this->tokens[$next]->isGivenKind(TokenSignatures::TYPINT_DOUBLE_DOTS)) { - return; + return null; } $next = $this->tokens->getNextMeaningfulToken($next); if (null === $next) { - return; + return null; } $optionnal = $this->tokens[$next]->isGivenKind(TokenSignatures::TYPINT_OPTIONAL); @@ -280,12 +280,7 @@ public function getSizeOfTheLine($index) return $size; } - /** - * @param int $index - * - * @return null|int - */ - public function endOfTheStatement($index) + public function endOfTheStatement(int $index): ?int { do { $index = $this->tokens->getNextMeaningfulToken($index); diff --git a/tests/Orchestra.php b/tests/Orchestra.php index 7a79bba..0501f4a 100644 --- a/tests/Orchestra.php +++ b/tests/Orchestra.php @@ -40,6 +40,8 @@ public static function run(): void ->before(new SingleLineAfterImportsFixer()) ->before(new NoWhitespaceInBlankLineFixer()) ; + + echo "\n"; } /** @@ -55,7 +57,7 @@ public static function assert(FixerInterface $fixer) */ public function before(FixerInterface $other) { - echo sprintf("Run %s before %s\n", $this->fixer->getName(), $other->getName()); + echo sprintf("\nRun %s before %s\n", $this->fixer->getName(), $other->getName()); Assert::greaterThan( $this->fixer->getPriority(), @@ -70,7 +72,7 @@ public function before(FixerInterface $other) */ public function after(FixerInterface $other) { - echo sprintf("Run %s after %s\n", $this->fixer->getName(), $other->getName()); + echo sprintf("\nRun %s after %s\n", $this->fixer->getName(), $other->getName()); Assert::lessThan( $this->fixer->getPriority(), diff --git a/tests/Runner.php b/tests/Runner.php index c035c5c..33c9102 100644 --- a/tests/Runner.php +++ b/tests/Runner.php @@ -6,7 +6,7 @@ use Exception; use PedroTroller\CS\Fixer\TokensAnalyzer; -use PhpCsFixer\Diff\v3_0\Differ; +use PhpCsFixer\Diff\Differ; use PhpCsFixer\Tokenizer\Tokens; use SplFileInfo; use Symfony\Component\Finder\Finder; diff --git a/tests/TokensAnalyzerIntegration/InSwitch.php b/tests/TokensAnalyzerIntegration/InSwitch.php index 408c848..a4a480f 100644 --- a/tests/TokensAnalyzerIntegration/InSwitch.php +++ b/tests/TokensAnalyzerIntegration/InSwitch.php @@ -17,23 +17,23 @@ final class InSwitch extends TokensAnalyzerIntegration public function getCode() { return <<<'PHP' -user = $user; - } -} -PHP; + public function setUser($user) + { + $this->user = $user; + } + } + PHP; } /** diff --git a/tests/TokensAnalyzerIntegration/NextSemiColon.php b/tests/TokensAnalyzerIntegration/NextSemiColon.php index e954984..850e007 100644 --- a/tests/TokensAnalyzerIntegration/NextSemiColon.php +++ b/tests/TokensAnalyzerIntegration/NextSemiColon.php @@ -17,32 +17,32 @@ final class NextSemiColon extends TokensAnalyzerIntegration public function getCode() { return <<<'PHP' -then(function (array $states) { - return array_map(function (array $state) { - if ($state['state'] === PromiseInterface::FULFILLED) { - return preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $state['value']->getBody()->getContents()); - } - - $uri = (string) $state['reason']->getRequest()->getUri(); - - $this->logger->error("Error while trying to fetch article whitelist from `{$uri}`", [ - 'error' => $state['reason'], - ]); - }, $states); - }) - ; - } -} -PHP; + then(function (array $states) { + return array_map(function (array $state) { + if ($state['state'] === PromiseInterface::FULFILLED) { + return preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $state['value']->getBody()->getContents()); + } + + $uri = (string) $state['reason']->getRequest()->getUri(); + + $this->logger->error("Error while trying to fetch article whitelist from `{$uri}`", [ + 'error' => $state['reason'], + ]); + }, $states); + }) + ; + } + } + PHP; } /** diff --git a/tests/TokensAnalyzerIntegration/Parenthesis.php b/tests/TokensAnalyzerIntegration/Parenthesis.php index 2f76274..a16de9d 100644 --- a/tests/TokensAnalyzerIntegration/Parenthesis.php +++ b/tests/TokensAnalyzerIntegration/Parenthesis.php @@ -14,35 +14,35 @@ final class Parenthesis extends TokensAnalyzerIntegration public function getCode() { return <<<'PHP' -name; - } + public function getName(): ?string + { + return $this->name; + } - public function setName(string $name): void - { - $this->name = $name; - } -} -PHP; + public function setName(string $name): void + { + $this->name = $name; + } + } + PHP; } public function assertions(TokensAnalyzer $analyzer, Tokens $tokens): void diff --git a/tests/TokensAnalyzerIntegration/ReturnedType.php b/tests/TokensAnalyzerIntegration/ReturnedType.php index 2f9fe94..904ea0a 100644 --- a/tests/TokensAnalyzerIntegration/ReturnedType.php +++ b/tests/TokensAnalyzerIntegration/ReturnedType.php @@ -17,35 +17,35 @@ final class ReturnedType extends TokensAnalyzerIntegration public function getCode() { return <<<'PHP' -name; - } + public function getName(): ?string + { + return $this->name; + } - public function setName(string $name): void - { - $this->name = $name; - } -} -PHP; + public function setName(string $name): void + { + $this->name = $name; + } + } + PHP; } /** diff --git a/tests/TokensAnalyzerIntegration/SizeOfTheLine.php b/tests/TokensAnalyzerIntegration/SizeOfTheLine.php index a06337b..d604fa2 100644 --- a/tests/TokensAnalyzerIntegration/SizeOfTheLine.php +++ b/tests/TokensAnalyzerIntegration/SizeOfTheLine.php @@ -17,20 +17,20 @@ final class SizeOfTheLine extends TokensAnalyzerIntegration public function getCode() { return <<<'PHP' -isAVeryLongMethodCall() - ->andThisIsAnOtherMethod() - ; - } -} -PHP; + class TheClass + { + public function theFunction() + { + $this->isAVeryLongMethodCall() + ->andThisIsAnOtherMethod() + ; + } + } + PHP; } /** diff --git a/tests/UseCase/Behat.php b/tests/UseCase/Behat.php index dded23a..498edf1 100644 --- a/tests/UseCase/Behat.php +++ b/tests/UseCase/Behat.php @@ -17,214 +17,214 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'CONTEXT' -kernel = $kernel; - } - - /** - * @BeforeScenario - */ - public function resetDatabase() - { - // ... - } - - /** - * @BeforeScenario - * @AfterStep - */ - public function resetLogs() - { - // ... - } - - public function doSomething() - { - // ... - } - - /** - * @When a demo scenario sends a request to :path - */ - public function aDemoScenarioSendsARequestTo($path) - { - // ... - } - - /** - * @Given I have a user account - * @When I create a user account - */ - public function theResponseShouldBeReceived() - { - // ... - } - - /** - * @BeforeScenario - */ - public function resetDatabase() - { - // ... - } - - /** - * @BeforeScenario - * @AfterStep - */ - public function resetLogs() - { - // ... - } - - /** - * @BeforeScenario - * @Given I am anonymous - */ - public function iAmAnnon() - { - // ... - } -} -CONTEXT; + kernel = $kernel; + } + + /** + * @BeforeScenario + */ + public function resetDatabase() + { + // ... + } + + /** + * @BeforeScenario + * @AfterStep + */ + public function resetLogs() + { + // ... + } + + public function doSomething() + { + // ... + } + + /** + * @When a demo scenario sends a request to :path + */ + public function aDemoScenarioSendsARequestTo($path) + { + // ... + } + + /** + * @Given I have a user account + * @When I create a user account + */ + public function theResponseShouldBeReceived() + { + // ... + } + + /** + * @BeforeScenario + */ + public function resetDatabase() + { + // ... + } + + /** + * @BeforeScenario + * @AfterStep + */ + public function resetLogs() + { + // ... + } + + /** + * @BeforeScenario + * @Given I am anonymous + */ + public function iAmAnnon() + { + // ... + } + } + CONTEXT; } public function getExpectation(): string { return <<<'CONTEXT' -kernel = $kernel; - } - - /** - * @BeforeScenario - * @Given I am anonymous - */ - public function iAmAnnon() - { - // ... - } - - /** - * @BeforeScenario - */ - public function resetDatabase() - { - // ... - } - - /** - * @BeforeScenario - * @AfterStep - */ - public function resetLogs() - { - // ... - } - - /** - * @Given I am on the homepage - */ - public function iAmOnTheHomepage() - { - // ... - } - - /** - * @Given I have a user account - * @When I create a user account - */ - public function theResponseShouldBeReceived() - { - // ... - } - - /** - * @When a demo scenario sends a request to :path - */ - public function aDemoScenarioSendsARequestTo($path) - { - // ... - } - - /** - * @Then the response should be received - */ - public function theResponseShouldBeReceived() - { - // ... - } - - public function doSomething() - { - // ... - } -} -CONTEXT; + kernel = $kernel; + } + + /** + * @BeforeScenario + * @Given I am anonymous + */ + public function iAmAnnon() + { + // ... + } + + /** + * @BeforeScenario + */ + public function resetDatabase() + { + // ... + } + + /** + * @BeforeScenario + * @AfterStep + */ + public function resetLogs() + { + // ... + } + + /** + * @Given I am on the homepage + */ + public function iAmOnTheHomepage() + { + // ... + } + + /** + * @Given I have a user account + * @When I create a user account + */ + public function theResponseShouldBeReceived() + { + // ... + } + + /** + * @When a demo scenario sends a request to :path + */ + public function aDemoScenarioSendsARequestTo($path) + { + // ... + } + + /** + * @Then the response should be received + */ + public function theResponseShouldBeReceived() + { + // ... + } + + public function doSomething() + { + // ... + } + } + CONTEXT; } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/CommentLineToPhpdocBlock.php b/tests/UseCase/CommentLineToPhpdocBlock.php index 29a8227..3895aa0 100644 --- a/tests/UseCase/CommentLineToPhpdocBlock.php +++ b/tests/UseCase/CommentLineToPhpdocBlock.php @@ -17,128 +17,128 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'PHP' -name = $name; - } - - // Get the name - // - // @return string - public function getName() - { - return $this->name; - } - - // Get the value - // @return null | string - public function getValue() - { - return $this->value; - } - - // Set the value - - // @param string $value - public function setValue($value) - { - $this->value = $value; - } - - // {@inheritdoc} - public function update(array $data) - { - return []; - } -} -PHP; + name = $name; + } + + // Get the name + // + // @return string + public function getName() + { + return $this->name; + } + + // Get the value + // @return null | string + public function getValue() + { + return $this->value; + } + + // Set the value + + // @param string $value + public function setValue($value) + { + $this->value = $value; + } + + // {@inheritdoc} + public function update(array $data) + { + return []; + } + } + PHP; } public function getExpectation(): string { return <<<'PHP' -name = $name; - } - - /** - * Get the name - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Get the value - * @return null | string - */ - public function getValue() - { - return $this->value; - } - - /** - * Set the value - * @param string $value - */ - public function setValue($value) - { - $this->value = $value; - } - - /** - * {@inheritdoc} - */ - public function update(array $data) - { - return []; - } -} -PHP; + name = $name; + } + + /** + * Get the name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Get the value + * @return null | string + */ + public function getValue() + { + return $this->value; + } + + /** + * Set the value + * @param string $value + */ + public function setValue($value) + { + $this->value = $value; + } + + /** + * {@inheritdoc} + */ + public function update(array $data) + { + return []; + } + } + PHP; } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/DoctrineMigrations/UselessComments.php b/tests/UseCase/DoctrineMigrations/UselessComments.php index 9056267..04de98e 100644 --- a/tests/UseCase/DoctrineMigrations/UselessComments.php +++ b/tests/UseCase/DoctrineMigrations/UselessComments.php @@ -17,78 +17,78 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'PHP' -abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); - - $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); - - $this->addSql('DROP TABLE admin'); - } -} -PHP; + abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE admin'); + } + } + PHP; } public function getExpectation(): string { return <<<'PHP' -abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); + public function up(Schema $schema): void + { + $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); - } + $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); + } - public function down(Schema $schema): void - { - $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); + public function down(Schema $schema): void + { + $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('DROP TABLE admin'); - } -} -PHP; + $this->addSql('DROP TABLE admin'); + } + } + PHP; } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/DoctrineMigrations/UselessGetDescription.php b/tests/UseCase/DoctrineMigrations/UselessGetDescription.php index 8599081..e07185e 100644 --- a/tests/UseCase/DoctrineMigrations/UselessGetDescription.php +++ b/tests/UseCase/DoctrineMigrations/UselessGetDescription.php @@ -17,69 +17,69 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'PHP' -abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); + public function up(Schema $schema): void + { + $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); - } + $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); + } - public function down(Schema $schema): void - { - $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); + public function down(Schema $schema): void + { + $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('DROP TABLE admin'); - } -} -PHP; + $this->addSql('DROP TABLE admin'); + } + } + PHP; } public function getExpectation(): string { return <<<'PHP' -abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); + public function up(Schema $schema): void + { + $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); - } + $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); + } - public function down(Schema $schema): void - { - $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); + public function down(Schema $schema): void + { + $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('DROP TABLE admin'); - } -} -PHP; + $this->addSql('DROP TABLE admin'); + } + } + PHP; } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/ExceptionsPunctuation.php b/tests/UseCase/ExceptionsPunctuation.php index cd1efcb..e05d681 100644 --- a/tests/UseCase/ExceptionsPunctuation.php +++ b/tests/UseCase/ExceptionsPunctuation.php @@ -17,65 +17,65 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'PHP' -dump($this); - } + $this->dump($this); + } - public function dump($data) - { - parent::dump($this); + public function dump($data) + { + parent::dump($this); - return serialize($data); - } -} -PHP; + return serialize($data); + } + } + PHP; } public function getExpectation(): string { return <<<'PHP' -dump($this); - } + $this->dump($this); + } - public function dump($data) - { - parent::dump($this); + public function dump($data) + { + parent::dump($this); - return serialize($data); - } -} -PHP; + return serialize($data); + } + } + PHP; } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/FuncSpec.php b/tests/UseCase/FuncSpec.php index 1091ca7..44bb647 100644 --- a/tests/UseCase/FuncSpec.php +++ b/tests/UseCase/FuncSpec.php @@ -25,95 +25,95 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'SPEC' -subject = $container->get(DirtinessRegistry::class); - } - - public function foo() - { - return 'bar'; - } - - function it_keeps_track_of_entity_dirtiness() - { - $uuid = Uuid::uuid4()->toString(); - - Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->false(); - - $this->subject->dirty(Identifier::fromString($uuid)); - Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->true(); - - $this->subject->clean(Identifier::fromString($uuid)); - Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->false(); - } -} -SPEC; + subject = $container->get(DirtinessRegistry::class); + } + + public function foo() + { + return 'bar'; + } + + function it_keeps_track_of_entity_dirtiness() + { + $uuid = Uuid::uuid4()->toString(); + + Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->false(); + + $this->subject->dirty(Identifier::fromString($uuid)); + Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->true(); + + $this->subject->clean(Identifier::fromString($uuid)); + Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->false(); + } + } + SPEC; } public function getExpectation(): string { return <<<'SPEC' -subject = $container->get(DirtinessRegistry::class); - } - - function it_keeps_track_of_entity_dirtiness() - { - $uuid = Uuid::uuid4()->toString(); - - Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->false(); - - $this->subject->dirty(Identifier::fromString($uuid)); - Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->true(); - - $this->subject->clean(Identifier::fromString($uuid)); - Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->false(); - } - - public function foo() - { - return 'bar'; - } -} -SPEC; + subject = $container->get(DirtinessRegistry::class); + } + + function it_keeps_track_of_entity_dirtiness() + { + $uuid = Uuid::uuid4()->toString(); + + Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->false(); + + $this->subject->dirty(Identifier::fromString($uuid)); + Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->true(); + + $this->subject->clean(Identifier::fromString($uuid)); + Assert::that($this->subject->isDirty(Identifier::fromString($uuid)))->false(); + } + + public function foo() + { + return 'bar'; + } + } + SPEC; } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/LineBreakBetweenMethods.php b/tests/UseCase/LineBreakBetweenMethods.php index b218a42..5405e04 100644 --- a/tests/UseCase/LineBreakBetweenMethods.php +++ b/tests/UseCase/LineBreakBetweenMethods.php @@ -17,103 +17,103 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'PHP' -string = $string; - $this->int = $int; + public function functionReturningAnonymouseClass() + { + return new class('foo', 100) { + + /** + * @var string + */ + private $string; + + /** + * @var string + */ + private $int; + + public function __construct(string $string, int $int) + { + $this->string = $string; + $this->int = $int; + } + + public function thisIsAVeryLongMethodNameAndItWillBeBreak(string $string, int $int) + { + return null; + } + }; + } } - - public function thisIsAVeryLongMethodNameAndItWillBeBreak(string $string, int $int) - { - return null; - } - }; - } -} -PHP; + PHP; } public function getExpectation(): string { return <<<'PHP' -string = $string; - $this->int = $int; - } - - public function thisIsAVeryLongMethodNameAndItWillBeBreak( - string $string, - int $int - ) { - return null; + public function functionReturningAnonymouseClass() + { + return new class('foo', 100) { + + /** + * @var string + */ + private $string; + + /** + * @var string + */ + private $int; + + public function __construct(string $string, int $int) + { + $this->string = $string; + $this->int = $int; + } + + public function thisIsAVeryLongMethodNameAndItWillBeBreak( + string $string, + int $int + ) { + return null; + } + }; + } } - }; - } -} -PHP; + PHP; } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/LineBreakBetweenMethods/Regression/Case4.php b/tests/UseCase/LineBreakBetweenMethods/Regression/Case4.php index acaffc1..48beb29 100644 --- a/tests/UseCase/LineBreakBetweenMethods/Regression/Case4.php +++ b/tests/UseCase/LineBreakBetweenMethods/Regression/Case4.php @@ -27,81 +27,81 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'PHP' -beConstructedWith('Plazza Hotel', 145); - } - - function it_is_initializable() - { - $this->shouldHaveType(Model\Hotel::class); - } - - function it_exposes_some_state() - { - $this->getName()->shouldReturn('Plazza Hotel'); - $this->getCapacity()->shouldReturn(145); - } - - function it_is_mutable() - { - $this->setName('Ritz Hotel'); - $this->setCapacity(100); - - $this->getName()->shouldReturn('Ritz Hotel'); - $this->getCapacity()->shouldReturn(100); - } -} -PHP; - } - - public function getExpectation(): string - { - return <<<'PHP' -beConstructedWith('Plazza Hotel', 145); - } - - function it_is_initializable() - { - $this->shouldHaveType(Model\Hotel::class); - } - - function it_exposes_some_state() - { - $this->getName()->shouldReturn('Plazza Hotel'); - $this->getCapacity()->shouldReturn(145); - } - - function it_is_mutable() - { - $this->setName('Ritz Hotel'); - $this->setCapacity(100); - - $this->getName()->shouldReturn('Ritz Hotel'); - $this->getCapacity()->shouldReturn(100); - } -} -PHP; - } - - public function getMinSupportedPhpVersion(): int - { - return 0; - } -} diff --git a/tests/UseCase/OrderedWithGetterAndSetterFirst.php b/tests/UseCase/OrderedWithGetterAndSetterFirst.php index 6c2502d..e0d7e2b 100644 --- a/tests/UseCase/OrderedWithGetterAndSetterFirst.php +++ b/tests/UseCase/OrderedWithGetterAndSetterFirst.php @@ -17,169 +17,169 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'PHP' - $value) { - $this->$key = $value; - } - } - - public function setFirstName($firstName) - { - $this->firstName = $firstName; - } - - public function setName($name) - { - $this->name = $name; - } - - public function enable() - { - $this->enabled = true; - } - - public function disable() - { - $this->enabled = false; - } - - public function isEnabled() - { - return $this->enabled; - } - - public function getName() - { - return $this->name; - } - - public function getIdentifier() - { - return $this->identifier; - } - - public function getFirstName() - { - return $this->firstName; - } - - public function hasIdentifier() - { - return null !== $this->identifier; - } -} -PHP; + $value) { + $this->$key = $value; + } + } + + public function setFirstName($firstName) + { + $this->firstName = $firstName; + } + + public function setName($name) + { + $this->name = $name; + } + + public function enable() + { + $this->enabled = true; + } + + public function disable() + { + $this->enabled = false; + } + + public function isEnabled() + { + return $this->enabled; + } + + public function getName() + { + return $this->name; + } + + public function getIdentifier() + { + return $this->identifier; + } + + public function getFirstName() + { + return $this->firstName; + } + + public function hasIdentifier() + { + return null !== $this->identifier; + } + } + PHP; } public function getExpectation(): string { return <<<'PHP' - $value) { - $this->$key = $value; - } - } - - public function getIdentifier() - { - return $this->identifier; - } - - public function hasIdentifier() - { - return null !== $this->identifier; - } - - public function getName() - { - return $this->name; - } - - public function setName($name) - { - $this->name = $name; - } - - public function getFirstName() - { - return $this->firstName; - } - - public function setFirstName($firstName) - { - $this->firstName = $firstName; - } - - public function isEnabled() - { - return $this->enabled; - } - - public function enable() - { - $this->enabled = true; - } - - public function disable() - { - $this->enabled = false; - } -} -PHP; + $value) { + $this->$key = $value; + } + } + + public function getIdentifier() + { + return $this->identifier; + } + + public function hasIdentifier() + { + return null !== $this->identifier; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getFirstName() + { + return $this->firstName; + } + + public function setFirstName($firstName) + { + $this->firstName = $firstName; + } + + public function isEnabled() + { + return $this->enabled; + } + + public function enable() + { + $this->enabled = true; + } + + public function disable() + { + $this->enabled = false; + } + } + PHP; } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/OrderedWithGetterAndSetterFirst/Regression/Case1.php b/tests/UseCase/OrderedWithGetterAndSetterFirst/Regression/Case1.php index 60fc967..028f52d 100644 --- a/tests/UseCase/OrderedWithGetterAndSetterFirst/Regression/Case1.php +++ b/tests/UseCase/OrderedWithGetterAndSetterFirst/Regression/Case1.php @@ -17,1511 +17,1511 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'PHP' -type = $type; - $this->email = $email; - - $this->givenName = $givenName; - $this->familyName = $familyName; - $this->password = null; - $this->telephone = $telephone; - $this->picture = $picture; - $this->country = $country; - $this->countriesInCharge = $countriesInCharge ?: []; - $this->areasOfExpertise = $areasOfExpertise ?: []; - $this->status = $status; - $this->passType = $passType; - $this->jobTitle = $jobTitle; - $this->industry = $industry; - $this->seniority = $seniority; - $this->challenge = $challenge; - $this->assistant = $assistant; - $this->tripDetails = $tripDetails; - - $this->identifier = Uuid::generate(); - $this->password = null; - $this->registeredAt = new DateTimeImmutable(); - $this->linkedIn = new LinkedIn\Profile(); - $this->emailVerified = false; - - $this->pushStatusHistory($status); - - Assert::oneOf($type, [ - self::TYPE_ASSOCIATION, - self::TYPE_JOURNALIST, - self::TYPE_OWNER, - self::TYPE_STAFF, - self::TYPE_OTHER_GUEST, - self::TYPE_RETAILER, - self::TYPE_SPONSOR, - ]); - - Assert::oneOf($passType, [ - self::PASS_MEMBER, - self::PASS_ATTENDEE, - self::PASS_1_TO_1, - ]); - - if (null === $workFor) { - return; - } - - if ($workFor instanceof Organisation) { - $this->workForOrganisation = $workFor; - - return; - } - - if ($workFor instanceof Sponsor) { - $this->workForSponsor = $workFor; - - return; - } - - throw new LogicException('$workFor have to be an Organisation or a Sponsor'); - } - - public function getIdentifier(): string - { - return $this->identifier; - } - - public function getGivenName(): ?string - { - return $this->givenName; - } - - public function setGivenName(string $givenName) - { - $this->givenName = $givenName; - } - - public function getFamilyName(): ?string - { - return $this->familyName; - } - - public function setFamilyName(string $familyName) - { - $this->familyName = $familyName; - } - - public function getEmail(): string - { - return $this->email; - } - - public function setEmail(string $email) - { - if ($email !== $this->email) { - $this->emailVerified = false; - } - - $this->email = $email; - } - - public function getPassword(): ?string - { - return $this->password; - } - - public function setPassword(string $password) - { - $this->password = $password; - } - - public function getTelephone(): ?Telephone - { - if (null === $this->telephone) { - return null; - } - - return empty($this->telephone->getRegion()) || empty($this->telephone->getNationalNumber()) - ? null - : $this->telephone; - } - - public function setTelephone(Telephone $telephone) - { - $this->telephone = $telephone; - } - - public function getStatus(): string - { - return $this->status; - } - - public function setStatus(string $status) - { - $this->status = $status; - - $this->pushStatusHistory($status); - } - - public function getRegisteredAt(): DateTimeImmutable - { - return $this->registeredAt; - } - - public static function createASponsor( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $country = null, - array $countriesInCharge = null, - Sponsor $workFor = null, - string $jobTitle = null, - string $picture = null, - array $areasOfExpertise = [], - string $passType = self::PASS_MEMBER, - Assistant $assistant = null - ) { - return new self( - self::TYPE_SPONSOR, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - $countriesInCharge, - $workFor, - $areasOfExpertise, - self::STATUS_ACCEPTED, - $passType, - $jobTitle, - null, - null, - null, - $assistant - ); - } - - public static function createARetailer( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $picture = null, - string $country = null, - array $countriesInCharge = null, - Organisation $workFor = null, - string $jobTitle = null, - string $industry = null, - string $seniority = null, - string $challenge = null, - array $areasOfExpertise = null, - Assistant $assistant = null - ) { - return new self( - self::TYPE_RETAILER, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - $countriesInCharge, - $workFor, - $areasOfExpertise, - self::STATUS_INCOMPLETE, - self::PASS_ATTENDEE, - $jobTitle, - $industry, - $seniority, - $challenge, - $assistant - ); - } - - public static function createAStaff( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $country = null, - Organisation $workFor = null, - string $jobTitle = null, - string $picture = null - ) { - return new self( - self::TYPE_STAFF, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - [], - $workFor, - [], - self::STATUS_CONFIRMED, - self::PASS_ATTENDEE, - $jobTitle - ); - } - - public static function createAnAssociation( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $country = null, - Organisation $workFor = null, - string $jobTitle = null, - string $picture = null - ) { - return new self( - self::TYPE_ASSOCIATION, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - [], - $workFor, - [], - self::STATUS_ACCEPTED, - self::PASS_ATTENDEE, - $jobTitle - ); - } - - public static function createAJournalist( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $country = null, - Organisation $workFor = null, - string $jobTitle = null, - string $picture = null - ) { - return new self( - self::TYPE_JOURNALIST, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - [], - $workFor, - [], - self::STATUS_ACCEPTED, - self::PASS_ATTENDEE, - $jobTitle - ); - } - - public static function createAnOtherGuest( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $country = null, - Organisation $workFor = null, - string $jobTitle = null, - string $picture = null - ) { - return new self( - self::TYPE_OTHER_GUEST, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - [], - $workFor, - [], - self::STATUS_ACCEPTED, - self::PASS_ATTENDEE, - $jobTitle - ); - } - - public function isStaff(): bool - { - return in_array($this->type, [ - self::TYPE_OWNER, - self::TYPE_STAFF, - ]); - } - - public function isOwner(): bool - { - return self::TYPE_OWNER === $this->type; - } - - public function isEqualTo(self $other): bool - { - return $other->getIdentifier() === $this->getIdentifier(); - } - - public function getType(): string - { - return $this->type; - } - - public function getCountry(): ?string - { - return $this->country; - } - - public function setCountry(string $country) - { - $this->country = $country; - } - - public function getCountriesInCharge(): array - { - return $this->countriesInCharge; - } - - public function setCountriesInCharge(array $countriesInCharge) - { - $this->countriesInCharge = $countriesInCharge; - } - - public function getAreasOfExpertise(): array - { - return $this->areasOfExpertise; - } - - public function setAreasOfExpertise(array $areasOfExpertise) - { - $this->areasOfExpertise = $areasOfExpertise; - } - - public function getPassType(): ?string - { - return $this->passType; - } - - public function setPassType(string $passType = self::PASS_MEMBER) - { - Assert::oneOf($passType, [ - self::PASS_MEMBER, - self::PASS_ATTENDEE, - self::PASS_1_TO_1, - ]); - - $this->passType = $passType; - } - - public function getJobTitle(): ?string - { - return $this->jobTitle; - } - - public function setJobTitle(string $jobTitle) - { - $this->jobTitle = $jobTitle; - } - - public function getIndustry(): ?string - { - return $this->industry; - } - - public function setIndustry(string $industry) - { - $this->industry = $industry; - } - - public function getSeniority(): ?string - { - return $this->seniority; - } - - public function setSeniority(string $seniority) - { - $this->seniority = $seniority; - } - - public function getChallenge(): ?string - { - return $this->challenge; - } - - public function setChallenge(string $challenge) - { - $this->challenge = $challenge; - } - - /** - * @return null|Organisation|Sponsor - */ - public function getWorkFor() - { - if (null !== $this->workForSponsor) { - return $this->workForSponsor; - } - - if (null !== $this->workForOrganisation && !$this->workForOrganisation->empty()) { - return $this->workForOrganisation; - } - } - - public function setWorkFor(Organisation $workFor) - { - $this->workForOrganisation = $workFor; - } - - public function attachToInvitation(Invitation $invitation) - { - if (null !== $this->invitation) { - throw new LogicException('There is already an invitation linked to the attendee.'); - } - - $invitation->acceptedBy($this); - - $this->invitation = $invitation; - } - - public function getInvitation(): ?Invitation - { - return $this->invitation; - } - - public function getLinkedIn(): LinkedIn\Profile - { - return $this->linkedIn; - } - - public function setLinkedIn(LinkedIn\Profile $linkedIn) - { - $this->linkedIn = $linkedIn; - } - - public function getAssistant(): ?Assistant - { - if (null === $this->assistant || $this->assistant->empty()) { - return null; - } - - return $this->assistant; - } - - public function setAssistant(Assistant $assistant) - { - $this->assistant = $assistant; - } - - public function hasVerifiedEmail(): bool - { - return $this->emailVerified; - } - - public function markEmailAsVerified() - { - $this->emailVerified = true; - } - - public function getSentInvitations(): ?iterable - { - return $this->sentInvitations; - } - - public function getPicture(): ?string - { - return $this->picture; - } - - public function setPicture(string $picture) - { - $this->picture = $picture; - } - - public function getTripDetails(): ?TripDetails - { - return $this->tripDetails; - } - - public function setTripDetails(TripDetails $tripDetails) - { - $this->tripDetails = $tripDetails; - } - - public function getStatusHistory(): array - { - $history = []; - - foreach ($this->statusHistory as $row) { - list($status, $dateStr) = $row; - $date = new DateTimeImmutable($dateStr); - - if (false === isset($history[$status]) || $history[$status] < $date) { - $history[$status] = $date; + type = $type; + $this->email = $email; + + $this->givenName = $givenName; + $this->familyName = $familyName; + $this->password = null; + $this->telephone = $telephone; + $this->picture = $picture; + $this->country = $country; + $this->countriesInCharge = $countriesInCharge ?: []; + $this->areasOfExpertise = $areasOfExpertise ?: []; + $this->status = $status; + $this->passType = $passType; + $this->jobTitle = $jobTitle; + $this->industry = $industry; + $this->seniority = $seniority; + $this->challenge = $challenge; + $this->assistant = $assistant; + $this->tripDetails = $tripDetails; + + $this->identifier = Uuid::generate(); + $this->password = null; + $this->registeredAt = new DateTimeImmutable(); + $this->linkedIn = new LinkedIn\Profile(); + $this->emailVerified = false; + + $this->pushStatusHistory($status); + + Assert::oneOf($type, [ + self::TYPE_ASSOCIATION, + self::TYPE_JOURNALIST, + self::TYPE_OWNER, + self::TYPE_STAFF, + self::TYPE_OTHER_GUEST, + self::TYPE_RETAILER, + self::TYPE_SPONSOR, + ]); + + Assert::oneOf($passType, [ + self::PASS_MEMBER, + self::PASS_ATTENDEE, + self::PASS_1_TO_1, + ]); + + if (null === $workFor) { + return; + } + + if ($workFor instanceof Organisation) { + $this->workForOrganisation = $workFor; + + return; + } + + if ($workFor instanceof Sponsor) { + $this->workForSponsor = $workFor; + + return; + } + + throw new LogicException('$workFor have to be an Organisation or a Sponsor'); + } + + public function getIdentifier(): string + { + return $this->identifier; + } + + public function getGivenName(): ?string + { + return $this->givenName; + } + + public function setGivenName(string $givenName) + { + $this->givenName = $givenName; + } + + public function getFamilyName(): ?string + { + return $this->familyName; + } + + public function setFamilyName(string $familyName) + { + $this->familyName = $familyName; + } + + public function getEmail(): string + { + return $this->email; + } + + public function setEmail(string $email) + { + if ($email !== $this->email) { + $this->emailVerified = false; + } + + $this->email = $email; + } + + public function getPassword(): ?string + { + return $this->password; + } + + public function setPassword(string $password) + { + $this->password = $password; + } + + public function getTelephone(): ?Telephone + { + if (null === $this->telephone) { + return null; + } + + return empty($this->telephone->getRegion()) || empty($this->telephone->getNationalNumber()) + ? null + : $this->telephone; + } + + public function setTelephone(Telephone $telephone) + { + $this->telephone = $telephone; + } + + public function getStatus(): string + { + return $this->status; + } + + public function setStatus(string $status) + { + $this->status = $status; + + $this->pushStatusHistory($status); + } + + public function getRegisteredAt(): DateTimeImmutable + { + return $this->registeredAt; + } + + public static function createASponsor( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $country = null, + array $countriesInCharge = null, + Sponsor $workFor = null, + string $jobTitle = null, + string $picture = null, + array $areasOfExpertise = [], + string $passType = self::PASS_MEMBER, + Assistant $assistant = null + ) { + return new self( + self::TYPE_SPONSOR, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + $countriesInCharge, + $workFor, + $areasOfExpertise, + self::STATUS_ACCEPTED, + $passType, + $jobTitle, + null, + null, + null, + $assistant + ); + } + + public static function createARetailer( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $picture = null, + string $country = null, + array $countriesInCharge = null, + Organisation $workFor = null, + string $jobTitle = null, + string $industry = null, + string $seniority = null, + string $challenge = null, + array $areasOfExpertise = null, + Assistant $assistant = null + ) { + return new self( + self::TYPE_RETAILER, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + $countriesInCharge, + $workFor, + $areasOfExpertise, + self::STATUS_INCOMPLETE, + self::PASS_ATTENDEE, + $jobTitle, + $industry, + $seniority, + $challenge, + $assistant + ); + } + + public static function createAStaff( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $country = null, + Organisation $workFor = null, + string $jobTitle = null, + string $picture = null + ) { + return new self( + self::TYPE_STAFF, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + [], + $workFor, + [], + self::STATUS_CONFIRMED, + self::PASS_ATTENDEE, + $jobTitle + ); + } + + public static function createAnAssociation( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $country = null, + Organisation $workFor = null, + string $jobTitle = null, + string $picture = null + ) { + return new self( + self::TYPE_ASSOCIATION, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + [], + $workFor, + [], + self::STATUS_ACCEPTED, + self::PASS_ATTENDEE, + $jobTitle + ); + } + + public static function createAJournalist( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $country = null, + Organisation $workFor = null, + string $jobTitle = null, + string $picture = null + ) { + return new self( + self::TYPE_JOURNALIST, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + [], + $workFor, + [], + self::STATUS_ACCEPTED, + self::PASS_ATTENDEE, + $jobTitle + ); + } + + public static function createAnOtherGuest( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $country = null, + Organisation $workFor = null, + string $jobTitle = null, + string $picture = null + ) { + return new self( + self::TYPE_OTHER_GUEST, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + [], + $workFor, + [], + self::STATUS_ACCEPTED, + self::PASS_ATTENDEE, + $jobTitle + ); + } + + public function isStaff(): bool + { + return in_array($this->type, [ + self::TYPE_OWNER, + self::TYPE_STAFF, + ]); + } + + public function isOwner(): bool + { + return self::TYPE_OWNER === $this->type; + } + + public function isEqualTo(self $other): bool + { + return $other->getIdentifier() === $this->getIdentifier(); + } + + public function getType(): string + { + return $this->type; + } + + public function getCountry(): ?string + { + return $this->country; + } + + public function setCountry(string $country) + { + $this->country = $country; + } + + public function getCountriesInCharge(): array + { + return $this->countriesInCharge; + } + + public function setCountriesInCharge(array $countriesInCharge) + { + $this->countriesInCharge = $countriesInCharge; + } + + public function getAreasOfExpertise(): array + { + return $this->areasOfExpertise; + } + + public function setAreasOfExpertise(array $areasOfExpertise) + { + $this->areasOfExpertise = $areasOfExpertise; + } + + public function getPassType(): ?string + { + return $this->passType; + } + + public function setPassType(string $passType = self::PASS_MEMBER) + { + Assert::oneOf($passType, [ + self::PASS_MEMBER, + self::PASS_ATTENDEE, + self::PASS_1_TO_1, + ]); + + $this->passType = $passType; + } + + public function getJobTitle(): ?string + { + return $this->jobTitle; + } + + public function setJobTitle(string $jobTitle) + { + $this->jobTitle = $jobTitle; + } + + public function getIndustry(): ?string + { + return $this->industry; + } + + public function setIndustry(string $industry) + { + $this->industry = $industry; + } + + public function getSeniority(): ?string + { + return $this->seniority; + } + + public function setSeniority(string $seniority) + { + $this->seniority = $seniority; + } + + public function getChallenge(): ?string + { + return $this->challenge; + } + + public function setChallenge(string $challenge) + { + $this->challenge = $challenge; + } + + /** + * @return null|Organisation|Sponsor + */ + public function getWorkFor() + { + if (null !== $this->workForSponsor) { + return $this->workForSponsor; + } + + if (null !== $this->workForOrganisation && !$this->workForOrganisation->empty()) { + return $this->workForOrganisation; + } + } + + public function setWorkFor(Organisation $workFor) + { + $this->workForOrganisation = $workFor; + } + + public function attachToInvitation(Invitation $invitation) + { + if (null !== $this->invitation) { + throw new LogicException('There is already an invitation linked to the attendee.'); + } + + $invitation->acceptedBy($this); + + $this->invitation = $invitation; + } + + public function getInvitation(): ?Invitation + { + return $this->invitation; + } + + public function getLinkedIn(): LinkedIn\Profile + { + return $this->linkedIn; + } + + public function setLinkedIn(LinkedIn\Profile $linkedIn) + { + $this->linkedIn = $linkedIn; + } + + public function getAssistant(): ?Assistant + { + if (null === $this->assistant || $this->assistant->empty()) { + return null; + } + + return $this->assistant; + } + + public function setAssistant(Assistant $assistant) + { + $this->assistant = $assistant; + } + + public function hasVerifiedEmail(): bool + { + return $this->emailVerified; + } + + public function markEmailAsVerified() + { + $this->emailVerified = true; + } + + public function getSentInvitations(): ?iterable + { + return $this->sentInvitations; + } + + public function getPicture(): ?string + { + return $this->picture; + } + + public function setPicture(string $picture) + { + $this->picture = $picture; + } + + public function getTripDetails(): ?TripDetails + { + return $this->tripDetails; + } + + public function setTripDetails(TripDetails $tripDetails) + { + $this->tripDetails = $tripDetails; + } + + public function getStatusHistory(): array + { + $history = []; + + foreach ($this->statusHistory as $row) { + list($status, $dateStr) = $row; + $date = new DateTimeImmutable($dateStr); + + if (false === isset($history[$status]) || $history[$status] < $date) { + $history[$status] = $date; + } + } + + asort($history); + + return $history; + } + + private function pushStatusHistory(string $status) + { + if (false === empty($this->statusHistory)) { + $last = end($this->statusHistory); + list($lastStatus, $dateStr) = $last; + + if ($status === $lastStatus) { + return; + } + } + + $this->statusHistory[] = [ + $status, + date('c'), + ]; + } } - } - - asort($history); - - return $history; - } - - private function pushStatusHistory(string $status) - { - if (false === empty($this->statusHistory)) { - $last = end($this->statusHistory); - list($lastStatus, $dateStr) = $last; - - if ($status === $lastStatus) { - return; - } - } - - $this->statusHistory[] = [ - $status, - date('c'), - ]; - } -} -PHP; + PHP; } public function getExpectation(): string { return <<<'PHP' -type = $type; - $this->email = $email; - - $this->givenName = $givenName; - $this->familyName = $familyName; - $this->password = null; - $this->telephone = $telephone; - $this->picture = $picture; - $this->country = $country; - $this->countriesInCharge = $countriesInCharge ?: []; - $this->areasOfExpertise = $areasOfExpertise ?: []; - $this->status = $status; - $this->passType = $passType; - $this->jobTitle = $jobTitle; - $this->industry = $industry; - $this->seniority = $seniority; - $this->challenge = $challenge; - $this->assistant = $assistant; - $this->tripDetails = $tripDetails; - - $this->identifier = Uuid::generate(); - $this->password = null; - $this->registeredAt = new DateTimeImmutable(); - $this->linkedIn = new LinkedIn\Profile(); - $this->emailVerified = false; - - $this->pushStatusHistory($status); - - Assert::oneOf($type, [ - self::TYPE_ASSOCIATION, - self::TYPE_JOURNALIST, - self::TYPE_OWNER, - self::TYPE_STAFF, - self::TYPE_OTHER_GUEST, - self::TYPE_RETAILER, - self::TYPE_SPONSOR, - ]); - - Assert::oneOf($passType, [ - self::PASS_MEMBER, - self::PASS_ATTENDEE, - self::PASS_1_TO_1, - ]); - - if (null === $workFor) { - return; - } - - if ($workFor instanceof Organisation) { - $this->workForOrganisation = $workFor; - - return; - } - - if ($workFor instanceof Sponsor) { - $this->workForSponsor = $workFor; - - return; - } - - throw new LogicException('$workFor have to be an Organisation or a Sponsor'); - } - - public function getIdentifier(): string - { - return $this->identifier; - } - - public function getGivenName(): ?string - { - return $this->givenName; - } - - public function setGivenName(string $givenName) - { - $this->givenName = $givenName; - } - - public function getFamilyName(): ?string - { - return $this->familyName; - } - - public function setFamilyName(string $familyName) - { - $this->familyName = $familyName; - } - - public function getEmail(): string - { - return $this->email; - } - - public function setEmail(string $email) - { - if ($email !== $this->email) { - $this->emailVerified = false; - } - - $this->email = $email; - } - - public function getPassword(): ?string - { - return $this->password; - } - - public function setPassword(string $password) - { - $this->password = $password; - } - - public function getTelephone(): ?Telephone - { - if (null === $this->telephone) { - return null; - } - - return empty($this->telephone->getRegion()) || empty($this->telephone->getNationalNumber()) - ? null - : $this->telephone; - } - - public function setTelephone(Telephone $telephone) - { - $this->telephone = $telephone; - } - - public function getStatus(): string - { - return $this->status; - } - - public function setStatus(string $status) - { - $this->status = $status; - - $this->pushStatusHistory($status); - } - - public function getRegisteredAt(): DateTimeImmutable - { - return $this->registeredAt; - } - - public function getCountry(): ?string - { - return $this->country; - } - - public function setCountry(string $country) - { - $this->country = $country; - } - - public function getCountriesInCharge(): array - { - return $this->countriesInCharge; - } - - public function setCountriesInCharge(array $countriesInCharge) - { - $this->countriesInCharge = $countriesInCharge; - } - - public function getAreasOfExpertise(): array - { - return $this->areasOfExpertise; - } - - public function setAreasOfExpertise(array $areasOfExpertise) - { - $this->areasOfExpertise = $areasOfExpertise; - } - - public function getLinkedIn(): LinkedIn\Profile - { - return $this->linkedIn; - } - - public function setLinkedIn(LinkedIn\Profile $linkedIn) - { - $this->linkedIn = $linkedIn; - } - - public function getPassType(): ?string - { - return $this->passType; - } - - public function setPassType(string $passType = self::PASS_MEMBER) - { - Assert::oneOf($passType, [ - self::PASS_MEMBER, - self::PASS_ATTENDEE, - self::PASS_1_TO_1, - ]); - - $this->passType = $passType; - } - - public function getJobTitle(): ?string - { - return $this->jobTitle; - } - - public function setJobTitle(string $jobTitle) - { - $this->jobTitle = $jobTitle; - } - - public function getIndustry(): ?string - { - return $this->industry; - } - - public function setIndustry(string $industry) - { - $this->industry = $industry; - } - - public function getSeniority(): ?string - { - return $this->seniority; - } - - public function setSeniority(string $seniority) - { - $this->seniority = $seniority; - } - - public function getChallenge(): ?string - { - return $this->challenge; - } - - public function setChallenge(string $challenge) - { - $this->challenge = $challenge; - } - - public function getInvitation(): ?Invitation - { - return $this->invitation; - } - - public function getAssistant(): ?Assistant - { - if (null === $this->assistant || $this->assistant->empty()) { - return null; - } - - return $this->assistant; - } - - public function setAssistant(Assistant $assistant) - { - $this->assistant = $assistant; - } - - public function getType(): string - { - return $this->type; - } - - public function getSentInvitations(): ?iterable - { - return $this->sentInvitations; - } - - public function getPicture(): ?string - { - return $this->picture; - } - - public function setPicture(string $picture) - { - $this->picture = $picture; - } - - public function getTripDetails(): ?TripDetails - { - return $this->tripDetails; - } - - public function setTripDetails(TripDetails $tripDetails) - { - $this->tripDetails = $tripDetails; - } - - public function getStatusHistory(): array - { - $history = []; - - foreach ($this->statusHistory as $row) { - list($status, $dateStr) = $row; - $date = new DateTimeImmutable($dateStr); - - if (false === isset($history[$status]) || $history[$status] < $date) { - $history[$status] = $date; + type = $type; + $this->email = $email; + + $this->givenName = $givenName; + $this->familyName = $familyName; + $this->password = null; + $this->telephone = $telephone; + $this->picture = $picture; + $this->country = $country; + $this->countriesInCharge = $countriesInCharge ?: []; + $this->areasOfExpertise = $areasOfExpertise ?: []; + $this->status = $status; + $this->passType = $passType; + $this->jobTitle = $jobTitle; + $this->industry = $industry; + $this->seniority = $seniority; + $this->challenge = $challenge; + $this->assistant = $assistant; + $this->tripDetails = $tripDetails; + + $this->identifier = Uuid::generate(); + $this->password = null; + $this->registeredAt = new DateTimeImmutable(); + $this->linkedIn = new LinkedIn\Profile(); + $this->emailVerified = false; + + $this->pushStatusHistory($status); + + Assert::oneOf($type, [ + self::TYPE_ASSOCIATION, + self::TYPE_JOURNALIST, + self::TYPE_OWNER, + self::TYPE_STAFF, + self::TYPE_OTHER_GUEST, + self::TYPE_RETAILER, + self::TYPE_SPONSOR, + ]); + + Assert::oneOf($passType, [ + self::PASS_MEMBER, + self::PASS_ATTENDEE, + self::PASS_1_TO_1, + ]); + + if (null === $workFor) { + return; + } + + if ($workFor instanceof Organisation) { + $this->workForOrganisation = $workFor; + + return; + } + + if ($workFor instanceof Sponsor) { + $this->workForSponsor = $workFor; + + return; + } + + throw new LogicException('$workFor have to be an Organisation or a Sponsor'); + } + + public function getIdentifier(): string + { + return $this->identifier; + } + + public function getGivenName(): ?string + { + return $this->givenName; + } + + public function setGivenName(string $givenName) + { + $this->givenName = $givenName; + } + + public function getFamilyName(): ?string + { + return $this->familyName; + } + + public function setFamilyName(string $familyName) + { + $this->familyName = $familyName; + } + + public function getEmail(): string + { + return $this->email; + } + + public function setEmail(string $email) + { + if ($email !== $this->email) { + $this->emailVerified = false; + } + + $this->email = $email; + } + + public function getPassword(): ?string + { + return $this->password; + } + + public function setPassword(string $password) + { + $this->password = $password; + } + + public function getTelephone(): ?Telephone + { + if (null === $this->telephone) { + return null; + } + + return empty($this->telephone->getRegion()) || empty($this->telephone->getNationalNumber()) + ? null + : $this->telephone; + } + + public function setTelephone(Telephone $telephone) + { + $this->telephone = $telephone; + } + + public function getStatus(): string + { + return $this->status; + } + + public function setStatus(string $status) + { + $this->status = $status; + + $this->pushStatusHistory($status); + } + + public function getRegisteredAt(): DateTimeImmutable + { + return $this->registeredAt; + } + + public function getCountry(): ?string + { + return $this->country; + } + + public function setCountry(string $country) + { + $this->country = $country; + } + + public function getCountriesInCharge(): array + { + return $this->countriesInCharge; + } + + public function setCountriesInCharge(array $countriesInCharge) + { + $this->countriesInCharge = $countriesInCharge; + } + + public function getAreasOfExpertise(): array + { + return $this->areasOfExpertise; + } + + public function setAreasOfExpertise(array $areasOfExpertise) + { + $this->areasOfExpertise = $areasOfExpertise; + } + + public function getLinkedIn(): LinkedIn\Profile + { + return $this->linkedIn; + } + + public function setLinkedIn(LinkedIn\Profile $linkedIn) + { + $this->linkedIn = $linkedIn; + } + + public function getPassType(): ?string + { + return $this->passType; + } + + public function setPassType(string $passType = self::PASS_MEMBER) + { + Assert::oneOf($passType, [ + self::PASS_MEMBER, + self::PASS_ATTENDEE, + self::PASS_1_TO_1, + ]); + + $this->passType = $passType; + } + + public function getJobTitle(): ?string + { + return $this->jobTitle; + } + + public function setJobTitle(string $jobTitle) + { + $this->jobTitle = $jobTitle; + } + + public function getIndustry(): ?string + { + return $this->industry; + } + + public function setIndustry(string $industry) + { + $this->industry = $industry; + } + + public function getSeniority(): ?string + { + return $this->seniority; + } + + public function setSeniority(string $seniority) + { + $this->seniority = $seniority; + } + + public function getChallenge(): ?string + { + return $this->challenge; + } + + public function setChallenge(string $challenge) + { + $this->challenge = $challenge; + } + + public function getInvitation(): ?Invitation + { + return $this->invitation; + } + + public function getAssistant(): ?Assistant + { + if (null === $this->assistant || $this->assistant->empty()) { + return null; + } + + return $this->assistant; + } + + public function setAssistant(Assistant $assistant) + { + $this->assistant = $assistant; + } + + public function getType(): string + { + return $this->type; + } + + public function getSentInvitations(): ?iterable + { + return $this->sentInvitations; + } + + public function getPicture(): ?string + { + return $this->picture; + } + + public function setPicture(string $picture) + { + $this->picture = $picture; + } + + public function getTripDetails(): ?TripDetails + { + return $this->tripDetails; + } + + public function setTripDetails(TripDetails $tripDetails) + { + $this->tripDetails = $tripDetails; + } + + public function getStatusHistory(): array + { + $history = []; + + foreach ($this->statusHistory as $row) { + list($status, $dateStr) = $row; + $date = new DateTimeImmutable($dateStr); + + if (false === isset($history[$status]) || $history[$status] < $date) { + $history[$status] = $date; + } + } + + asort($history); + + return $history; + } + + public static function createASponsor( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $country = null, + array $countriesInCharge = null, + Sponsor $workFor = null, + string $jobTitle = null, + string $picture = null, + array $areasOfExpertise = [], + string $passType = self::PASS_MEMBER, + Assistant $assistant = null + ) { + return new self( + self::TYPE_SPONSOR, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + $countriesInCharge, + $workFor, + $areasOfExpertise, + self::STATUS_ACCEPTED, + $passType, + $jobTitle, + null, + null, + null, + $assistant + ); + } + + public static function createARetailer( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $picture = null, + string $country = null, + array $countriesInCharge = null, + Organisation $workFor = null, + string $jobTitle = null, + string $industry = null, + string $seniority = null, + string $challenge = null, + array $areasOfExpertise = null, + Assistant $assistant = null + ) { + return new self( + self::TYPE_RETAILER, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + $countriesInCharge, + $workFor, + $areasOfExpertise, + self::STATUS_INCOMPLETE, + self::PASS_ATTENDEE, + $jobTitle, + $industry, + $seniority, + $challenge, + $assistant + ); + } + + public static function createAStaff( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $country = null, + Organisation $workFor = null, + string $jobTitle = null, + string $picture = null + ) { + return new self( + self::TYPE_STAFF, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + [], + $workFor, + [], + self::STATUS_CONFIRMED, + self::PASS_ATTENDEE, + $jobTitle + ); + } + + public static function createAnAssociation( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $country = null, + Organisation $workFor = null, + string $jobTitle = null, + string $picture = null + ) { + return new self( + self::TYPE_ASSOCIATION, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + [], + $workFor, + [], + self::STATUS_ACCEPTED, + self::PASS_ATTENDEE, + $jobTitle + ); + } + + public static function createAJournalist( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $country = null, + Organisation $workFor = null, + string $jobTitle = null, + string $picture = null + ) { + return new self( + self::TYPE_JOURNALIST, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + [], + $workFor, + [], + self::STATUS_ACCEPTED, + self::PASS_ATTENDEE, + $jobTitle + ); + } + + public static function createAnOtherGuest( + string $email, + string $givenName = null, + string $familyName = null, + Telephone $telephone = null, + string $country = null, + Organisation $workFor = null, + string $jobTitle = null, + string $picture = null + ) { + return new self( + self::TYPE_OTHER_GUEST, + $email, + $givenName, + $familyName, + $telephone, + $picture, + $country, + [], + $workFor, + [], + self::STATUS_ACCEPTED, + self::PASS_ATTENDEE, + $jobTitle + ); + } + + public function isStaff(): bool + { + return in_array($this->type, [ + self::TYPE_OWNER, + self::TYPE_STAFF, + ]); + } + + public function isOwner(): bool + { + return self::TYPE_OWNER === $this->type; + } + + public function isEqualTo(self $other): bool + { + return $other->getIdentifier() === $this->getIdentifier(); + } + + /** + * @return null|Organisation|Sponsor + */ + public function getWorkFor() + { + if (null !== $this->workForSponsor) { + return $this->workForSponsor; + } + + if (null !== $this->workForOrganisation && !$this->workForOrganisation->empty()) { + return $this->workForOrganisation; + } + } + + public function setWorkFor(Organisation $workFor) + { + $this->workForOrganisation = $workFor; + } + + public function attachToInvitation(Invitation $invitation) + { + if (null !== $this->invitation) { + throw new LogicException('There is already an invitation linked to the attendee.'); + } + + $invitation->acceptedBy($this); + + $this->invitation = $invitation; + } + + public function hasVerifiedEmail(): bool + { + return $this->emailVerified; + } + + public function markEmailAsVerified() + { + $this->emailVerified = true; + } + + private function pushStatusHistory(string $status) + { + if (false === empty($this->statusHistory)) { + $last = end($this->statusHistory); + list($lastStatus, $dateStr) = $last; + + if ($status === $lastStatus) { + return; + } + } + + $this->statusHistory[] = [ + $status, + date('c'), + ]; + } } - } - - asort($history); - - return $history; - } - - public static function createASponsor( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $country = null, - array $countriesInCharge = null, - Sponsor $workFor = null, - string $jobTitle = null, - string $picture = null, - array $areasOfExpertise = [], - string $passType = self::PASS_MEMBER, - Assistant $assistant = null - ) { - return new self( - self::TYPE_SPONSOR, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - $countriesInCharge, - $workFor, - $areasOfExpertise, - self::STATUS_ACCEPTED, - $passType, - $jobTitle, - null, - null, - null, - $assistant - ); - } - - public static function createARetailer( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $picture = null, - string $country = null, - array $countriesInCharge = null, - Organisation $workFor = null, - string $jobTitle = null, - string $industry = null, - string $seniority = null, - string $challenge = null, - array $areasOfExpertise = null, - Assistant $assistant = null - ) { - return new self( - self::TYPE_RETAILER, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - $countriesInCharge, - $workFor, - $areasOfExpertise, - self::STATUS_INCOMPLETE, - self::PASS_ATTENDEE, - $jobTitle, - $industry, - $seniority, - $challenge, - $assistant - ); - } - - public static function createAStaff( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $country = null, - Organisation $workFor = null, - string $jobTitle = null, - string $picture = null - ) { - return new self( - self::TYPE_STAFF, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - [], - $workFor, - [], - self::STATUS_CONFIRMED, - self::PASS_ATTENDEE, - $jobTitle - ); - } - - public static function createAnAssociation( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $country = null, - Organisation $workFor = null, - string $jobTitle = null, - string $picture = null - ) { - return new self( - self::TYPE_ASSOCIATION, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - [], - $workFor, - [], - self::STATUS_ACCEPTED, - self::PASS_ATTENDEE, - $jobTitle - ); - } - - public static function createAJournalist( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $country = null, - Organisation $workFor = null, - string $jobTitle = null, - string $picture = null - ) { - return new self( - self::TYPE_JOURNALIST, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - [], - $workFor, - [], - self::STATUS_ACCEPTED, - self::PASS_ATTENDEE, - $jobTitle - ); - } - - public static function createAnOtherGuest( - string $email, - string $givenName = null, - string $familyName = null, - Telephone $telephone = null, - string $country = null, - Organisation $workFor = null, - string $jobTitle = null, - string $picture = null - ) { - return new self( - self::TYPE_OTHER_GUEST, - $email, - $givenName, - $familyName, - $telephone, - $picture, - $country, - [], - $workFor, - [], - self::STATUS_ACCEPTED, - self::PASS_ATTENDEE, - $jobTitle - ); - } - - public function isStaff(): bool - { - return in_array($this->type, [ - self::TYPE_OWNER, - self::TYPE_STAFF, - ]); - } - - public function isOwner(): bool - { - return self::TYPE_OWNER === $this->type; - } - - public function isEqualTo(self $other): bool - { - return $other->getIdentifier() === $this->getIdentifier(); - } - - /** - * @return null|Organisation|Sponsor - */ - public function getWorkFor() - { - if (null !== $this->workForSponsor) { - return $this->workForSponsor; - } - - if (null !== $this->workForOrganisation && !$this->workForOrganisation->empty()) { - return $this->workForOrganisation; - } - } - - public function setWorkFor(Organisation $workFor) - { - $this->workForOrganisation = $workFor; - } - - public function attachToInvitation(Invitation $invitation) - { - if (null !== $this->invitation) { - throw new LogicException('There is already an invitation linked to the attendee.'); - } - - $invitation->acceptedBy($this); - - $this->invitation = $invitation; - } - - public function hasVerifiedEmail(): bool - { - return $this->emailVerified; - } - - public function markEmailAsVerified() - { - $this->emailVerified = true; - } - - private function pushStatusHistory(string $status) - { - if (false === empty($this->statusHistory)) { - $last = end($this->statusHistory); - list($lastStatus, $dateStr) = $last; - - if ($status === $lastStatus) { - return; - } - } - - $this->statusHistory[] = [ - $status, - date('c'), - ]; - } -} -PHP; + PHP; } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/OrderedWithGetterAndSetterFirst/Regression/Case2.php b/tests/UseCase/OrderedWithGetterAndSetterFirst/Regression/Case2.php index e73c419..fced081 100644 --- a/tests/UseCase/OrderedWithGetterAndSetterFirst/Regression/Case2.php +++ b/tests/UseCase/OrderedWithGetterAndSetterFirst/Regression/Case2.php @@ -17,58 +17,58 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'PHP' -beConstructedWith($start, $end, 'Europe/London'); - } - - function it_is_initializable() - { - $this->shouldHaveType(Slot\Free::class); - $this->shouldImplement(Slot::class); - } - - function it_has_an_unique_identifier_for_its_period_of_time() - { - $this->getIdentifier()->shouldReturn('20180626-1600-1630'); - } - - function it_has_a_start_date() - { - $this - ->getStartAt() - ->shouldBeLike(new DateTimeImmutable('4:00pm 26-06-2018', new DateTimezone('Europe/London'))) - ; - } - - function it_has_a_end_date() - { - $this - ->getEndAt() - ->shouldbeLike(new DateTimeImmutable('4:30pm 26-06-2018', new DateTimezone('Europe/London'))) - ; - } - - function it_is_free() - { - $this->isFree()->shouldReturn(true); - } -} -PHP; + beConstructedWith($start, $end, 'Europe/London'); + } + + function it_is_initializable() + { + $this->shouldHaveType(Slot\Free::class); + $this->shouldImplement(Slot::class); + } + + function it_has_an_unique_identifier_for_its_period_of_time() + { + $this->getIdentifier()->shouldReturn('20180626-1600-1630'); + } + + function it_has_a_start_date() + { + $this + ->getStartAt() + ->shouldBeLike(new DateTimeImmutable('4:00pm 26-06-2018', new DateTimezone('Europe/London'))) + ; + } + + function it_has_a_end_date() + { + $this + ->getEndAt() + ->shouldbeLike(new DateTimeImmutable('4:30pm 26-06-2018', new DateTimezone('Europe/London'))) + ; + } + + function it_is_free() + { + $this->isFree()->shouldReturn(true); + } + } + PHP; } public function getExpectation(): string diff --git a/tests/UseCase/Phpspec.php b/tests/UseCase/Phpspec.php index 0efa0c4..dafcbd4 100644 --- a/tests/UseCase/Phpspec.php +++ b/tests/UseCase/Phpspec.php @@ -21,116 +21,116 @@ public function getFixers(): iterable public function getRawScript(): string { return <<<'SPEC' -configure([ - 'action' => 'collapsed', - 'types' => ['@var'], - ]); - - yield $fixer; - } - - public function getRawScript(): string - { - return <<<'PHP' -configure([ - 'action' => 'expanded', - 'types' => ['@var'], - ]); - - yield $fixer; - } - - public function getRawScript(): string - { - return <<<'PHP' -setName('foo'); - - return $this; - } - - /** - * @return string|null - */ - public function getName() - { - switch (empty($this->name)) { - case true: - return ''; - case false: - return $this->name; - } - } - - /** - * @return callable - */ - public function buildCallable() - { - return function () { return true; return false; }; - } -} -PHP; + setName('foo'); + + return $this; + } + + /** + * @return string|null + */ + public function getName() + { + switch (empty($this->name)) { + case true: + return ''; + case false: + return $this->name; + } + } + + /** + * @return callable + */ + public function buildCallable() + { + return function () { return true; return false; }; + } + } + PHP; } public function getExpectation(): string { return <<<'PHP' -name)) { - case true: - return ''; - case false: - return $this->name; - } - } - - /** - * @return callable - */ - public function buildCallable() - { - return function () { return true; }; - } -} -PHP; + name)) { + case true: + return ''; + case false: + return $this->name; + } + } + + /** + * @return callable + */ + public function buildCallable() + { + return function () { return true; }; + } + } + PHP; } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/UselessComment.php b/tests/UseCase/UselessComment.php deleted file mode 100644 index 756d194..0000000 --- a/tests/UseCase/UselessComment.php +++ /dev/null @@ -1,74 +0,0 @@ -user; - } - - /** - * @param User $user - */ - public function setUser(User $user) - { - $this->user = $user; - } -} -PHP; - } - - public function getExpectation(): string - { - return <<<'PHP' -user; - } - - public function setUser(User $user) - { - $this->user = $user; - } -} -PHP; - } - - public function getMinSupportedPhpVersion(): int - { - return 0; - } -} diff --git a/tests/UseCase/UselessComment/Php71.php b/tests/UseCase/UselessComment/Php71.php deleted file mode 100644 index 4d59e04..0000000 --- a/tests/UseCase/UselessComment/Php71.php +++ /dev/null @@ -1,79 +0,0 @@ -name; - } - - /** - * @param string $name - * - * @return void - */ - public function setName(string $name): void - { - $this->name = $name; - } -} -PHP; - } - - public function getExpectation(): string - { - return <<<'PHP' -name; - } - - public function setName(string $name): void - { - $this->name = $name; - } -} -PHP; - } - - public function getMinSupportedPhpVersion(): int - { - return 70100; - } -} diff --git a/tests/UseCase/UselessComment/Regression/DocBlockEnd.php b/tests/UseCase/UselessComment/Regression/DocBlockEnd.php deleted file mode 100644 index a87e64a..0000000 --- a/tests/UseCase/UselessComment/Regression/DocBlockEnd.php +++ /dev/null @@ -1,89 +0,0 @@ -canPublish($attribute, $subject, $user); - } - - /** - * @param string $attribute - * @param mixed $subject - * @param User $user - * - * @return bool - */ - public function canPublish(string $attribute, $subject, User $user): bool - { - return $this->canEdit($attribute, $subject, $user); - } -} -PHP; - } - - public function getExpectation(): string - { - return <<<'PHP' -canPublish($attribute, $subject, $user); - } - - /** - * @param mixed $subject - */ - public function canPublish(string $attribute, $subject, User $user): bool - { - return $this->canEdit($attribute, $subject, $user); - } -} -PHP; - } - - public function getMinSupportedPhpVersion(): int - { - return 70100; - } -} diff --git a/tests/UseCase/UselessComment/Regression/DoubleLineBreak.php b/tests/UseCase/UselessComment/Regression/DoubleLineBreak.php deleted file mode 100644 index 681ce76..0000000 --- a/tests/UseCase/UselessComment/Regression/DoubleLineBreak.php +++ /dev/null @@ -1,77 +0,0 @@ -user = $user; - - return $this; - } -} -PHP; - } - - public function getExpectation(): string - { - return <<<'PHP' -user = $user; - - return $this; - } -} -PHP; - } - - public function getMinSupportedPhpVersion(): int - { - return 0; - } -} diff --git a/tests/UseCase/UselessComment/Regression/WithInterface.php b/tests/UseCase/UselessComment/Regression/WithInterface.php deleted file mode 100644 index 4844643..0000000 --- a/tests/UseCase/UselessComment/Regression/WithInterface.php +++ /dev/null @@ -1,73 +0,0 @@ - - */ -interface TokenGeneratorInterface -{ - /** - * @return string - */ - public function lifetime(array $payloads, DateTimeInterface $expiredAt): string; - - /** - * @return string - */ - public function disposable(array $payloads, DateTimeInterface $expiredAt = null): string; -} -PHP; - } - - public function getExpectation(): string - { - return <<<'PHP' - - */ -interface TokenGeneratorInterface -{ - public function lifetime(array $payloads, DateTimeInterface $expiredAt): string; - - public function disposable(array $payloads, DateTimeInterface $expiredAt = null): string; -} -PHP; - } - - public function getMinSupportedPhpVersion(): int - { - return 70000; - } -}