Browse Source

Merge branch '4.next' into 5.x

ADmad 3 years ago
parent
commit
629aaebb37

+ 1 - 1
.gitattributes

@@ -37,7 +37,7 @@ tests/TestCase export-ignore
 .stickler.yml export-ignore
 Makefile export-ignore
 phpcs.xml export-ignore
-phpstan.neon export-ignore
+phpstan.neon.dist export-ignore
 phpstan-baseline.neon export-ignore
 phpunit.xml.dist export-ignore
 psalm.xml export-ignore

+ 1 - 1
.github/workflows/cancel.yml

@@ -13,6 +13,6 @@ jobs:
       actions: write  # for styfle/cancel-workflow-action to cancel/stop running workflows
     runs-on: ubuntu-latest
     steps:
-    - uses: styfle/cancel-workflow-action@0.10.0
+    - uses: styfle/cancel-workflow-action@0.10
       with:
         workflow_id: ${{ github.event.workflow.id }}

+ 1 - 0
.gitignore

@@ -5,6 +5,7 @@
 /tags
 /composer.lock
 /phpunit.xml
+/phpstan.neon
 /vendor
 /vendors
 /composer.phar

phpstan.neon → phpstan.neon.dist


+ 1 - 0
src/Cache/Engine/FileEngine.php

@@ -167,6 +167,7 @@ class FileEngine extends CacheEngine
 
         $this->_File->rewind();
         $time = time();
+        /** @psalm-suppress RiskyCast */
         $cachetime = (int)$this->_File->current();
 
         if ($cachetime < $time) {

+ 2 - 0
src/Core/functions.php

@@ -206,8 +206,10 @@ if (!function_exists('env')) {
             $key = 'SCRIPT_URL';
         }
 
+        /** @var string|null $val */
         $val = $_SERVER[$key] ?? $_ENV[$key] ?? null;
         if ($val == null && getenv($key) !== false) {
+            /** @var string|false $val */
             $val = getenv($key);
         }
 

+ 1 - 1
src/Database/Expression/WhenThenExpression.php

@@ -132,7 +132,7 @@ class WhenThenExpression implements ExpressionInterface
                 'The `$when` argument must be either a non-empty array, a scalar value, an object, ' .
                 'or an instance of `\%s`, `%s` given.',
                 ExpressionInterface::class,
-                is_array($when) ? '[]' : get_debug_type($when)
+                is_array($when) ? '[]' : get_debug_type($when) // @phpstan-ignore-line
             ));
         }
 

+ 4 - 4
src/Database/Type/DateTimeType.php

@@ -313,7 +313,7 @@ class DateTimeType extends BaseType implements BatchCastingInterface
             return $value->setTimezone($this->defaultTimezone);
         }
 
-        /** @var class-string<\DatetimeInterface> $class */
+        /** @var class-string<\DateTimeInterface> $class */
         $class = $this->_className;
         try {
             if ($value === '' || $value === null || is_bool($value)) {
@@ -321,7 +321,7 @@ class DateTimeType extends BaseType implements BatchCastingInterface
             }
 
             if (is_int($value) || (is_string($value) && ctype_digit($value))) {
-                /** @var \Datetime|\DateTimeImmutable $dateTime */
+                /** @var \DateTime|\DateTimeImmutable $dateTime */
                 $dateTime = new $class('@' . $value);
 
                 return $dateTime->setTimezone($this->defaultTimezone);
@@ -334,7 +334,7 @@ class DateTimeType extends BaseType implements BatchCastingInterface
                     $dateTime = $this->_parseValue($value);
                 }
 
-                /** @var \Datetime|\DateTimeImmutable|null $dateTime */
+                /** @var \DateTime|\DateTimeImmutable|null $dateTime */
                 if ($dateTime !== null) {
                     $dateTime = $dateTime->setTimezone($this->defaultTimezone);
                 }
@@ -377,7 +377,7 @@ class DateTimeType extends BaseType implements BatchCastingInterface
             $value['microsecond']
         );
 
-        /** @var \Datetime|\DateTimeImmutable $dateTime */
+        /** @var \DateTime|\DateTimeImmutable $dateTime */
         $dateTime = new $class($format, $value['timezone'] ?? $this->userTimezone);
 
         return $dateTime->setTimezone($this->defaultTimezone);

+ 1 - 1
src/Error/Debugger.php

@@ -715,7 +715,7 @@ class Debugger
         if ($remaining > 0) {
             if (method_exists($var, '__debugInfo')) {
                 try {
-                    foreach ($var->__debugInfo() as $key => $val) {
+                    foreach ((array)$var->__debugInfo() as $key => $val) {
                         $node->addProperty(new PropertyNode("'{$key}'", null, static::export($val, $context)));
                     }
 

+ 5 - 1
src/Validation/Validation.php

@@ -1271,7 +1271,11 @@ class Validation
     {
         if ($check instanceof UploadedFileInterface) {
             $code = $check->getError();
-        } elseif (is_array($check) && isset($check['error'])) {
+        } elseif (is_array($check)) {
+            if (!isset($check['error'])) {
+                return false;
+            }
+
             $code = $check['error'];
         } else {
             $code = $check;

+ 10 - 0
tests/TestCase/Error/DebuggerTest.php

@@ -28,6 +28,7 @@ use Cake\Error\Debugger;
 use Cake\Form\Form;
 use Cake\Http\ServerRequest;
 use Cake\Log\Log;
+use Cake\ORM\Table;
 use Cake\TestSuite\TestCase;
 use InvalidArgumentException;
 use MyClass;
@@ -378,6 +379,15 @@ TEXT;
     }
 
     /**
+     * Test exportVar with a mock
+     */
+    public function testExportVarMockObject(): void
+    {
+        $result = Debugger::exportVar($this->getMockBuilder(Table::class)->getMock());
+        $this->assertStringContainsString('object(Mock_Table', $result);
+    }
+
+    /**
      * Text exportVarAsNodes()
      */
     public function testExportVarAsNodes(): void