Browse Source

Fix errors reported by psalm.

ADmad 6 years ago
parent
commit
cea018e3d4

+ 15 - 122
psalm-baseline.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<files>
+<files psalm-version="3.3.2@201030928de5001941a59eddce77b9d326bc1880">
   <file src="src/Auth/BaseAuthenticate.php">
     <PossiblyInvalidArrayOffset occurrences="1">
       <code>$hidden[$key]</code>
@@ -773,79 +773,31 @@
       <code>$data</code>
       <code>$data</code>
     </PossiblyNullArgument>
-    <PossiblyNullArrayAccess occurrences="16">
-      <code>$data['type']</code>
-      <code>$data['type']</code>
-      <code>$data['length']</code>
-      <code>$data['length']</code>
-      <code>$data['type']</code>
-      <code>$data['length']</code>
-      <code>$data['precision']</code>
-      <code>$data['type']</code>
-      <code>$data['autoIncrement']</code>
+    <PossiblyNullArrayAccess occurrences="8">
       <code>$data['type']</code>
       <code>$data['columns']</code>
       <code>$data['type']</code>
+      <code>$data['type']</code>
       <code>$constraint['type']</code>
       <code>$constraint['type']</code>
       <code>$data['type']</code>
       <code>$data['type']</code>
     </PossiblyNullArrayAccess>
-    <PossiblyNullArrayOffset occurrences="1">
-      <code>$typeMap</code>
-    </PossiblyNullArrayOffset>
   </file>
   <file src="src/Database/Schema/PostgresSchema.php">
     <PossiblyInvalidArrayOffset occurrences="1">
       <code>$index['columns'][]</code>
     </PossiblyInvalidArrayOffset>
-    <PossiblyNullArgument occurrences="1">
-      <code>$data</code>
-    </PossiblyNullArgument>
-    <PossiblyNullArrayAccess occurrences="16">
-      <code>$data['type']</code>
-      <code>$data['type']</code>
-      <code>$data['autoIncrement']</code>
-      <code>$data['null']</code>
-      <code>$data['default']</code>
-      <code>$data['type']</code>
-      <code>$data['length']</code>
-      <code>$data['type']</code>
-      <code>$data['length']</code>
-      <code>$data['length']</code>
-      <code>$data['precision']</code>
+    <PossiblyNullArrayAccess occurrences="3">
       <code>$constraint['type']</code>
       <code>$constraint['type']</code>
       <code>$data['columns']</code>
-      <code>$data['type']</code>
-      <code>$data['type']</code>
     </PossiblyNullArrayAccess>
-    <PossiblyNullArrayOffset occurrences="1">
-      <code>$typeMap</code>
-    </PossiblyNullArrayOffset>
   </file>
   <file src="src/Database/Schema/SqliteSchema.php">
-    <PossiblyNullArrayAccess occurrences="16">
-      <code>$data['type']</code>
-      <code>$data['length']</code>
-      <code>$data['type']</code>
-      <code>$data['length']</code>
-      <code>$data['length']</code>
-      <code>$data['precision']</code>
-      <code>$data['type']</code>
-      <code>$data['type']</code>
-      <code>$data['columns']</code>
+    <PossiblyNullArrayAccess occurrences="1">
       <code>$schema-&gt;getColumn($data['columns'][0])['type']</code>
-      <code>$data['type']</code>
-      <code>$data['references']</code>
-      <code>$data['update']</code>
-      <code>$data['delete']</code>
-      <code>$data['columns']</code>
-      <code>$data['columns']</code>
     </PossiblyNullArrayAccess>
-    <PossiblyNullArrayOffset occurrences="1">
-      <code>$typeMap</code>
-    </PossiblyNullArrayOffset>
     <PossiblyNullOperand occurrences="1">
       <code>$schema-&gt;getColumn($existingColumn)</code>
     </PossiblyNullOperand>
@@ -854,32 +806,12 @@
     </PropertyNotSetInConstructor>
   </file>
   <file src="src/Database/Schema/SqlserverSchema.php">
-    <PossiblyNullArgument occurrences="1">
-      <code>$data</code>
-    </PossiblyNullArgument>
-    <PossiblyNullArrayAccess occurrences="18">
-      <code>$data['type']</code>
-      <code>$data['type']</code>
-      <code>$data['autoIncrement']</code>
-      <code>$data['null']</code>
-      <code>$data['default']</code>
-      <code>$data['type']</code>
-      <code>$data['length']</code>
-      <code>$data['type']</code>
-      <code>$data['type']</code>
-      <code>$data['length']</code>
-      <code>$data['length']</code>
-      <code>$data['precision']</code>
+    <PossiblyNullArrayAccess occurrences="4">
       <code>$constraint['type']</code>
       <code>$constraint['type']</code>
       <code>$data['columns']</code>
-      <code>$data['type']</code>
-      <code>$data['type']</code>
       <code>$column['type']</code>
     </PossiblyNullArrayAccess>
-    <PossiblyNullArrayOffset occurrences="1">
-      <code>$typeMap</code>
-    </PossiblyNullArrayOffset>
     <PossiblyUndefinedArrayOffset occurrences="2">
       <code>$row['default']</code>
       <code>$row['default']</code>
@@ -1010,9 +942,8 @@
       <code>$type</code>
       <code>$type</code>
     </PossiblyInvalidArgument>
-    <PossiblyInvalidArrayAccess occurrences="2">
+    <PossiblyInvalidArrayAccess occurrences="1">
       <code>$result[$position]</code>
-      <code>$row[$column]</code>
     </PossiblyInvalidArrayAccess>
     <PossiblyNullPropertyFetch occurrences="1">
       <code>$this-&gt;_statement-&gt;queryString</code>
@@ -1143,11 +1074,6 @@
       <code>$end</code>
     </PossiblyNullOperand>
   </file>
-  <file src="src/Event/Decorator/SubjectFilterDecorator.php">
-    <PossiblyInvalidArgument occurrences="1">
-      <code>$this-&gt;_options['allowedSubject']</code>
-    </PossiblyInvalidArgument>
-  </file>
   <file src="src/Event/Event.php">
     <ImplementedReturnTypeMismatch occurrences="1">
       <code>object|null</code>
@@ -1199,15 +1125,6 @@
       <code>$nc</code>
     </PossiblyNullOperand>
   </file>
-  <file src="src/Http/Client/Auth/Oauth.php">
-    <PossiblyInvalidArgument occurrences="2">
-      <code>$credentials['privateKey']</code>
-      <code>$credentials['privateKeyPassphrase']</code>
-    </PossiblyInvalidArgument>
-    <TypeDoesNotContainType occurrences="1">
-      <code>is_resource($credentials['privateKeyPassphrase'])</code>
-    </TypeDoesNotContainType>
-  </file>
   <file src="src/Http/Client/FormData.php">
     <MissingConstructor occurrences="1">
       <code>$_boundary</code>
@@ -1335,9 +1252,6 @@
       <code>$data['secure']</code>
       <code>$data['httponly']</code>
     </PossiblyInvalidArgument>
-    <PossiblyUndefinedArrayOffset occurrences="1">
-      <code>$data['expires']</code>
-    </PossiblyUndefinedArrayOffset>
   </file>
   <file src="src/Http/Runner.php">
     <MissingConstructor occurrences="1">
@@ -1505,6 +1419,11 @@
       <code>static::$niceFormat</code>
     </PossiblyInvalidArgument>
   </file>
+  <file src="src/I18n/Translator.php">
+    <PossiblyInvalidArrayOffset occurrences="1">
+      <code>$message['_context']</code>
+    </PossiblyInvalidArrayOffset>
+  </file>
   <file src="src/I18n/TranslatorRegistry.php">
     <ImplementedReturnTypeMismatch occurrences="1">
       <code>\Aura\Intl\TranslatorInterface|null</code>
@@ -1549,11 +1468,6 @@
       <code>$level</code>
     </MoreSpecificImplementedParamType>
   </file>
-  <file src="src/Log/Log.php">
-    <PossiblyFalseArgument occurrences="1">
-      <code>$level</code>
-    </PossiblyFalseArgument>
-  </file>
   <file src="src/Log/LogEngineRegistry.php">
     <MoreSpecificImplementedParamType occurrences="1">
       <code>$class</code>
@@ -1579,16 +1493,6 @@
       <code>$this-&gt;appCharset</code>
     </PossiblyNullArgument>
   </file>
-  <file src="src/Mailer/Transport/MailTransport.php">
-    <PossiblyNullArgument occurrences="1">
-      <code>$params</code>
-    </PossiblyNullArgument>
-  </file>
-  <file src="src/Mailer/TransportRegistry.php">
-    <MoreSpecificImplementedParamType occurrences="1">
-      <code>$class</code>
-    </MoreSpecificImplementedParamType>
-  </file>
   <file src="src/Network/Socket.php">
     <InvalidArgument occurrences="1">
       <code>[$this, '_connectionErrorHandler']</code>
@@ -1978,9 +1882,6 @@
     <PossiblyInvalidArgument occurrences="1">
       <code>$params</code>
     </PossiblyInvalidArgument>
-    <PossiblyInvalidArrayAccess occurrences="1">
-      <code>$params['path']</code>
-    </PossiblyInvalidArrayAccess>
     <PossiblyInvalidIterator occurrences="1">
       <code>$options['map']</code>
     </PossiblyInvalidIterator>
@@ -2001,9 +1902,6 @@
       <code>$e-&gt;getCode()</code>
       <code>$params</code>
     </PossiblyInvalidArgument>
-    <PossiblyInvalidArrayAccess occurrences="1">
-      <code>$options['_namePrefix']</code>
-    </PossiblyInvalidArrayAccess>
     <PossiblyNullOperand occurrences="1">
       <code>$frag</code>
     </PossiblyNullOperand>
@@ -2336,9 +2234,7 @@
     </RedundantCondition>
   </file>
   <file src="src/TestSuite/TestCase.php">
-    <PossiblyFalseArgument occurrences="3">
-      <code>$tag</code>
-      <code>$tag</code>
+    <PossiblyFalseArgument occurrences="1">
       <code>$tag</code>
     </PossiblyFalseArgument>
     <PossiblyInvalidArgument occurrences="2">
@@ -2576,10 +2472,9 @@
     <ImplementedReturnTypeMismatch occurrences="1">
       <code>string</code>
     </ImplementedReturnTypeMismatch>
-    <InvalidArgument occurrences="3">
+    <InvalidArgument occurrences="2">
       <code>$modelName</code>
       <code>$modelName</code>
-      <code>$options['disabled']</code>
     </InvalidArgument>
     <PossiblyNullArgument occurrences="3">
       <code>$url</code>
@@ -2672,9 +2567,7 @@
     </UninitializedProperty>
   </file>
   <file src="src/View/View.php">
-    <PossiblyNullPropertyAssignmentValue occurrences="4">
-      <code>$request ?: Router::getRequest(true)</code>
-      <code>$request ?: Router::getRequest(true)</code>
+    <PossiblyNullPropertyAssignmentValue occurrences="2">
       <code>$request ?: Router::getRequest(true)</code>
       <code>$defaultLayout</code>
     </PossiblyNullPropertyAssignmentValue>

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

@@ -309,6 +309,7 @@ class MysqlSchema extends BaseSchema
      */
     public function columnSql(TableSchema $schema, string $name): string
     {
+        /** @var array $data */
         $data = $schema->getColumn($name);
         $out = $this->_driver->quoteIdentifier($name);
         $nativeJson = $this->_driver->supportsNativeJson();

+ 2 - 0
src/Database/Schema/PostgresSchema.php

@@ -355,6 +355,7 @@ class PostgresSchema extends BaseSchema
      */
     public function columnSql(TableSchema $schema, string $name): string
     {
+        /** @var array $data */
         $data = $schema->getColumn($name);
         $out = $this->_driver->quoteIdentifier($name);
         $typeMap = [
@@ -506,6 +507,7 @@ class PostgresSchema extends BaseSchema
      */
     public function constraintSql(TableSchema $schema, string $name): string
     {
+        /** @var array $data */
         $data = $schema->getConstraint($name);
         $out = 'CONSTRAINT ' . $this->_driver->quoteIdentifier($name);
         if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY) {

+ 3 - 0
src/Database/Schema/SqliteSchema.php

@@ -286,6 +286,7 @@ class SqliteSchema extends BaseSchema
      */
     public function columnSql(TableSchema $schema, string $name): string
     {
+        /** @var array $data */
         $data = $schema->getColumn($name);
         $typeMap = [
             TableSchema::TYPE_BINARY_UUID => ' BINARY(16)',
@@ -393,6 +394,7 @@ class SqliteSchema extends BaseSchema
      */
     public function constraintSql(TableSchema $schema, string $name): string
     {
+        /** @var array $data */
         $data = $schema->getConstraint($name);
         if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY &&
             count($data['columns']) === 1 &&
@@ -460,6 +462,7 @@ class SqliteSchema extends BaseSchema
      */
     public function indexSql(TableSchema $schema, string $name): string
     {
+        /** @var array $data */
         $data = $schema->getIndex($name);
         $columns = array_map(
             [$this->_driver, 'quoteIdentifier'],

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

@@ -343,6 +343,7 @@ class SqlserverSchema extends BaseSchema
      */
     public function columnSql(TableSchema $schema, string $name): string
     {
+        /** @var array $data */
         $data = $schema->getColumn($name);
         $out = $this->_driver->quoteIdentifier($name);
         $typeMap = [
@@ -507,6 +508,7 @@ class SqlserverSchema extends BaseSchema
      */
     public function constraintSql(TableSchema $schema, string $name): string
     {
+        /** @var array $data */
         $data = $schema->getConstraint($name);
         $out = 'CONSTRAINT ' . $this->_driver->quoteIdentifier($name);
         if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY) {

+ 4 - 4
src/Database/Statement/StatementDecorator.php

@@ -338,12 +338,12 @@ class StatementDecorator implements StatementInterface, Countable, IteratorAggre
      */
     public function lastInsertId(?string $table = null, ?string $column = null)
     {
-        $row = null;
         if ($column && $this->columnCount()) {
             $row = $this->fetch(static::FETCH_TYPE_ASSOC);
-        }
-        if (isset($row[$column])) {
-            return $row[$column];
+
+            if ($row && isset($row[$column])) {
+                return $row[$column];
+            }
         }
 
         return $this->_driver->lastInsertId($table, $column);

+ 1 - 0
src/Event/EventManager.php

@@ -113,6 +113,7 @@ class EventManager implements EventManagerInterface
             return $this;
         }
 
+        /** @var array $options */
         $priority = $options['priority'] ?? static::$defaultPriority;
         $this->_listeners[$eventKey][$priority][] = [
             'callable' => $callable,

+ 1 - 1
src/Mailer/TransportRegistry.php

@@ -59,7 +59,7 @@ class TransportRegistry extends ObjectRegistry
      *
      * Part of the template method for Cake\Core\ObjectRegistry::load()
      *
-     * @param string|\Cake\Mailer\AbstractTransport $class The classname or object to make.
+     * @param string|object $class The classname or object to make.
      * @param string $alias The alias of the object.
      * @param array $config An array of settings to use for the cache engine.
      * @return \Cake\Mailer\AbstractTransport The constructed transport class.

+ 1 - 0
src/ORM/Marshaller.php

@@ -628,6 +628,7 @@ class Marshaller
      * @param array $options List of options.
      * @return \Cake\Datasource\EntityInterface[]
      * @see \Cake\ORM\Entity::$_accessible
+     * @psalm-suppress NullArrayOffset
      */
     public function mergeMany(iterable $entities, array $data, array $options = []): array
     {

+ 2 - 0
src/Routing/RouteBuilder.php

@@ -849,6 +849,7 @@ class RouteBuilder
      * @param callable|null $callback The callback to invoke that builds the prefixed routes.
      * @return void
      * @throws \InvalidArgumentException If a valid callback is not passed
+     * @psalm-suppress PossiblyInvalidArrayAccess
      */
     public function prefix(string $name, $params = [], ?callable $callback = null): void
     {
@@ -889,6 +890,7 @@ class RouteBuilder
      * @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 function plugin(string $name, $options = [], ?callable $callback = null): void
     {

+ 2 - 0
src/Routing/Router.php

@@ -841,6 +841,7 @@ class Router
      *   If you have no parameters, this argument can be a callable.
      * @param callable|null $callback The callback to invoke that builds the prefixed routes.
      * @return void
+     * @psalm-suppress PossiblyInvalidArrayAccess
      */
     public static function prefix(string $name, $params = [], ?callable $callback = null): void
     {
@@ -874,6 +875,7 @@ 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 = [], ?callable $callback = null): void
     {

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

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