Browse Source

Merge branch '1.12'

Conflicts:
	Symfony/CS/Finder/DefaultFinder.php
	Symfony/CS/Tests/Fixtures/Integration/PHP7.test
	Symfony/CS/Tests/Fixtures/Integration/misc/PHP7.test
	tests/Fixtures/Integration/misc/PHP7.test
Dariusz Ruminski 8 years ago
parent
commit
59a1a65b33

+ 4 - 4
src/Fixer/ControlStructure/IncludeFixer.php

@@ -50,7 +50,7 @@ final class IncludeFixer extends AbstractFixer
     private function clearIncludies(Tokens $tokens, array $includies)
     {
         foreach (array_reverse($includies) as $includy) {
-            if ($includy['end']) {
+            if ($includy['end'] && !$tokens[$includy['end']]->isGivenKind(T_CLOSE_TAG)) {
                 $tokens->removeLeadingWhitespace($includy['end']);
             }
 
@@ -59,7 +59,7 @@ final class IncludeFixer extends AbstractFixer
             if ($braces) {
                 $nextToken = $tokens[$tokens->getNextMeaningfulToken($braces['close'])];
 
-                if ($nextToken->equals(';')) {
+                if ($nextToken->equalsAny(array(';', array(T_CLOSE_TAG)))) {
                     $tokens->removeLeadingWhitespace($braces['open']);
                     $tokens->removeTrailingWhitespace($braces['open']);
                     $tokens->removeLeadingWhitespace($braces['close']);
@@ -96,7 +96,7 @@ final class IncludeFixer extends AbstractFixer
                 $includy = array(
                     'begin' => $index,
                     'braces' => null,
-                    'end' => $tokens->getNextTokenOfKind($index, array(';')),
+                    'end' => $tokens->getNextTokenOfKind($index, array(';', array(T_CLOSE_TAG))),
                 );
 
                 $nextTokenIndex = $tokens->getNextMeaningfulToken($index);
@@ -107,7 +107,7 @@ final class IncludeFixer extends AbstractFixer
                     // Include is also legal as function parameter or condition statement but requires being wrapped then.
                     $braceCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextTokenIndex);
 
-                    if ($tokens[$tokens->getNextMeaningfulToken($braceCloseIndex)]->equals(';')) {
+                    if ($tokens[$tokens->getNextMeaningfulToken($braceCloseIndex)]->equalsAny(array(';', array(T_CLOSE_TAG)))) {
                         $includy['braces'] = array(
                             'open' => $nextTokenIndex,
                             'close' => $braceCloseIndex,

+ 6 - 1
src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php

@@ -49,7 +49,12 @@ final class PhpdocAnnotationWithoutDotFixer extends AbstractFixer
             foreach ($annotations as $annotation) {
                 if ($annotation->getTag()->valid()) {
                     $line = $doc->getLine($annotation->getEnd());
-                    $line->setContent(preg_replace('/[.。](\s+)$/u', '\1', $line->getContent()));
+
+                    $content = preg_replace('/(?<![.。])[.。](\s+)$/u', '\1', $line->getContent());
+
+                    if (null !== $content) {
+                        $line->setContent($content);
+                    }
                 }
             }
             $token->setContent($doc->getContent());

+ 1 - 0
src/Test/IntegrationCaseFactory.php

@@ -98,6 +98,7 @@ final class IntegrationCaseFactory
 
         foreach ($lines as $line) {
             $labelValuePair = explode('=', $line);
+
             if (2 !== count($labelValuePair)) {
                 throw new \InvalidArgumentException(sprintf('Invalid REQUIREMENTS line: "%d".', $line));
             }

+ 9 - 4
tests/Fixer/ControlStructure/IncludeFixerTest.php

@@ -35,13 +35,13 @@ final class IncludeFixerTest extends AbstractFixerTestCase
         $template = '<?php %s';
         $tests = array();
         foreach (array('require', 'require_once', 'include', 'include_once') as $statement) {
-            $test[] = array(
-                sprintf($template.' "foo.php" ?>', $statement),
+            $tests[] = array(
+                sprintf($template.' "foo.php"?>', $statement),
                 sprintf($template.' ("foo.php") ?>', $statement),
             );
 
-            $test[] = array(
-                sprintf($template.' /**/ "foo.php" // test
+            $tests[] = array(
+                sprintf($template.' /**/ "foo.php"// test
                     ?>', $statement),
                 sprintf($template.' /**/ ("foo.php") // test
                     ?>', $statement),
@@ -57,6 +57,11 @@ final class IncludeFixerTest extends AbstractFixerTestCase
                 sprintf($template.'            $a;', $statement),
             );
 
+            $tests[] = array(
+                sprintf($template.' $a; ', $statement),
+                sprintf($template.'            $a   ; ', $statement),
+            );
+
             $tests[] = array(
                 sprintf($template." /**/'foo.php';", $statement),
                 sprintf($template."/**/'foo.php';", $statement),

+ 22 - 8
tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php

@@ -39,10 +39,13 @@ final class PhpdocAnnotationWithoutDotFixerTest extends AbstractFixerTestCase
      *
      * Description.
      *
-     * @param string $str   Some string
-     * @param bool   $isStr Is it a string?
-     * @param int    $int   Some multiline
-     *                      description. With many dots
+     * @param string $str        Some string
+     * @param string $ellipsis1  Ellipsis is this: ...
+     * @param string $ellipsis2  Ellipsis is this: 。。。
+     * @param string $ellipsis3  Ellipsis is this: …
+     * @param bool   $isStr      Is it a string?
+     * @param int    $int        Some multiline
+     *                           description. With many dots
      *
      * @return array Result array
      *
@@ -54,14 +57,25 @@ final class PhpdocAnnotationWithoutDotFixerTest extends AbstractFixerTestCase
      *
      * Description.
      *
-     * @param string $str   Some string.
-     * @param bool   $isStr Is it a string?
-     * @param int    $int   Some multiline
-     *                      description. With many dots.
+     * @param string $str        Some string.
+     * @param string $ellipsis1  Ellipsis is this: ...
+     * @param string $ellipsis2  Ellipsis is this: 。。。
+     * @param string $ellipsis3  Ellipsis is this: …
+     * @param bool   $isStr      Is it a string?
+     * @param int    $int        Some multiline
+     *                           description. With many dots.
      *
      * @return array Result array。
      *
      * @SomeCustomAnnotation This is important sentence that must not be modified.
+     */',
+            ),
+            array(
+                // invalid char inside line won't crash the fixer
+                '<?php
+    /**
+     * @var string This: '.chr(174).' is an odd character.
+     * @var string This: '.chr(174).' is an odd character 2nd time。
      */',
             ),
         );

+ 0 - 2
tests/Fixtures/Integration/priority/declare_strict_types,no_blank_lines_before_namespace.test

@@ -7,7 +7,6 @@ php=7.0
 --EXPECT--
 <?php declare(strict_types=1);
 declare(ticks=1);
-declare(encoding='ISO-8859-1');
 namespace A\B\C;
 class A {
 }
@@ -15,7 +14,6 @@ class A {
 --INPUT--
 <?php
 declare(ticks=1);
-declare(encoding='ISO-8859-1');
 declare(strict_types=1);
 
 namespace A\B\C;

+ 0 - 2
tests/Fixtures/Integration/priority/declare_strict_types,no_extra_consecutive_blank_lines.test

@@ -7,7 +7,6 @@ php=7.0
 --EXPECT--
 <?php declare(strict_types=1);
 declare(ticks=1);
-declare(encoding='ISO-8859-1');
 
 namespace A\B\C;
 class A {
@@ -16,7 +15,6 @@ class A {
 --INPUT--
 <?php
 declare(ticks=1);
-declare(encoding='ISO-8859-1');
 declare(strict_types=1);
 
 namespace A\B\C;

+ 0 - 2
tests/Fixtures/Integration/priority/declare_strict_types,no_whitespace_in_blank_line.test

@@ -7,7 +7,6 @@ php=7.0
 --EXPECT--
 <?php declare(strict_types=1);
 declare(ticks=1);
-declare(encoding='ISO-8859-1');
 
 
 namespace A\B\C;
@@ -17,7 +16,6 @@ class A {
 --INPUT--
 <?php
 declare(ticks=1);
-declare(encoding='ISO-8859-1');
      declare(strict_types=1);
 
 namespace A\B\C;

+ 0 - 2
tests/Fixtures/Integration/priority/declare_strict_types,single_blank_line_before_namespace.test

@@ -7,7 +7,6 @@ php=7.0
 --EXPECT--
 <?php declare(strict_types=1);
 declare(ticks=1);
-declare(encoding='ISO-8859-1');
 
 namespace A\B\C;
 class A {
@@ -16,7 +15,6 @@ class A {
 --INPUT--
 <?php
 declare(ticks=1);
-declare(encoding='ISO-8859-1');
 declare(strict_types=1);
 
 namespace A\B\C;