Browse Source

Merge pull request #13007 from cakephp/master-phpstan

Update phpstan
ADmad 7 years ago
parent
commit
7b7a66a0f9

+ 1 - 1
.travis.yml

@@ -93,7 +93,7 @@ script:
 
   - if [[ $CODECOVERAGE == 1 ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=clover.xml; fi
 
-  - if [[ $CHECKS == 1 ]]; then composer require --dev "phpstan/phpstan:^0.10" && vendor/bin/phpstan analyse -c phpstan.neon -l 2 src/; fi
+  - if [[ $CHECKS == 1 ]]; then composer require --dev phpstan/phpstan:^0.11 && vendor/bin/phpstan analyse -c phpstan.neon -l 2 src/; fi
   - if [[ $CHECKS == 1 ]]; then composer cs-check; fi
 
 after_success:

+ 3 - 3
phpstan.neon

@@ -3,9 +3,6 @@ parameters:
         - tests/bootstrap.php
     ignoreErrors:
         - '#Constant MCRYPT_[A-Z0-9_]+ not found#'
-        - '#Function mcrypt_[a-zA-Z0-9_]+ not found#'
-        - '#Function wincache_ucache_[a-zA-Z0-9_]+ not found#'
-        - '#Function xcache_[a-zA-Z0-9_]+ not found#'
         - '#Cake\\Database\\Type\\[a-zA-Z0-9_]+Type::__construct\(\) does not call parent constructor from Cake\\Database\\Type#'
         - '#Constructor of class Cake\\[a-zA-Z0-9_\\]+ has an unused parameter#'
         - '#Access to undefined constant Memcached::OPT_CLIENT_MODE#'
@@ -21,6 +18,8 @@ parameters:
         - '#Access to an undefined property PHPUnit\\Framework\\Test::\$fixtureManager#'
         - '#Call to an undefined method Traversable::getArrayCopy().#'
         - '#Variable \$config in isset\(\) is never defined#'
+        - '#Variable \$plural in isset\(\) is never defined#'
+        - '#Variable \$context in isset\(\) is never defined#'
         - '#Call to static method id\(\) on an unknown class PHPUnit_Runner_Version#'
         - '#Call to an undefined method DateTimeInterface::i18nFormat\(\)#'
         - '#Cannot call method lastInsertId\(\) on null#'
@@ -29,6 +28,7 @@ parameters:
         - '#Variable \$_SESSION in isset\(\) always exists and is not nullable#'
         - '#PHPDoc tag @throws with type PHPUnit\\Exception is not subtype of Throwable#'
         - '#Call to an undefined method PHPUnit\\Framework\\MockObject\\MockObject#'
+        - '#Call to an undefined method DOMNode::setAttribute\(\)#'
         - '#Binary operation "\+" between array|false and array results in an error#'
         - '#Result of method Cake\\Auth\\BaseAuthenticate::unauthenticated\(\) \(void\) is used#'
     earlyTerminatingMethodCalls:

+ 1 - 1
src/Controller/Component/RequestHandlerComponent.php

@@ -241,7 +241,7 @@ class RequestHandlerComponent extends Component
         try {
             $xml = Xml::build($xml, ['return' => 'domdocument', 'readFile' => false]);
             // We might not get child nodes if there are nested inline entities.
-            if ($xml->childNodes->length > 0) {
+            if ((int)$xml->childNodes->length > 0) {
                 return Xml::toArray($xml);
             }
 

+ 1 - 1
src/Http/Middleware/BodyParserMiddleware.php

@@ -172,7 +172,7 @@ class BodyParserMiddleware
         try {
             $xml = Xml::build($body, ['return' => 'domdocument', 'readFile' => false]);
             // We might not get child nodes if there are nested inline entities.
-            if ($xml->childNodes->length > 0) {
+            if ((int)$xml->childNodes->length > 0) {
                 return Xml::toArray($xml);
             }
 

+ 9 - 9
src/I18n/RelativeTimeFormatter.php

@@ -197,27 +197,27 @@ class RelativeTimeFormatter
             list($past['H'], $past['i'], $past['s'], $past['d'], $past['m'], $past['Y']) = explode('/', date('H/i/s/d/m/Y', $pastTime));
             $weeks = $days = $hours = $minutes = $seconds = 0;
 
-            $years = $future['Y'] - $past['Y'];
-            $months = $future['m'] + ((12 * $years) - $past['m']);
+            $years = (int)$future['Y'] - (int)$past['Y'];
+            $months = (int)$future['m'] + ((12 * $years) - (int)$past['m']);
 
             if ($months >= 12) {
                 $years = floor($months / 12);
                 $months -= ($years * 12);
             }
-            if ($future['m'] < $past['m'] && $future['Y'] - $past['Y'] === 1) {
+            if ((int)$future['m'] < (int)$past['m'] && (int)$future['Y'] - (int)$past['Y'] === 1) {
                 $years--;
             }
 
-            if ($future['d'] >= $past['d']) {
-                $days = $future['d'] - $past['d'];
+            if ((int)$future['d'] >= (int)$past['d']) {
+                $days = (int)$future['d'] - (int)$past['d'];
             } else {
-                $daysInPastMonth = date('t', $pastTime);
-                $daysInFutureMonth = date('t', mktime(0, 0, 0, $future['m'] - 1, 1, $future['Y']));
+                $daysInPastMonth = (int)date('t', $pastTime);
+                $daysInFutureMonth = (int)date('t', mktime(0, 0, 0, (int)$future['m'] - 1, 1, (int)$future['Y']));
 
                 if (!$backwards) {
-                    $days = ($daysInPastMonth - $past['d']) + $future['d'];
+                    $days = ($daysInPastMonth - (int)$past['d']) + (int)$future['d'];
                 } else {
-                    $days = ($daysInFutureMonth - $past['d']) + $future['d'];
+                    $days = ($daysInFutureMonth - (int)$past['d']) + (int)$future['d'];
                 }
 
                 if ($future['m'] != $past['m']) {

+ 9 - 6
src/Validation/Validation.php

@@ -1336,9 +1336,10 @@ class Validation
     /**
      * Validates the size of an uploaded image.
      *
-     * @param array|\Psr\Http\Message\UploadedFileInterface  $file The uploaded file data from PHP.
+     * @param array|\Psr\Http\Message\UploadedFileInterface $file The uploaded file data from PHP.
      * @param array $options Options to validate width and height.
      * @return bool
+     * @throws \InvalidArgumentException
      */
     public static function imageSize($file, $options)
     {
@@ -1346,9 +1347,11 @@ class Validation
             throw new InvalidArgumentException('Invalid image size validation parameters! Missing `width` and / or `height`.');
         }
 
-        $file = static::getFilename($file);
+        $filename = static::getFilename($file);
+
+        list($width, $height) = getimagesize($filename);
 
-        list($width, $height) = getimagesize($file);
+        $validHeight = $validWidth = null;
 
         if (isset($options['height'])) {
             $validHeight = self::comparison($height, $options['height'][0], $options['height'][1]);
@@ -1356,13 +1359,13 @@ class Validation
         if (isset($options['width'])) {
             $validWidth = self::comparison($width, $options['width'][0], $options['width'][1]);
         }
-        if (isset($validHeight, $validWidth)) {
+        if ($validHeight !== null && $validWidth !== null) {
             return ($validHeight && $validWidth);
         }
-        if (isset($validHeight)) {
+        if ($validHeight !== null) {
             return $validHeight;
         }
-        if (isset($validWidth)) {
+        if ($validWidth !== null) {
             return $validWidth;
         }