Browse Source

Strict parameters

Dariusz Ruminski 8 years ago
parent
commit
2b38023436

+ 5 - 0
src/Fixer/Basic/Psr0Fixer.php

@@ -82,6 +82,11 @@ final class Psr0Fixer extends AbstractPsrAutoloadingFixer
 
             if (isset($this->configuration['dir'])) {
                 $dir = substr($dir, strlen(realpath($this->configuration['dir'])) + 1);
+
+                if (false === $dir) {
+                    $dir = '';
+                }
+
                 if (strlen($normNamespace) > strlen($dir)) {
                     if ('' !== $dir) {
                         $normNamespace = substr($normNamespace, -strlen($dir));

+ 4 - 2
src/Fixer/Import/NoUnusedImportsFixer.php

@@ -72,9 +72,11 @@ final class NoUnusedImportsFixer extends AbstractFixer
      */
     public function supports(\SplFileInfo $file)
     {
+        $path = $file->getPathName();
+
         // some fixtures are auto-generated by Symfony and may contain unused use statements
-        if (false !== strpos($file, DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR) &&
-            false === strpos($file, DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR)
+        if (false !== strpos($path, DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR) &&
+            false === strpos($path, DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR)
         ) {
             return false;
         }

+ 10 - 10
src/Report/JunitReporter.php

@@ -65,13 +65,13 @@ final class JunitReporter implements ReporterInterface
     {
         $testcase = $dom->createElement('testcase');
         $testcase->setAttribute('name', 'All OK');
-        $testcase->setAttribute('assertions', 1);
+        $testcase->setAttribute('assertions', '1');
 
         $testsuite->appendChild($testcase);
-        $testsuite->setAttribute('tests', 1);
-        $testsuite->setAttribute('assertions', 1);
-        $testsuite->setAttribute('failures', 0);
-        $testsuite->setAttribute('errors', 0);
+        $testsuite->setAttribute('tests', '1');
+        $testsuite->setAttribute('assertions', '1');
+        $testsuite->setAttribute('failures', '0');
+        $testsuite->setAttribute('errors', '0');
     }
 
     /**
@@ -93,10 +93,10 @@ final class JunitReporter implements ReporterInterface
             $assertionsCount += (int) $testcase->getAttribute('assertions');
         }
 
-        $testsuite->setAttribute('tests', count($reportSummary->getChanged()));
-        $testsuite->setAttribute('assertions', $assertionsCount);
-        $testsuite->setAttribute('failures', $assertionsCount);
-        $testsuite->setAttribute('errors', 0);
+        $testsuite->setAttribute('tests', (string) count($reportSummary->getChanged()));
+        $testsuite->setAttribute('assertions', (string) $assertionsCount);
+        $testsuite->setAttribute('failures', (string) $assertionsCount);
+        $testsuite->setAttribute('errors', '0');
     }
 
     /**
@@ -116,7 +116,7 @@ final class JunitReporter implements ReporterInterface
         $testcase = $dom->createElement('testcase');
         $testcase->setAttribute('name', $testName);
         $testcase->setAttribute('file', $file);
-        $testcase->setAttribute('assertions', $appliedFixersCount);
+        $testcase->setAttribute('assertions', (string) $appliedFixersCount);
 
         $failure = $dom->createElement('failure');
         $failure->setAttribute('type', 'code_style');

+ 3 - 3
src/Report/XmlReporter.php

@@ -45,7 +45,7 @@ final class XmlReporter implements ReporterInterface
         $i = 1;
         foreach ($reportSummary->getChanged() as $file => $fixResult) {
             $fileXML = $dom->createElement('file');
-            $fileXML->setAttribute('id', $i++);
+            $fileXML->setAttribute('id', (string) $i++);
             $fileXML->setAttribute('name', $file);
             $filesXML->appendChild($fileXML);
 
@@ -117,7 +117,7 @@ final class XmlReporter implements ReporterInterface
         $timeXML = $dom->createElement('time');
         $timeXML->setAttribute('unit', 's');
         $timeTotalXML = $dom->createElement('total');
-        $timeTotalXML->setAttribute('value', $time);
+        $timeTotalXML->setAttribute('value', (string) $time);
         $timeXML->appendChild($timeTotalXML);
 
         return $timeXML;
@@ -134,7 +134,7 @@ final class XmlReporter implements ReporterInterface
         $memory = round($memory / 1024 / 1024, 3);
 
         $memoryXML = $dom->createElement('memory');
-        $memoryXML->setAttribute('value', $memory);
+        $memoryXML->setAttribute('value', (string) $memory);
         $memoryXML->setAttribute('unit', 'MB');
 
         return $memoryXML;

+ 2 - 2
src/Test/AbstractIntegrationTestCase.php

@@ -43,7 +43,7 @@ use Symfony\Component\Finder\Finder;
  * --SETTINGS--*
  * {"checkPriority": true}
  * --REQUIREMENTS--*
- * {"php": 5.4**, "hhvm": false***}
+ * {"php": "50600"**, "hhvm": false***}
  * --EXPECT--
  * Expected code after fixing
  * --INPUT--*
@@ -168,7 +168,7 @@ abstract class AbstractIntegrationTestCase extends \PHPUnit_Framework_TestCase
             $this->markTestSkipped('HHVM is not supported.');
         }
 
-        if (version_compare(PHP_VERSION, $case->getRequirement('php')) < 0) {
+        if (PHP_VERSION_ID < $case->getRequirement('php')) {
             $this->markTestSkipped(sprintf('PHP %s (or later) is required for "%s".', $case->getRequirement('php'), $case->getFileName()));
         }
 

+ 1 - 1
src/Test/IntegrationCaseFactory.php

@@ -124,7 +124,7 @@ final class IntegrationCaseFactory
     {
         return $this->parseJson($config, array(
             'hhvm' => true,
-            'php' => PHP_VERSION,
+            'php' => PHP_VERSION_ID,
         ));
     }
 

+ 10 - 1
src/Utils.php

@@ -115,6 +115,15 @@ final class Utils
             throw new \InvalidArgumentException(sprintf('The given token must be whitespace, got "%s".', $token->getName()));
         }
 
-        return ltrim(strrchr(str_replace(array("\r\n", "\r"), "\n", $token->getContent()), 10), "\n");
+        $str = strrchr(
+            str_replace(array("\r\n", "\r"), "\n", $token->getContent()),
+            "\n"
+        );
+
+        if (false === $str) {
+            return '';
+        }
+
+        return ltrim($str, "\n");
     }
 }

+ 31 - 1
tests/Cache/FileCacheManagerTest.php

@@ -67,6 +67,11 @@ final class FileCacheManagerTest extends \PHPUnit_Framework_TestCase
             ))
         ;
 
+        $handler
+            ->method('getFile')
+            ->willReturn($this->getFile())
+        ;
+
         $manager = new FileCacheManager(
             $handler,
             $signature
@@ -115,6 +120,11 @@ final class FileCacheManagerTest extends \PHPUnit_Framework_TestCase
             ))
         ;
 
+        $handler
+            ->method('getFile')
+            ->willReturn($this->getFile())
+        ;
+
         $manager = new FileCacheManager(
             $handler,
             $signature
@@ -158,6 +168,11 @@ final class FileCacheManagerTest extends \PHPUnit_Framework_TestCase
             ->with($this->identicalTo($cache))
         ;
 
+        $handler
+            ->method('getFile')
+            ->willReturn($this->getFile())
+        ;
+
         $manager = new FileCacheManager(
             $handler,
             $signature
@@ -211,6 +226,11 @@ final class FileCacheManagerTest extends \PHPUnit_Framework_TestCase
             ->willReturn($cache)
         ;
 
+        $handler
+            ->method('getFile')
+            ->willReturn($this->getFile())
+        ;
+
         $manager = new FileCacheManager(
             $handler,
             $signature
@@ -266,6 +286,11 @@ final class FileCacheManagerTest extends \PHPUnit_Framework_TestCase
             ->willReturn($cache)
         ;
 
+        $handler
+            ->method('getFile')
+            ->willReturn($this->getFile())
+        ;
+
         $manager = new FileCacheManager(
             $handler,
             $signature
@@ -320,6 +345,11 @@ final class FileCacheManagerTest extends \PHPUnit_Framework_TestCase
             ->willReturn($cache)
         ;
 
+        $handler
+            ->method('getFile')
+            ->willReturn($this->getFile())
+        ;
+
         $manager = new FileCacheManager(
             $handler,
             $signature
@@ -706,7 +736,7 @@ final class FileCacheManagerTest extends \PHPUnit_Framework_TestCase
      */
     private function getFile()
     {
-        return __DIR__.'/.php_cs.cache';
+        return __DIR__.'/../Fixtures/.php_cs.empty-cache';
     }
 
     /**

+ 0 - 0
tests/Fixtures/.php_cs.empty-cache


+ 1 - 1
tests/Fixtures/Integration/misc/PHP7.test

@@ -8,7 +8,7 @@ PHP 7 test.
 --SETTINGS--
 {"checkPriority": false}
 --REQUIREMENTS--
-{"php": 7.0}
+{"php": "70000"}
 --EXPECT--
 <?php
 

Some files were not shown because too many files changed in this diff