diff --git a/.gitattributes b/.gitattributes
index bb847623..30182964 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,6 +1,5 @@
-/Tests export-ignore
+/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
-phpunit.xml.dist export-ignore
-tests_bootstrap.php export-ignore
+phpcs.xml.dist export-ignore
diff --git a/.gitignore b/.gitignore
index 2042d62e..2a76e0ea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
vendor/
-*.phpunit.xml
+phpcs.xml
composer.lock
+tests/input2
+phpcs.log
diff --git a/.travis.yml b/.travis.yml
index d3b92e36..100afc59 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,23 +1,32 @@
+dist: trusty
+sudo: false
language: php
-sudo: false
+php:
+ - 7.1
+ - 7.2
+ - nightly
+
+cache:
+ directories:
+ - $HOME/.composer/cache
before_install:
- - composer self-update
+ - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
+ - composer self-update
+
+install: travis_retry composer update --prefer-dist
-install:
- - composer install --prefer-source
+script:
+ - vendor/bin/phpcs
+ - vendor/bin/phpcs tests/input --report=summary --report-file=phpcs.log; diff tests/expected_report.txt phpcs.log
-matrix:
- include:
- - php: 5.3
- - php: 5.4
- - php: 5.5
- - php: 5.6
- - php: nightly
- - php: hhvm
- allow_failures:
- - php: nightly
- - php: hhvm
+jobs:
+ allow_failures:
+ - php: nightly
-script: ./vendor/bin/phpunit
+ include:
+ - stage: Apply fixes
+ before_script:
+ - cp -R tests/input/ tests/input2/
+ script: vendor/bin/phpcbf tests/input2; diff tests/input2 tests/fixed
diff --git a/Docs/README.md b/Docs/README.md
deleted file mode 100644
index 5b652002..00000000
--- a/Docs/README.md
+++ /dev/null
@@ -1,38 +0,0 @@
-Doctrine Coding Standard
-========================
-
-The Doctrine project follows a coding standard based on
-[PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) with custom
-additions and modifications.
-When contributing to the Doctrine project, the following rules have to be met in order to fulfill this standard.
-
-Formatting
-----------
-
-- Corresponding assignment statement tokens MUST be aligned. Assignment tokens are:
- `=`, `&=`, `.=`, `/=`, `-=`, `%=`, `*=`, `+=`, `^=`.
- Each `=` token MUST be on the same column as the one from the previous corresponding statement.
-
-```php
-$foo = 'Foo';
-$fooBar = 'FooBar';
-$fooBarBaz = 'FooBarBaz';
-$foo .= $bar;
-
-$foo = 'Foo';
-
-$object->foo($foo);
-
-$fooBar = 'FooBar';
-
-$object->fooBar($fooBar);
-
-$fooBarBaz = 'FoobarBaz';
-
-$object->fooBarBaz($fooBarBaz);
-```
-
-Strings
--------
-
-- The string concatenation token `.` MUST be surrounded by spaces.
diff --git a/Docs/Strings/ConcatenationSpacingSniff.xml b/Docs/Strings/ConcatenationSpacingSniff.xml
deleted file mode 100644
index d6065243..00000000
--- a/Docs/Strings/ConcatenationSpacingSniff.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
- . 'World!';
-]]>
-
-
- '. 'World!';
-]]>
-
-
- .'World!';
-]]>
-
-
- '.'World!';
-]]>
-
-
-
diff --git a/README.md b/README.md
index 72841d50..801117cf 100644
--- a/README.md
+++ b/README.md
@@ -9,108 +9,55 @@ The [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) Coding Stand
Installation
------------
-You have three possibilities to use the Doctrine Coding Standard with PHP_CodeSniffer in a particular project.
+You have two possibilities to use the Doctrine Coding Standard with PHP_CodeSniffer in a particular project.
-### 1. Standalone installation
+### 1. As a composer dependency of your project
-You can install the Doctrine Coding Standard as a plugin into your global system PHP_CodeSniffer installation:
-
-```bash
-$ cd /path/to/phpcs/CodeSniffer/Standards
-$ php composer create-project doctrine/coding-standard Doctrine ~0.1@dev
-```
-
-Then you can use it like
-(assuming that you have the `phpcs` binary in your search path):
-
-```bash
-$ phpcs --standard=Doctrine /path/to/some/file/to/sniff.php
-```
-
-Or even set it as default standard
-(assuming that you have the `phpcs` binary in your search path):
-
-```bash
-$ phpcs --config-set default_standard Doctrine
-```
-
-And just sniff a particular file with
-(assuming that you have the `phpcs` binary in your search path):
-
-```bash
-$ phpcs /path/to/some/file/to/sniff.php
-```
-
-### 2. Global installation
-
-You also can install the Doctrine Coding Standard globally:
+You can install the Doctrine Coding Standard as a composer dependency to your particular project.
+Just add the following block to your project's `composer.json` file:
```bash
-$ php composer global require doctrine/coding-standard:~0.1@dev
+$ php composer require doctrine/coding-standard:~0.1@dev
```
Then you can use it like:
```bash
-$ phpcs --standard=~/.composer/vendor/doctrine/coding-standard/Doctrine /path/to/some/file/to/sniff.php
-```
-
-Or even set it as default standard:
-
-```bash
-$ phpcs --config-set default_standard ~/.composer/vendor/doctrine/coding-standard/Doctrine
+$ ./vendor/bin/phpcs --standard=Doctrine /path/to/some/file/to/sniff.php
```
-And just sniff a particular file with:
+You might also do automatic fixes using `phpcbf`:
```bash
-$ phpcs /path/to/some/file/to/sniff.php
+$ ./vendor/bin/phpcbf --standard=Doctrine /path/to/some/file/to/sniff.php
```
-### 3. Custom installation
+### 2. Global installation
-You can install the Doctrine Coding Standard anywhere you want:
+You can also install the Doctrine Coding Standard globally:
```bash
-$ php composer create-project doctrine/coding-standard /path/to/coding-standard/Doctrine ~0.1@dev
+$ composer global require doctrine/coding-standard:~0.1@dev
```
Then you can use it like:
```bash
-$ ./vendor/bin/phpcs --standard=. /path/to/some/file/to/sniff.php
-```
-
-### 4. As a composer dependency of your project
-
-You can install the Doctrine Coding Standard as a composer dependency to your particular project.
-Just add the following block to your project's `composer.json` file:
-
-```bash
-$ php composer require doctrine/coding-standard:~0.1@dev
+$ phpcs --standard=Doctrine /path/to/some/file/to/sniff.php
```
-Then you can use it like:
+You might also do automatic fixes using `phpcbf`:
```bash
-$ ./vendor/bin/phpcs --standard=vendor/doctrine/coding-standard/Doctrine /path/to/some/file/to/sniff.php
+$ phpcbf --standard=Doctrine /path/to/some/file/to/sniff.php
```
Testing
-------
-If you are contributing to the Doctrine Coding Standard and want to test your contribution, you have to
-make sure all dependencies are correctly installed:
-
-```bash
-$ php composer install --prefer-source
-```
-
-The option `--prefer-source` is particularly necessary to ensure the test suite from PHP_CodeSniffer is
-installed. Otherwise the test suite for the Doctrine Coding Standard won't work!
-
-Run the test suite with:
+If you are contributing to the Doctrine Coding Standard and want to test your contribution, you just
+need to execute PHPCS with the tests folder and ensure it matches the expected report:
```bash
-$ ./vendor/bin/phpunit
+$ ./vendor/bin/phpcs tests/input --report=summary --report-file=phpcs.log; diff tests/expected_report.txt phpcs.log
```
diff --git a/composer.json b/composer.json
index e1f3dd5d..8ff1eeaa 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
"name": "doctrine/coding-standard",
- "type": "library",
+ "type": "phpcodesniffer-standard",
"description": "Doctrine Coding Standard",
"keywords": ["doctrine", "coding", "standard", "cs", "code", "style", "sniffer"],
"homepage": "http://www.doctrine-project.org",
@@ -9,14 +9,16 @@
{"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"},
{"name": "Steve Müller", "email": "st.mueller@dzh-online.de"}
],
- "require": {
- "php": ">=5.3",
- "squizlabs/php_codesniffer": "~1.0"
+ "autoload": {
+ "psr-4": {
+ "Doctrine\\Sniffs\\": "lib/Doctrine/Sniffs"
+ }
},
- "require-dev": {
- "phpunit/phpunit": "~4.7"
+ "require": {
+ "php": "^7.1",
+ "squizlabs/php_codesniffer": "~3.0",
+ "dealerdirect/phpcodesniffer-composer-installer": "^0.4.2"
},
- "target-dir": "Doctrine",
"extra": {
"branch-alias": {
"dev-master": "0.1-dev"
diff --git a/lib/Doctrine/Sniffs/Spacing/ControlStructureSniff.php b/lib/Doctrine/Sniffs/Spacing/ControlStructureSniff.php
new file mode 100644
index 00000000..6ecb2014
--- /dev/null
+++ b/lib/Doctrine/Sniffs/Spacing/ControlStructureSniff.php
@@ -0,0 +1,134 @@
+.
+*/
+
+declare(strict_types=1);
+
+namespace Doctrine\Sniffs\Spacing;
+
+use PHP_CodeSniffer\Files\File;
+use PHP_CodeSniffer\Sniffs\Sniff;
+
+/**
+ * Small modification on PSR2 sniff to allow a space before the NOT operator
+ *
+ * @see \PHP_CodeSniffer\Standards\PSR2\Sniffs\ControlStructures\ControlStructureSpacingSniff
+ */
+final class ControlStructureSniff implements Sniff
+{
+ private const OPENER_NAME = 'parenthesis_opener';
+ private const OPENER_MESSAGE = 'Expected no spaces after opening bracket; %s found';
+ private const CLOSER_NAME = 'parenthesis_closer';
+ private const CLOSER_MESSAGE = 'Expected no spaces before closing bracket; %s found';
+
+ /**
+ * Returns an array of tokens this test wants to listen for.
+ *
+ * @return array
+ */
+ public function register()
+ {
+ return [
+ \T_IF,
+ \T_WHILE,
+ \T_FOREACH,
+ \T_FOR,
+ \T_SWITCH,
+ \T_DO,
+ \T_ELSE,
+ \T_ELSEIF,
+ \T_TRY,
+ \T_CATCH,
+ ];
+ }
+
+ public function process(File $phpcsFile, $stackPtr)
+ {
+ $tokens = $phpcsFile->getTokens();
+
+ if ( ! isset($tokens[$stackPtr][self::OPENER_NAME], $tokens[$stackPtr][self::CLOSER_NAME])) {
+ return;
+ }
+
+ $openerPosition = $tokens[$stackPtr][self::OPENER_NAME];
+ $closerPosition = $tokens[$stackPtr][self::CLOSER_NAME];
+
+ $this->validateParenthesisOpener($phpcsFile, $tokens, $stackPtr, $openerPosition);
+ $this->validateParenthesisCloser($phpcsFile, $tokens, $stackPtr, $openerPosition, $closerPosition);
+ }
+
+ private function validateParenthesisOpener(File $file, array $tokens, int $position, int $openerPosition) : void
+ {
+ $nextTokenPosition = $openerPosition + 1;
+ $nextToken = $tokens[$nextTokenPosition];
+
+ if ($nextToken['code'] !== T_WHITESPACE || $tokens[$nextTokenPosition + 1]['code'] === T_BOOLEAN_NOT) {
+ return;
+ }
+
+ $spaces = $nextToken['length'];
+
+ if (\strpos($nextToken['content'], $file->eolChar) !== false) {
+ $spaces = 'newline';
+ }
+
+ $file->recordMetric($position, 'Spaces after control structure open parenthesis', $spaces);
+
+ if ($spaces === 0) {
+ return;
+ }
+
+ if ( ! $file->addFixableError(self::OPENER_MESSAGE, $nextTokenPosition, 'AfterOpenBrace', [$spaces])) {
+ return;
+ }
+
+ $file->fixer->replaceToken($nextTokenPosition, '');
+ }
+
+ private function validateParenthesisCloser(
+ File $file,
+ array $tokens,
+ int $position,
+ int $openerPosition,
+ int $closerPosition
+ ) : void {
+ if ($tokens[$openerPosition]['line'] !== $tokens[$closerPosition]['line']) {
+ return;
+ }
+
+ $previousTokenPosition = $closerPosition - 1;
+ $previousToken = $tokens[$previousTokenPosition];
+ $spaces = 0;
+
+ if ($previousToken['code'] === T_WHITESPACE) {
+ $spaces = $previousToken['length'];
+ }
+
+ $file->recordMetric($position, 'Spaces before control structure close parenthesis', $spaces);
+
+ if ($spaces === 0) {
+ return;
+ }
+
+ if ( ! $file->addFixableError(self::CLOSER_MESSAGE, $previousTokenPosition, 'BeforeCloseBrace', [$spaces])) {
+ return;
+ }
+
+ $file->fixer->replaceToken($previousTokenPosition, '');
+ }
+}
diff --git a/lib/Doctrine/Sniffs/Spacing/EnsureSpaces.php b/lib/Doctrine/Sniffs/Spacing/EnsureSpaces.php
new file mode 100644
index 00000000..2804121a
--- /dev/null
+++ b/lib/Doctrine/Sniffs/Spacing/EnsureSpaces.php
@@ -0,0 +1,74 @@
+.
+*/
+
+declare(strict_types=1);
+
+namespace Doctrine\Sniffs\Spacing;
+
+use PHP_CodeSniffer\Files\File;
+
+trait EnsureSpaces
+{
+ protected function ensureSpaceBefore(File $file, array $tokens, int $position, string $message) : void
+ {
+ $spacing = $this->numberOfSpaces($tokens, $position - 1);
+
+ if ($spacing === 1) {
+ return;
+ }
+
+ if ( ! $file->addFixableError($message, $position, 'before', ['before', $spacing])) {
+ return;
+ }
+
+ if ($spacing === 0) {
+ $file->fixer->addContentBefore($position, ' ');
+ return;
+ }
+
+ $file->fixer->replaceToken($position - 1, ' ');
+ }
+
+ protected function ensureSpaceAfter(File $file, array $tokens, int $position, string $message) : void
+ {
+ $spacing = $this->numberOfSpaces($tokens, $position + 1);
+
+ if ($spacing === 1) {
+ return;
+ }
+
+ if ( ! $file->addFixableError($message, $position, 'after', ['after', $spacing])) {
+ return;
+ }
+
+ if ($spacing === 0) {
+ $file->fixer->addContent($position, ' ');
+ return;
+ }
+
+ $file->fixer->replaceToken($position + 1, ' ');
+ }
+
+ private function numberOfSpaces(array $tokens, int $position) : int
+ {
+ $token = $tokens[$position];
+
+ return $token['code'] === T_WHITESPACE ? $token['length'] : 0;
+ }
+}
diff --git a/Tests/Strings/ConcatenationSpacingUnitTest.php b/lib/Doctrine/Sniffs/Spacing/SpaceOnNotSniff.php
similarity index 62%
rename from Tests/Strings/ConcatenationSpacingUnitTest.php
rename to lib/Doctrine/Sniffs/Spacing/SpaceOnNotSniff.php
index 99d7591a..d3a33b7d 100644
--- a/Tests/Strings/ConcatenationSpacingUnitTest.php
+++ b/lib/Doctrine/Sniffs/Spacing/SpaceOnNotSniff.php
@@ -17,37 +17,29 @@
* .
*/
-class Doctrine_Tests_Strings_ConcatenationSpacingUnitTest extends AbstractSniffUnitTest
+declare(strict_types=1);
+
+namespace Doctrine\Sniffs\Spacing;
+
+use PHP_CodeSniffer\Sniffs\Sniff;
+use PHP_CodeSniffer\Files\File;
+
+final class SpaceOnNotSniff implements Sniff
{
- /**
- * {@inheritdoc}
- */
- public function getErrorList()
+ use EnsureSpaces;
+
+ private const MESSAGE = 'There must be a single space %s a NOT operator; %d found';
+
+ public function register()
{
- return array(
- 4 => 1,
- 5 => 1,
- 6 => 2,
- 11 => 1,
- 12 => 1,
- 13 => 2,
- 16 => 1,
- 17 => 1,
- 18 => 2,
- 21 => 1,
- 22 => 1,
- 23 => 2,
- 25 => 4,
- 31 => 1,
- 34 => 1,
- );
+ return [\T_BOOLEAN_NOT];
}
- /**
- * {@inheritdoc}
- */
- public function getWarningList()
+ public function process(File $phpcsFile, $stackPtr)
{
- return array();
+ $tokens = $phpcsFile->getTokens();
+
+ $this->ensureSpaceBefore($phpcsFile, $tokens, $stackPtr, self::MESSAGE);
+ $this->ensureSpaceAfter($phpcsFile, $tokens, $stackPtr, self::MESSAGE);
}
}
diff --git a/Sniffs/Strings/ConcatenationSpacingSniff.php b/lib/Doctrine/Sniffs/Spacing/SpaceOnReturnTypeSniff.php
similarity index 52%
rename from Sniffs/Strings/ConcatenationSpacingSniff.php
rename to lib/Doctrine/Sniffs/Spacing/SpaceOnReturnTypeSniff.php
index 9aa51808..ede41e25 100644
--- a/Sniffs/Strings/ConcatenationSpacingSniff.php
+++ b/lib/Doctrine/Sniffs/Spacing/SpaceOnReturnTypeSniff.php
@@ -17,34 +17,41 @@
* .
*/
-/**
- * Sniff that verifies that there are spaces around the string concatenation operator ".".
- *
- * @author Steve Müller
- */
-class Doctrine_Sniffs_Strings_ConcatenationSpacingSniff implements PHP_CodeSniffer_Sniff
+declare(strict_types=1);
+
+namespace Doctrine\Sniffs\Spacing;
+
+use PHP_CodeSniffer\Files\File;
+use PHP_CodeSniffer\Sniffs\Sniff;
+
+final class SpaceOnReturnTypeSniff implements Sniff
{
- /**
- * {@inheritdoc}
- */
+ use EnsureSpaces;
+
+ private const MESSAGE = 'There must be a single space %s the colon on return types; %d found';
+
public function register()
{
- return array(T_STRING_CONCAT);
+ return [\T_RETURN_TYPE];
+ }
+
+ public function process(File $phpcsFile, $stackPtr)
+ {
+ $tokens = $phpcsFile->getTokens();
+ $colonPosition = $this->findColonPosition($tokens, $stackPtr);
+
+ $this->ensureSpaceBefore($phpcsFile, $tokens, $colonPosition, self::MESSAGE);
+ $this->ensureSpaceAfter($phpcsFile, $tokens, $colonPosition, self::MESSAGE);
}
- /**
- * {@inheritdoc}
- */
- public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
+ private function findColonPosition(array $tokens, int $position) : int
{
- $tokens = $phpcsFile->getTokens();
+ $colonPosition = $position;
- if (T_WHITESPACE !== $tokens[$stackPtr - 1]['code']) {
- $phpcsFile->addError('Missing space before the string concatenation operator ".".', $stackPtr, 'Before');
- }
+ do {
+ --$colonPosition;
+ } while ($tokens[$colonPosition]['code'] !== T_COLON);
- if (T_WHITESPACE !== $tokens[$stackPtr + 1]['code']) {
- $phpcsFile->addError('Missing space after the string concatenation operator ".".', $stackPtr, 'After');
- }
+ return $colonPosition;
}
}
diff --git a/lib/Doctrine/ruleset.xml b/lib/Doctrine/ruleset.xml
new file mode 100644
index 00000000..9c17cde6
--- /dev/null
+++ b/lib/Doctrine/ruleset.xml
@@ -0,0 +1,33 @@
+
+
+ The Doctrine coding standard.
+
+
+
+
+
+
+
+
+
+ error
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
new file mode 100644
index 00000000..9c9331f3
--- /dev/null
+++ b/phpcs.xml.dist
@@ -0,0 +1,15 @@
+
+
+ Check the code of the sniffs in doctrine/coding-standards.
+
+
+
+
+
+
+
+
+
+
+ lib
+
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
deleted file mode 100644
index b33adf29..00000000
--- a/phpunit.xml.dist
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
- ./vendor/squizlabs/php_codesniffer/tests/Standards/AllSniffs.php
-
-
-
diff --git a/ruleset.xml b/ruleset.xml
deleted file mode 100644
index 7287d86f..00000000
--- a/ruleset.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
- The Doctrine coding standard.
-
-
-
-
-
-
- error
-
-
-
-
-
-
-
-
-
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
new file mode 100644
index 00000000..0b74045c
--- /dev/null
+++ b/tests/expected_report.txt
@@ -0,0 +1,16 @@
+
+PHP CODE SNIFFER REPORT SUMMARY
+----------------------------------------------------------------------
+FILE ERRORS WARNINGS
+----------------------------------------------------------------------
+tests/input/concatenation_spacing.php 19 0
+tests/input/not_spacing.php 7 0
+tests/input/return_type_on_closures.php 21 0
+tests/input/return_type_on_methods.php 16 0
+----------------------------------------------------------------------
+A TOTAL OF 63 ERRORS AND 0 WARNINGS WERE FOUND IN 4 FILES
+----------------------------------------------------------------------
+PHPCBF CAN FIX 63 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+----------------------------------------------------------------------
+
+
diff --git a/tests/fixed/concatenation_spacing.php b/tests/fixed/concatenation_spacing.php
new file mode 100644
index 00000000..0c71ed80
--- /dev/null
+++ b/tests/fixed/concatenation_spacing.php
@@ -0,0 +1,35 @@
+ 0) {
+ echo 1;
+} elseif ( ! $test === 0) {
+ echo 0;
+} else {
+ echo -1;
+}
+
+while ( ! true) {
+ echo 1;
+}
+
+do {
+ echo 1;
+} while ( ! true);
diff --git a/tests/fixed/return_type_on_closures.php b/tests/fixed/return_type_on_closures.php
new file mode 100644
index 00000000..9e531d39
--- /dev/null
+++ b/tests/fixed/return_type_on_closures.php
@@ -0,0 +1,61 @@
+ 0) {
+ echo 1;
+} elseif ( !$test === 0) {
+ echo 0;
+} else {
+ echo -1;
+}
+
+while ( ! true) {
+ echo 1;
+}
+
+do {
+ echo 1;
+} while ( ! true);
diff --git a/tests/input/return_type_on_closures.php b/tests/input/return_type_on_closures.php
new file mode 100644
index 00000000..2848baf2
--- /dev/null
+++ b/tests/input/return_type_on_closures.php
@@ -0,0 +1,66 @@
+.
-*/
-
-/**
- * Copies a directory recursively.
- *
- * @param string $source The source path to copy.
- * @param string $target The target path to copy to.
- */
-function copyDirectory($source, $target)
-{
- /** @var $iterator \RecursiveIteratorIterator|\RecursiveDirectoryIterator */
- $iterator = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
- RecursiveIteratorIterator::SELF_FIRST
- );
-
- foreach ($iterator as $file) {
- /** @var $file SplFileInfo */
- if ($file->isDir()) {
- mkdir($target . '/' . $iterator->getSubPathName());
- } else {
- copy($file, $target . '/' . $iterator->getSubPathName());
- }
- }
-}
-
-/**
- * Removes a directory recursively.
- *
- * @param string $directory The path to the directory to remove.
- */
-function removeDirectory($directory)
-{
- /** @var $iterator \RecursiveIteratorIterator|\RecursiveDirectoryIterator */
- $iterator = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS),
- RecursiveIteratorIterator::CHILD_FIRST
- );
-
- foreach ($iterator as $file) {
- /** @var $file SplFileInfo */
- if ($file->isDir()) {
- rmdir($file->getRealPath());
- } else {
- unlink($file->getRealPath());
- }
- }
-
- rmdir($directory);
-}
-
-$phpCodeSnifferDir = __DIR__ . '/vendor/squizlabs/php_codesniffer';
-
-if ( ! file_exists($phpCodeSnifferDir)) {
- throw new \RuntimeException(
- 'Could not find PHP_CodeSniffer dependency. ' .
- 'Did you maybe forget to run "php composer.phar install --prefer-source --dev"?'
- );
-}
-
-$sniffTestSuiteFile = $phpCodeSnifferDir . '/tests/Standards/AllSniffs.php';
-
-if ( ! file_exists($sniffTestSuiteFile)) {
- throw new \RuntimeException(
- 'Could not find PHP_CodeSniffer test suite. ' .
- 'Did you maybe forget to run composer installation with option "--prefer-source"?'
- );
-}
-
-require_once __DIR__ . '/vendor/autoload.php';
-
-$doctrineStandardDir = $phpCodeSnifferDir . '/CodeSniffer/Standards/Doctrine';
-
-if (file_exists($doctrineStandardDir)) {
- removeDirectory($doctrineStandardDir);
-}
-
-mkdir($doctrineStandardDir);
-mkdir($doctrineStandardDir . '/Sniffs');
-mkdir($doctrineStandardDir . '/Tests');
-copy(__DIR__ . '/ruleset.xml', $doctrineStandardDir . '/ruleset.xml');
-
-copyDirectory(__DIR__ . '/Sniffs', $doctrineStandardDir . '/Sniffs');
-copyDirectory(__DIR__ . '/Tests', $doctrineStandardDir . '/Tests');