Skip to content

Commit

Permalink
Add Rule for PHP 7.2 (#6)
Browse files Browse the repository at this point in the history
* feat(ruleSet): add RuleSet for Php 7.2
* ci(travis): add php 7.0 / 7.1 / 7.2 in `travis.yml`
* ci(travis): add conflict package that fails with php7.2
* cs: apply coding standard
  • Loading branch information
dardinier authored and emri99 committed Nov 6, 2019
1 parent 5aa78c7 commit 27c5b03
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
composer.lock
npm-debug.log
/test/coverage/
/vendor/
/vendor/
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: php
php:
- "5.6"
# - "7.2"
- "7.0"
- "7.1"
- "7.2"
env:
- TRAVIS_CI=true
install:
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"require-dev": {
"phpunit/phpunit": "^5.7.5"
},
"conflict": {
"sebastian/comparator": "1.2.2"
},
"autoload": {
"psr-4": {
"Coffreo\\PhpCsFixer\\Config\\": "src"
Expand Down
8 changes: 1 addition & 7 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@
final class Factory
{
/**
* @param RuleSet $ruleSet
*
* @throws \RuntimeException
*
* @return Config
*/
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());
Expand Down
10 changes: 2 additions & 8 deletions src/RuleSet/AbstractRuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = [
Expand Down
79 changes: 79 additions & 0 deletions src/RuleSet/Php72.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/**
* This file is part of Coffreo project "coffreo/php-cs-fixer-config"
*
* (c) Coffreo SAS <[email protected]>
*
* 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;
}
4 changes: 1 addition & 3 deletions test/Unit/RuleSet/AbstractRuleSetTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

/**
Expand Down
100 changes: 100 additions & 0 deletions test/Unit/RuleSet/Php72Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

/**
* This file is part of Coffreo project "coffreo/php-cs-fixer-config"
*
* (c) Coffreo SAS <[email protected]>
*
* 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;
}
}

0 comments on commit 27c5b03

Please sign in to comment.