Browse Source

Fix PHPStan issues.

mscherer 7 years ago
parent
commit
7be8c8def8

+ 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']) {