Browse Source

Merge pull request #13891 from cakephp/4.x-cleanup

4.x cleanup
Mark Story 6 years ago
parent
commit
d53069ccee

+ 2 - 20
phpstan-baseline.neon

@@ -238,11 +238,6 @@ parameters:
 			path: src/I18n/Date.php
 
 		-
-			message: "#^Parameter \\#4 \\$timezone of function datefmt_create expects int, null given\\.$#"
-			count: 1
-			path: src/I18n/Date.php
-
-		-
 			message: "#^Parameter \\#5 \\$calendar of function datefmt_create expects int\\|IntlCalendar, null given\\.$#"
 			count: 1
 			path: src/I18n/Date.php
@@ -253,11 +248,6 @@ parameters:
 			path: src/I18n/FrozenDate.php
 
 		-
-			message: "#^Parameter \\#4 \\$timezone of function datefmt_create expects int, null given\\.$#"
-			count: 1
-			path: src/I18n/FrozenDate.php
-
-		-
 			message: "#^Parameter \\#5 \\$calendar of function datefmt_create expects int\\|IntlCalendar, null given\\.$#"
 			count: 1
 			path: src/I18n/FrozenDate.php
@@ -273,11 +263,6 @@ parameters:
 			path: src/I18n/FrozenTime.php
 
 		-
-			message: "#^Parameter \\#4 \\$timezone of function datefmt_create expects int, null given\\.$#"
-			count: 1
-			path: src/I18n/FrozenTime.php
-
-		-
 			message: "#^Parameter \\#5 \\$calendar of function datefmt_create expects int\\|IntlCalendar, null given\\.$#"
 			count: 1
 			path: src/I18n/FrozenTime.php
@@ -293,11 +278,6 @@ parameters:
 			path: src/I18n/Time.php
 
 		-
-			message: "#^Parameter \\#4 \\$timezone of function datefmt_create expects int, null given\\.$#"
-			count: 1
-			path: src/I18n/Time.php
-
-		-
 			message: "#^Parameter \\#5 \\$calendar of function datefmt_create expects int\\|IntlCalendar, null given\\.$#"
 			count: 1
 			path: src/I18n/Time.php
@@ -531,3 +511,5 @@ parameters:
 			message: "#^Class Psy\\\\Shell not found\\.$#"
 			count: 1
 			path: src/basics.php
+
+

+ 0 - 2
src/Cache/CacheRegistry.php

@@ -91,8 +91,6 @@ class CacheRegistry extends ObjectRegistry
             );
         }
 
-        $config = $instance->getConfig();
-
         return $instance;
     }
 

+ 0 - 2
src/Console/ConsoleOutput.php

@@ -296,13 +296,11 @@ class ConsoleOutput
     public function setStyle(string $style, array $definition): void
     {
         if (!$definition) {
-            /** @psalm-suppress PossiblyNullArrayOffset */
             unset(static::$_styles[$style]);
 
             return;
         }
 
-        /** @psalm-suppress PossiblyNullArrayOffset */
         static::$_styles[$style] = $definition;
     }
 

+ 0 - 1
src/Controller/Component/SecurityComponent.php

@@ -352,7 +352,6 @@ class SecurityComponent extends Component
             if (!empty($unlockedFields)) {
                 foreach ($unlockedFields as $off) {
                     $off = explode('.', $off);
-                    /** @psalm-suppress PossiblyInvalidArgument */
                     $field = array_values(array_intersect(explode('.', $key), $off));
                     $isUnlocked = ($field === $off);
                     if ($isUnlocked) {

+ 0 - 1
src/Database/Query.php

@@ -2123,7 +2123,6 @@ class Query implements ExpressionInterface, IteratorAggregate
         }
 
         if ($expression->getConjunction() === $conjunction) {
-            /** @psalm-suppress PossiblyInvalidArgument */
             $expression->add($append, $types);
         } else {
             $expression = $this->newExpr()

+ 0 - 1
src/Database/Schema/SqlserverSchema.php

@@ -179,7 +179,6 @@ class SqlserverSchema extends BaseSchema
             $field['autoIncrement'] = true;
         }
         if ($field['type'] === TableSchema::TYPE_BOOLEAN) {
-            /** @psalm-suppress PossiblyUndefinedArrayOffset */
             $row['default'] = (int)$row['default'];
         }
 

+ 3 - 6
src/Database/Type/DateTimeType.php

@@ -247,16 +247,13 @@ class DateTimeType extends BaseType
 
         $class = $this->_className;
         try {
-            $date = false;
-            if ($value === '' || $value === null || $value === false || $value === true) {
+            if ($value === '' || $value === null || is_bool($value)) {
                 return null;
             }
             $isString = is_string($value);
             if (ctype_digit($value)) {
-                /** @var \DateTimeInterface $date */
-                $date = new $class('@' . $value);
-
-                return $date;
+                /** @var \DateTimeInterface */
+                return new $class('@' . $value);
             } elseif ($isString && $this->_useLocaleMarshal) {
                 return $this->_parseLocaleValue($value);
             } elseif ($isString) {

+ 0 - 1
src/Form/FormProtector.php

@@ -348,7 +348,6 @@ class FormProtector
             if (!empty($unlockedFields)) {
                 foreach ($unlockedFields as $off) {
                     $off = explode('.', $off);
-                    /** @psalm-suppress PossiblyInvalidArgument */
                     $field = array_values(array_intersect(explode('.', $key), $off));
                     $isUnlocked = ($field === $off);
                     if ($isUnlocked) {

+ 1 - 1
src/Http/ControllerFactory.php

@@ -3,7 +3,7 @@ declare(strict_types=1);
 
 class_alias(
     'Cake\Controller\ControllerFactory',
-    'Cake\Http\ControllerFactory',
+    'Cake\Http\ControllerFactory'
 );
 deprecationWarning(
     'Use Cake\Controller\ControllerFactory instead of Cake\Http\ControllerFactory.'

+ 1 - 1
src/Routing/Exception/MissingControllerException.php

@@ -3,7 +3,7 @@ declare(strict_types=1);
 
 class_alias(
     'Cake\Http\Exception\MissingControllerException',
-    'Cake\Routing\Exception\MissingControllerException',
+    'Cake\Routing\Exception\MissingControllerException'
 );
 deprecationWarning(
     'Use Cake\Http\Exception\MissingControllerException instead of Cake\Routing\Exception\MissingControllerException.'

+ 0 - 2
src/Routing/RouteBuilder.php

@@ -834,7 +834,6 @@ class RouteBuilder
      * @param callable|null $callback The callback to invoke that builds the prefixed routes.
      * @return $this
      * @throws \InvalidArgumentException If a valid callback is not passed
-     * @psalm-suppress PossiblyInvalidArrayAccess
      */
     public function prefix(string $name, $params = [], $callback = null)
     {
@@ -851,7 +850,6 @@ class RouteBuilder
         if (isset($this->_params['prefix'])) {
             $name = $this->_params['prefix'] . '/' . $name;
         }
-        /** @psalm-suppress PossiblyInvalidArgument */
         $params = array_merge($params, ['prefix' => $name]);
         $this->scope($path, $params, $callback);
 

+ 0 - 1
src/Routing/Router.php

@@ -879,7 +879,6 @@ class Router
      * @param callable|null $callback The callback to invoke that builds the plugin routes.
      *   Only required when $options is defined
      * @return void
-     * @psalm-suppress PossiblyInvalidArrayAccess
      */
     public static function plugin(string $name, $options = [], $callback = null): void
     {

+ 0 - 1
src/View/Widget/RadioWidget.php

@@ -223,7 +223,6 @@ class RadioWidget extends BasicWidget
             $label = $input;
         }
 
-        /** @psalm-suppress PossiblyUndefinedArrayOffset */
         return $this->_templates->format('radioWrapper', [
             'input' => $input,
             'label' => $label,

+ 8 - 12
tests/TestCase/Command/SchemacacheCommandsTest.php

@@ -17,6 +17,7 @@ declare(strict_types=1);
 namespace Cake\Test\TestCase\Command;
 
 use Cake\Cache\Cache;
+use Cake\Cache\Engine\NullEngine;
 use Cake\Datasource\ConnectionManager;
 use Cake\TestSuite\ConsoleIntegrationTestTrait;
 use Cake\TestSuite\TestCase;
@@ -48,10 +49,9 @@ class SchemacacheCommandsTest extends TestCase
         $this->setAppNamespace();
         $this->useCommandRunner();
 
-        $this->cache = $this->getMockBuilder('Cake\Cache\CacheEngine')->getMock();
-        $this->cache->expects($this->any())
-            ->method('init')
-            ->will($this->returnValue(true));
+        $this->cache = $this->getMockBuilder(NullEngine::class)
+            ->setMethods(['set', 'get', 'delete'])
+            ->getMock();
         Cache::setConfig('orm_cache', $this->cache);
 
         $this->connection = ConnectionManager::get('test');
@@ -123,10 +123,7 @@ class SchemacacheCommandsTest extends TestCase
      */
     public function testBuildNoArgs()
     {
-        $this->cache->expects($this->any())
-            ->method('set')
-            ->will($this->returnValue(true));
-        $this->cache->expects($this->at(3))
+        $this->cache->expects($this->at(0))
             ->method('set')
             ->with('test_articles')
             ->will($this->returnValue(true));
@@ -204,11 +201,10 @@ class SchemacacheCommandsTest extends TestCase
      */
     public function testClearNoArgs()
     {
-        $this->cache->method('delete')
-            ->will($this->returnValue(true));
-        $this->cache->expects($this->at(3))
+        $this->cache->expects($this->at(0))
             ->method('delete')
-            ->with('test_articles');
+            ->with('test_articles')
+            ->will($this->returnValue(true));
 
         $this->exec('schema_cache clear --connection test');
         $this->assertExitSuccess();

+ 8 - 13
tests/TestCase/Database/SchemaCacheTest.php

@@ -17,7 +17,7 @@ declare(strict_types=1);
 namespace Cake\Test\TestCase\Database;
 
 use Cake\Cache\Cache;
-use Cake\Cache\CacheEngine;
+use Cake\Cache\Engine\NullEngine;
 use Cake\Database\Schema\CachedCollection;
 use Cake\Database\SchemaCache;
 use Cake\Datasource\ConnectionManager;
@@ -53,10 +53,9 @@ class SchemaCacheTest extends TestCase
     {
         parent::setUp();
 
-        $this->cache = $this->getMockBuilder(CacheEngine::class)->getMock();
-        $this->cache->expects($this->any())
-            ->method('init')
-            ->will($this->returnValue(true));
+        $this->cache = $this->getMockBuilder(NullEngine::class)
+            ->setMethods(['set', 'get', 'delete'])
+            ->getMock();
         Cache::setConfig('orm_cache', $this->cache);
 
         $this->connection = ConnectionManager::get('test');
@@ -114,9 +113,7 @@ class SchemaCacheTest extends TestCase
      */
     public function testBuildNoArgs()
     {
-        $this->cache->method('set')
-            ->will($this->returnValue(true));
-        $this->cache->expects($this->at(3))
+        $this->cache->expects($this->at(0))
             ->method('set')
             ->with('test_articles')
             ->will($this->returnValue(true));
@@ -170,12 +167,10 @@ class SchemaCacheTest extends TestCase
      */
     public function testClearNoArgs()
     {
-        $this->cache->method('delete')
-            ->will($this->returnValue(true));
-
-        $this->cache->expects($this->at(3))
+        $this->cache->expects($this->at(0))
             ->method('delete')
-            ->with('test_articles');
+            ->with('test_articles')
+            ->will($this->returnValue(true));
 
         $ormCache = new SchemaCache($this->connection);
         $ormCache->clear();