Browse Source

Fix phpstan errors on interfaces - level 5

mscherer 7 years ago
parent
commit
2c08e46229

+ 1 - 1
src/Database/Schema/CachedCollection.php

@@ -70,7 +70,7 @@ class CachedCollection implements CollectionInterface
     /**
      * {@inheritDoc}
      */
-    public function describe(string $name, array $options = []): TableSchemaInterface
+    public function describe(string $name, array $options = []): TableSchema
     {
         $options += ['forceRefresh' => false];
         $cacheConfig = $this->getCacheMetadata();

+ 2 - 2
src/Database/Schema/Collection.php

@@ -86,10 +86,10 @@ class Collection implements CollectionInterface
      *
      * @param string $name The name of the table to describe.
      * @param array $options The options to use, see above.
-     * @return \Cake\Database\Schema\TableSchemaInterface Object with column metadata.
+     * @return \Cake\Database\Schema\TableSchema Object with column metadata.
      * @throws \Cake\Database\Exception when table cannot be described.
      */
-    public function describe(string $name, array $options = []): TableSchemaInterface
+    public function describe(string $name, array $options = []): TableSchema
     {
         $config = $this->_connection->config();
         if (strpos($name, '.')) {

+ 2 - 2
src/Database/Schema/CollectionInterface.php

@@ -44,8 +44,8 @@ interface CollectionInterface
      *
      * @param string $name The name of the table to describe.
      * @param array $options The options to use, see above.
-     * @return \Cake\Database\Schema\TableSchemaInterface Object with column metadata.
+     * @return \Cake\Database\Schema\TableSchema Object with column metadata.
      * @throws \Cake\Database\Exception when table cannot be described.
      */
-    public function describe(string $name, array $options = []): TableSchemaInterface;
+    public function describe(string $name, array $options = []): TableSchema;
 }

+ 11 - 11
src/Database/Schema/SqlGeneratorInterface.php

@@ -16,7 +16,7 @@ declare(strict_types=1);
  */
 namespace Cake\Database\Schema;
 
-use Cake\Database\Connection;
+use Cake\Datasource\ConnectionInterface;
 
 /**
  * An interface used by TableSchema objects.
@@ -29,11 +29,11 @@ interface SqlGeneratorInterface
      * Uses the connection to access the schema dialect
      * to generate platform specific SQL.
      *
-     * @param \Cake\Database\Connection $connection The connection to generate SQL for.
+     * @param \Cake\Datasource\ConnectionInterface $connection The connection to generate SQL for.
      * @return array List of SQL statements to create the table and the
      *    required indexes.
      */
-    public function createSql(Connection $connection): array;
+    public function createSql(ConnectionInterface $connection): array;
 
     /**
      * Generate the SQL to drop a table.
@@ -41,32 +41,32 @@ interface SqlGeneratorInterface
      * Uses the connection to access the schema dialect to generate platform
      * specific SQL.
      *
-     * @param \Cake\Database\Connection $connection The connection to generate SQL for.
+     * @param \Cake\Datasource\ConnectionInterface $connection The connection to generate SQL for.
      * @return array SQL to drop a table.
      */
-    public function dropSql(Connection $connection): array;
+    public function dropSql(ConnectionInterface $connection): array;
 
     /**
      * Generate the SQL statements to truncate a table
      *
-     * @param \Cake\Database\Connection $connection The connection to generate SQL for.
+     * @param \Cake\Datasource\ConnectionInterface $connection The connection to generate SQL for.
      * @return array SQL to truncate a table.
      */
-    public function truncateSql(Connection $connection): array;
+    public function truncateSql(ConnectionInterface $connection): array;
 
     /**
      * Generate the SQL statements to add the constraints to the table
      *
-     * @param \Cake\Database\Connection $connection The connection to generate SQL for.
+     * @param \Cake\Datasource\ConnectionInterface $connection The connection to generate SQL for.
      * @return array SQL to add the constraints.
      */
-    public function addConstraintSql(Connection $connection): array;
+    public function addConstraintSql(ConnectionInterface $connection): array;
 
     /**
      * Generate the SQL statements to drop the constraints to the table
      *
-     * @param \Cake\Database\Connection $connection The connection to generate SQL for.
+     * @param \Cake\Datasource\ConnectionInterface $connection The connection to generate SQL for.
      * @return array SQL to drop a table.
      */
-    public function dropConstraintSql(Connection $connection): array;
+    public function dropConstraintSql(ConnectionInterface $connection): array;
 }

+ 6 - 6
src/Database/Schema/TableSchema.php

@@ -16,9 +16,9 @@ declare(strict_types=1);
  */
 namespace Cake\Database\Schema;
 
-use Cake\Database\Connection;
 use Cake\Database\Exception;
 use Cake\Database\TypeFactory;
+use Cake\Datasource\ConnectionInterface;
 
 /**
  * Represents a single table in a database schema.
@@ -703,7 +703,7 @@ class TableSchema implements TableSchemaInterface, SqlGeneratorInterface
     /**
      * @inheritDoc
      */
-    public function createSql(Connection $connection): array
+    public function createSql(ConnectionInterface $connection): array
     {
         $dialect = $connection->getDriver()->schemaDialect();
         $columns = $constraints = $indexes = [];
@@ -723,7 +723,7 @@ class TableSchema implements TableSchemaInterface, SqlGeneratorInterface
     /**
      * @inheritDoc
      */
-    public function dropSql(Connection $connection): array
+    public function dropSql(ConnectionInterface $connection): array
     {
         $dialect = $connection->getDriver()->schemaDialect();
 
@@ -733,7 +733,7 @@ class TableSchema implements TableSchemaInterface, SqlGeneratorInterface
     /**
      * @inheritDoc
      */
-    public function truncateSql(Connection $connection): array
+    public function truncateSql(ConnectionInterface $connection): array
     {
         $dialect = $connection->getDriver()->schemaDialect();
 
@@ -743,7 +743,7 @@ class TableSchema implements TableSchemaInterface, SqlGeneratorInterface
     /**
      * @inheritDoc
      */
-    public function addConstraintSql(Connection $connection): array
+    public function addConstraintSql(ConnectionInterface $connection): array
     {
         $dialect = $connection->getDriver()->schemaDialect();
 
@@ -753,7 +753,7 @@ class TableSchema implements TableSchemaInterface, SqlGeneratorInterface
     /**
      * @inheritDoc
      */
-    public function dropConstraintSql(Connection $connection): array
+    public function dropConstraintSql(ConnectionInterface $connection): array
     {
         $dialect = $connection->getDriver()->schemaDialect();
 

+ 1 - 1
src/Database/Statement/BufferedStatement.php

@@ -48,7 +48,7 @@ class BufferedStatement implements Iterator, StatementInterface
     /**
      * The driver for the statement
      *
-     * @var \Cake\Database\DriverInterface
+     * @var \Cake\Database\Driver
      */
     protected $_driver;
 

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

@@ -285,7 +285,7 @@ class DateTimeType extends BaseType
     }
 
     /**
-     * @param \Cake\I18n\Time|\DateTime $date DateTime object
+     * @param \DateTimeInterface $date DateTime object
      * @param mixed $value Request data
      * @return bool
      */

+ 1 - 0
src/Datasource/ConnectionInterface.php

@@ -28,6 +28,7 @@ use Cake\Database\Log\QueryLogger;
  * @method \Cake\Database\StatementInterface prepare($sql)
  * @method \Cake\Database\StatementInterface execute($query, $params = [], array $types = [])
  * @method string quote($value, $type = null)
+ * @method \Cake\Database\Driver getDriver()
  */
 interface ConnectionInterface
 {

+ 1 - 1
src/Http/ActionDispatcher.php

@@ -47,7 +47,7 @@ class ActionDispatcher
      * Dispatches a Request & Response
      *
      * @param \Cake\Http\ServerRequest $request The request to dispatch.
-     * @param \Psr\Http\Message\ResponseInterface $response The response to dispatch.
+     * @param \Cake\Http\Response $response The response to dispatch.
      * @return \Psr\Http\Message\ResponseInterface A modified/replaced response.
      */
     public function dispatch(ServerRequest $request, ?ResponseInterface $response = null): ResponseInterface

+ 2 - 1
src/Http/BaseApplication.php

@@ -127,6 +127,7 @@ abstract class BaseApplication implements
      * @param string $name The plugin classname
      * @param array $config Configuration options for the plugin
      * @return \Cake\Core\PluginInterface
+     * @throws \InvalidArgumentException
      */
     protected function makePlugin(string $name, array $config): PluginInterface
     {
@@ -233,7 +234,7 @@ abstract class BaseApplication implements
      * - Create the controller that will handle this request.
      * - Invoke the controller.
      *
-     * @param \Psr\Http\Message\ServerRequestInterface $request The request
+     * @param \Cake\Http\ServerRequest $request The request
      * @return \Psr\Http\Message\ResponseInterface
      */
     public function handle(

+ 7 - 6
src/Http/Middleware/CsrfProtectionMiddleware.php

@@ -85,7 +85,7 @@ class CsrfProtectionMiddleware implements MiddlewareInterface
     /**
      * Checks and sets the CSRF token depending on the HTTP verb.
      *
-     * @param \Psr\Http\Message\ServerRequestInterface $request The request.
+     * @param \Cake\Http\ServerRequest $request The request.
      * @param \Psr\Http\Server\RequestHandlerInterface $handler The request handler.
      * @return \Psr\Http\Message\ResponseInterface A response.
      */
@@ -104,6 +104,7 @@ class CsrfProtectionMiddleware implements MiddlewareInterface
         if ($method === 'GET' && $cookieData === null) {
             $token = $this->_createToken();
             $request = $this->_addTokenToRequest($token, $request);
+            /** @var \Cake\Http\Response $response */
             $response = $handler->handle($request);
 
             return $this->_addTokenCookie($token, $request, $response);
@@ -147,10 +148,10 @@ class CsrfProtectionMiddleware implements MiddlewareInterface
      * Add a CSRF token to the request parameters.
      *
      * @param string $token The token to add.
-     * @param \Cake\Http\ServerRequest $request The request to augment
-     * @return \Cake\Http\ServerRequest Modified request
+     * @param \Psr\Http\Message\ServerRequestInterface $request The request to augment
+     * @return \Psr\Http\Message\ServerRequestInterface Modified request
      */
-    protected function _addTokenToRequest(string $token, ServerRequest $request): ServerRequest
+    protected function _addTokenToRequest(string $token, ServerRequestInterface $request): ServerRequestInterface
     {
         $params = $request->getAttribute('params');
         $params['_csrfToken'] = $token;
@@ -162,11 +163,11 @@ class CsrfProtectionMiddleware implements MiddlewareInterface
      * Add a CSRF token to the response cookies.
      *
      * @param string $token The token to add.
-     * @param \Cake\Http\ServerRequest $request The request to validate against.
+     * @param \Psr\Http\Message\ServerRequestInterface $request The request to validate against.
      * @param \Cake\Http\Response $response The response.
      * @return \Cake\Http\Response $response Modified response.
      */
-    protected function _addTokenCookie(string $token, ServerRequest $request, Response $response): Response
+    protected function _addTokenCookie(string $token, ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
     {
         $expiry = new Time($this->_config['expiry']);
 

+ 2 - 2
src/ORM/ResultSet.php

@@ -58,7 +58,7 @@ class ResultSet implements ResultSetInterface
     /**
      * Default table instance
      *
-     * @var \Cake\ORM\Table|\Cake\Datasource\RepositoryInterface
+     * @var \Cake\ORM\Table
      */
     protected $_defaultTable;
 
@@ -172,7 +172,7 @@ class ResultSet implements ResultSetInterface
         $repository = $query->getRepository();
         $this->_statement = $statement;
         $this->_driver = $query->getConnection()->getDriver();
-        $this->_defaultTable = $query->getRepository();
+        $this->_defaultTable = $repository;
         $this->_calculateAssociationMap($query);
         $this->_hydrate = $query->isHydrationEnabled();
         $this->_entityClass = $repository->getEntityClass();

+ 2 - 2
src/Routing/Router.php

@@ -245,10 +245,10 @@ class Router
      * Push a request onto the request stack. Pushing a request
      * sets the request context used when generating URLs.
      *
-     * @param \Cake\Http\ServerRequest $request Request instance.
+     * @param \Psr\Http\Message\ServerRequestInterface $request Request instance.
      * @return void
      */
-    public static function pushRequest(ServerRequest $request): void
+    public static function pushRequest(ServerRequestInterface $request): void
     {
         static::$_requests[] = $request;
         static::setRequestContext($request);

+ 3 - 2
src/TestSuite/Fixture/FixtureManager.php

@@ -285,13 +285,14 @@ class FixtureManager
         }
 
         try {
-            $createTables = function ($db, $fixtures) use ($test): void {
+            $createTables = function (ConnectionInterface $db, $fixtures) use ($test): void {
                 $tables = $db->getSchemaCollection()->listTables();
                 $configName = $db->configName();
                 if (!isset($this->_insertionMap[$configName])) {
                     $this->_insertionMap[$configName] = [];
                 }
 
+                /** @var \Cake\Datasource\FixtureInterface[] $fixtures */
                 foreach ($fixtures as $fixture) {
                     if (in_array($fixture->table, $tables, true)) {
                         try {
@@ -376,7 +377,7 @@ class FixtureManager
             if ($logQueries && !$this->_debug) {
                 $db->disableQueryLogging();
             }
-            $db->transactional(function ($db) use ($fixtures, $operation): void {
+            $db->transactional(function (ConnectionInterface $db) use ($fixtures, $operation): void {
                 $db->disableConstraints(function ($db) use ($fixtures, $operation): void {
                     $operation($db, $fixtures);
                 });

+ 2 - 1
tests/TestCase/Controller/ControllerTest.php

@@ -448,7 +448,8 @@ class ControllerTest extends TestCase
      */
     public function testRefererSlash(): void
     {
-        $request = $this->getMockBuilder('Cake\Http\ServerRequest')
+        /** @var \Cake\Http\ServerRequest|\PHPUnit\Framework\MockObject\MockObject $request */
+        $request = $this->getMockBuilder(ServerRequest::class)
             ->setMethods(['referer'])
             ->getMock();
         $request = $request->withAttribute('base', '/base');