diff --git a/.gitignore b/.gitignore index 81f96c8..6b6c207 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ composer.lock npm-debug.log /test/coverage/ -/vendor/ \ No newline at end of file +/vendor/ diff --git a/.travis.yml b/.travis.yml index 4fe5807..31c6f97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,9 @@ language: php php: - "5.6" -# - "7.2" + - "7.0" + - "7.1" + - "7.2" env: - TRAVIS_CI=true install: diff --git a/composer.json b/composer.json index beb5c17..bdd3657 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,9 @@ "require-dev": { "phpunit/phpunit": "^5.7.5" }, + "conflict": { + "sebastian/comparator": "1.2.2" + }, "autoload": { "psr-4": { "Coffreo\\PhpCsFixer\\Config\\": "src" diff --git a/src/Factory.php b/src/Factory.php index 1206bdb..7aeca18 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -16,8 +16,6 @@ final class Factory { /** - * @param RuleSet $ruleSet - * * @throws \RuntimeException * * @return Config @@ -25,11 +23,7 @@ final class Factory public static function fromRuleSet(RuleSet $ruleSet) { if (PHP_VERSION_ID < $ruleSet->targetPhpVersion()) { - throw new \RuntimeException(\sprintf( - 'Current PHP version "%s is less than targeted PHP version "%s".', - PHP_VERSION_ID, - $ruleSet->targetPhpVersion() - )); + throw new \RuntimeException(\sprintf('Current PHP version "%s is less than targeted PHP version "%s".', PHP_VERSION_ID, $ruleSet->targetPhpVersion())); } $config = new Config($ruleSet->name()); diff --git a/src/RuleSet/AbstractRuleSet.php b/src/RuleSet/AbstractRuleSet.php index 388c989..4737cb4 100644 --- a/src/RuleSet/AbstractRuleSet.php +++ b/src/RuleSet/AbstractRuleSet.php @@ -45,17 +45,11 @@ final public function __construct($header = null) } if (!\is_string($header)) { - throw new \InvalidArgumentException(\sprintf( - 'Header needs to be specified as null or a string. Got "%s" instead.', - \is_object($header) ? \get_class($header) : \gettype($header) - )); + throw new \InvalidArgumentException(\sprintf('Header needs to be specified as null or a string. Got "%s" instead.', \is_object($header) ? \get_class($header) : \gettype($header))); } if ('' === \trim($header)) { - throw new \InvalidArgumentException(\sprintf( - 'If specified, header needs to be a non-blank string. Got "%s" instead.', - $header - )); + throw new \InvalidArgumentException(\sprintf('If specified, header needs to be a non-blank string. Got "%s" instead.', $header)); } $this->rules['header_comment'] = [ diff --git a/src/RuleSet/Php72.php b/src/RuleSet/Php72.php new file mode 100644 index 0000000..8e19f8e --- /dev/null +++ b/src/RuleSet/Php72.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Coffreo\PhpCsFixer\Config\RuleSet; + +final class Php72 extends AbstractRuleSet +{ + protected $name = 'Coffreo (PHP 7.2)'; + + protected $rules = [ + '@Symfony' => true, + '@PHP71Migration' => true, + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'class_keyword_remove' => false, + 'combine_consecutive_unsets' => true, + 'declare_strict_types' => true, + 'dir_constant' => false, + 'doctrine_annotation_braces' => [ + 'syntax' => 'without_braces', + ], + 'doctrine_annotation_indentation' => true, + 'doctrine_annotation_spaces' => true, + 'ereg_to_preg' => true, + 'function_to_constant' => true, + 'general_phpdoc_annotation_remove' => false, + 'header_comment' => false, + 'heredoc_to_nowdoc' => true, + 'is_null' => [ + 'use_yoda_style' => true, + ], + 'linebreak_after_opening_tag' => true, + 'list_syntax' => [ + 'syntax' => 'short', + ], + 'mb_str_functions' => true, + 'modernize_types_casting' => true, + 'native_function_invocation' => true, + 'no_alias_functions' => true, + 'no_blank_lines_before_namespace' => false, + 'no_multiline_whitespace_before_semicolons' => true, + 'no_php4_constructor' => false, + 'no_short_echo_tag' => true, + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'non_printable_character' => true, + 'not_operator_with_space' => false, + 'not_operator_with_successor_space' => false, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_construct' => true, + 'php_unit_dedicate_assert' => true, + 'php_unit_strict' => false, + 'php_unit_test_class_requires_covers' => false, + 'phpdoc_add_missing_param_annotation' => [ + 'only_untyped' => false, + ], + 'phpdoc_order' => true, + 'psr0' => false, + 'psr4' => false, + 'semicolon_after_instruction' => true, + 'silenced_deprecation_error' => false, + 'simplified_null_return' => false, + 'strict_comparison' => true, + 'strict_param' => true, + ]; + + protected $targetPhpVersion = 70200; +} diff --git a/test/Unit/RuleSet/AbstractRuleSetTestCase.php b/test/Unit/RuleSet/AbstractRuleSetTestCase.php index 4743f24..8f420c1 100644 --- a/test/Unit/RuleSet/AbstractRuleSetTestCase.php +++ b/test/Unit/RuleSet/AbstractRuleSetTestCase.php @@ -203,9 +203,7 @@ final protected function checkPhpCsFixerVersion() return; } - throw new \PHPUnit_Framework_SkippedTestError(sprintf( - 'This test cannot be executed because current PHP-CS-FIXER version "%s" did not match current "%s" expected cs-fixer.', - Application::VERSION, $this->className())); + throw new \PHPUnit_Framework_SkippedTestError(sprintf('This test cannot be executed because current PHP-CS-FIXER version "%s" did not match current "%s" expected cs-fixer.', Application::VERSION, $this->className())); } /** diff --git a/test/Unit/RuleSet/Php72Test.php b/test/Unit/RuleSet/Php72Test.php new file mode 100644 index 0000000..9738e2d --- /dev/null +++ b/test/Unit/RuleSet/Php72Test.php @@ -0,0 +1,100 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Coffreo\PhpCsFixer\Config\Test\Unit\RuleSet; + +use Coffreo\PhpCsFixer\Config\RuleSet\Php72; + +final class Php72Test extends AbstractRuleSetTestCase +{ + protected function className() + { + return Php72::class; + } + + protected function name() + { + return 'Coffreo (PHP 7.2)'; + } + + protected function targetPhpCsFixer() + { + return '2.3.'; + } + + protected function rules() + { + return [ + '@Symfony' => true, + '@PHP71Migration' => true, + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'class_keyword_remove' => false, + 'combine_consecutive_unsets' => true, + 'declare_strict_types' => true, + 'dir_constant' => false, + 'doctrine_annotation_braces' => [ + 'syntax' => 'without_braces', + ], + 'doctrine_annotation_indentation' => true, + 'doctrine_annotation_spaces' => true, + 'ereg_to_preg' => true, + 'function_to_constant' => true, + 'general_phpdoc_annotation_remove' => false, + 'header_comment' => false, + 'heredoc_to_nowdoc' => true, + 'is_null' => [ + 'use_yoda_style' => true, + ], + 'linebreak_after_opening_tag' => true, + 'list_syntax' => [ + 'syntax' => 'short', + ], + 'mb_str_functions' => true, + 'modernize_types_casting' => true, + 'native_function_invocation' => true, + 'no_alias_functions' => true, + 'no_blank_lines_before_namespace' => false, + 'no_multiline_whitespace_before_semicolons' => true, + 'no_php4_constructor' => false, + 'no_short_echo_tag' => true, + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'non_printable_character' => true, + 'not_operator_with_space' => false, + 'not_operator_with_successor_space' => false, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_construct' => true, + 'php_unit_dedicate_assert' => true, + 'php_unit_strict' => false, + 'php_unit_test_class_requires_covers' => false, + 'phpdoc_add_missing_param_annotation' => [ + 'only_untyped' => false, + ], + 'phpdoc_order' => true, + 'psr0' => false, + 'psr4' => false, + 'semicolon_after_instruction' => true, + 'silenced_deprecation_error' => false, + 'simplified_null_return' => false, + 'strict_comparison' => true, + 'strict_param' => true, + ]; + } + + protected function targetPhpVersion() + { + return 70200; + } +}