From 4329252709b276b0d16140dda95e7c42b67e3843 Mon Sep 17 00:00:00 2001 From: Marcel Voigt Date: Sun, 9 Aug 2015 18:31:53 +0200 Subject: [PATCH] Suggest php-cs-fixer and add default config See .php_cs for default configuration. Install php-cs-fixer globally and run php-cs-fixer fix to fix common coding standards or style issues. --- .php_cs | 29 +++++++++++++++++++ CONTRIBUTING.md | 15 ++++++++++ composer.json | 3 +- library/Rules/Tld.php | 2 +- .../AbstractNestedExceptionTest.php | 2 -- tests/Exceptions/ValidationExceptionTest.php | 8 ++--- 6 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 .php_cs diff --git a/.php_cs b/.php_cs new file mode 100644 index 00000000..8180228f --- /dev/null +++ b/.php_cs @@ -0,0 +1,29 @@ +files() + ->name('*.php') + ->name('*.phpt') + ->in('library') + ->in('tests'); + +return Symfony\CS\Config\Config::create() + ->level(\Symfony\CS\FixerInterface::PSR2_LEVEL) + ->fixers(array( + // All items of the @param, @throws, @return, @var, and @type phpdoc + // tags must be aligned vertically. + 'phpdoc_params', + // Convert double quotes to single quotes for simple strings. + 'single_quote', + // Group and seperate @phpdocs with empty lines. + 'phpdoc_separation', + // An empty line feed should precede a return statement. + 'return', + // Remove trailing whitespace at the end of blank lines. + 'whitespacy_lines', + // Removes extra empty lines. + 'extra_empty_lines', + // Unused use statements must be removed. + 'unused_use' + )) + ->finder($finder); diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 279ea305..6ddce9f0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -140,6 +140,21 @@ No test should fail. You can tweak the PHPUnit's settings by copying `phpunit.xml.dist` to `phpunit.xml` and changing it according to your needs. +## Coding style and standards + +We follow the [PSR-2](http://www.php-fig.org/psr/psr-2/) coding style and +[PSR-4](http://www.php-fig.org/psr/psr-4/) autoloading standard. + +There are some preferences regarding code style which you can easily adhere to +by using [php-cs-fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer). + +This will format all PHP files consistently using the preferences of this +project. + +```sh +$ vendor/bin/php-cs-fixer fix +``` + *** See also: diff --git a/composer.json b/composer.json index 40d9c10c..7a4b4f45 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "egulias/email-validator": "Strict (RFC compliant) email validation", "malkusch/bav": "German bank account validation", "symfony/validator": "Use Symfony validator through Respect\\Validation", - "zendframework/zend-validator": "Use Zend Framework validator through Respect\\Validation" + "zendframework/zend-validator": "Use Zend Framework validator through Respect\\Validation", + "fabpot/php-cs-fixer": "Fix PSR2 and other coding style issues" }, "autoload": { "psr-4": { diff --git a/library/Rules/Tld.php b/library/Rules/Tld.php index cf247723..bac35e58 100644 --- a/library/Rules/Tld.php +++ b/library/Rules/Tld.php @@ -92,7 +92,7 @@ class Tld extends AbstractRule 'uol', 'vacations', 'vegas', 'ventures', 'versicherung', 'vet', 'viajes', 'video', 'villas', 'vision', 'vista', 'vistaprint', 'vlaanderen', 'vodka', 'vote', 'voting', 'voto', 'voyage', 'wales', 'walter', 'wang', 'watch', 'webcam', 'website', 'wed', - 'wedding', 'weir', 'whoswho', 'wien', 'wiki', 'williamhill', 'win', 'windows', + 'wedding', 'weir', 'whoswho', 'wien', 'wiki', 'williamhill', 'win', 'windows', 'wme', 'work', 'works', 'world', 'wtc', 'wtf', 'xbox', 'xerox', 'xin', 'xyz', 'yachts', 'yandex', 'yodobashi', 'yoga', 'yokohama', 'youtube', 'zip', 'zone', 'zuerich', //country diff --git a/tests/Exceptions/AbstractNestedExceptionTest.php b/tests/Exceptions/AbstractNestedExceptionTest.php index ecd14178..6df279bc 100644 --- a/tests/Exceptions/AbstractNestedExceptionTest.php +++ b/tests/Exceptions/AbstractNestedExceptionTest.php @@ -11,8 +11,6 @@ namespace Respect\Validation\Exceptions; -use Respect\Validation\Validator as v; - /** * phpunit has an issue with mocking exceptions when in HHVM: * https://github.com/sebastianbergmann/phpunit-mock-objects/issues/207 diff --git a/tests/Exceptions/ValidationExceptionTest.php b/tests/Exceptions/ValidationExceptionTest.php index 01f1ea5b..7c84c9cf 100644 --- a/tests/Exceptions/ValidationExceptionTest.php +++ b/tests/Exceptions/ValidationExceptionTest.php @@ -97,12 +97,12 @@ class ValidationExceptionTest extends \PHPUnit_Framework_TestCase array(array(), ''), array(array(array(), 'foo'), "(), 'foo'"), array(array(array(1), 'foo'), "(1), 'foo'"), - array(array(1, array(2, array(3))), "1, (2, (3))"), - array(array(1, array(2, array(3, array(4)))), "1, (2, (3, (4)))"), - array(array(1, array(2, array(3, array(4, array(5))))), "1, (2, (3, (4, ...)))"), + array(array(1, array(2, array(3))), '1, (2, (3))'), + array(array(1, array(2, array(3, array(4)))), '1, (2, (3, (4)))'), + array(array(1, array(2, array(3, array(4, array(5))))), '1, (2, (3, (4, ...)))'), array(array('foo', 'bar'), "'foo', 'bar'"), array(array('foo', -1), "'foo', -1"), - array(array(new \stdClass, "foo"), "Object of class stdClass, 'foo'"), + array(array(new \stdClass, 'foo'), "Object of class stdClass, 'foo'"), array(new \stdClass, 'Object of class stdClass'), array($x = new \DateTime, $x->format('Y-m-d H:i:s')), );