Browse Source

Merge branch 'master' into 4.next

Mark Story 6 years ago
parent
commit
8d63f745db

+ 1 - 20
phpstan-baseline.neon

@@ -351,21 +351,11 @@ parameters:
 			path: src/I18n/Date.php
 
 		-
-			message: "#^Call to function is_subclass_of\\(\\) with class\\-string\\<static\\(Cake\\\\I18n\\\\Date\\)\\> and 'Cake\\\\\\\\Chronos\\\\\\\\Date' will always evaluate to false\\.$#"
-			count: 1
-			path: src/I18n/Date.php
-
-		-
 			message: "#^Unsafe usage of new static\\(\\)\\.$#"
 			count: 1
 			path: src/I18n/Date.php
 
 		-
-			message: "#^Result of \\|\\| is always true\\.$#"
-			count: 1
-			path: src/I18n/FrozenDate.php
-
-		-
 			message: "#^Unsafe usage of new static\\(\\)\\.$#"
 			count: 1
 			path: src/I18n/FrozenDate.php
@@ -376,11 +366,6 @@ parameters:
 			path: src/I18n/FrozenDate.php
 
 		-
-			message: "#^Call to function is_subclass_of\\(\\) with class\\-string\\<static\\(Cake\\\\I18n\\\\FrozenTime\\)\\> and 'Cake\\\\\\\\Chronos\\\\\\\\Date' will always evaluate to false\\.$#"
-			count: 1
-			path: src/I18n/FrozenTime.php
-
-		-
 			message: "#^Unsafe usage of new static\\(\\)\\.$#"
 			count: 1
 			path: src/I18n/FrozenTime.php
@@ -391,11 +376,6 @@ parameters:
 			path: src/I18n/FrozenTime.php
 
 		-
-			message: "#^Call to function is_subclass_of\\(\\) with class\\-string\\<static\\(Cake\\\\I18n\\\\Time\\)\\> and 'Cake\\\\\\\\Chronos\\\\\\\\Date' will always evaluate to false\\.$#"
-			count: 1
-			path: src/I18n/Time.php
-
-		-
 			message: "#^Unsafe usage of new static\\(\\)\\.$#"
 			count: 1
 			path: src/I18n/Time.php
@@ -604,3 +584,4 @@ parameters:
 			message: "#^Call to an undefined method DateTimeInterface\\:\\:setTimezone\\(\\)\\.$#"
 			count: 1
 			path: src/View/Helper/TimeHelper.php
+

+ 16 - 16
psalm.xml

@@ -9,34 +9,34 @@
     autoloader="tests/bootstrap.php"
 >
     <projectFiles>
-        <directory name="src" />
+        <directory name="src"/>
         <ignoreFiles>
-            <directory name="src/Filesystem" />
-            <directory name="src/Auth" />
-            <directory name="vendor" />
-            <file name="src/Controller/Component/AuthComponent.php" />
+            <directory name="src/Filesystem"/>
+            <directory name="src/Auth"/>
+            <directory name="vendor"/>
+            <file name="src/Controller/Component/AuthComponent.php"/>
         </ignoreFiles>
     </projectFiles>
 
     <issueHandlers>
-        <RedundantConditionGivenDocblockType errorLevel="suppress" />
-        <TypeCoercion errorLevel="suppress" />
-        <DocblockTypeContradiction errorLevel="suppress" />
-        <MissingClosureParamType errorLevel="suppress" />
-        <MissingClosureReturnType errorLevel="suppress" />
+        <RedundantConditionGivenDocblockType errorLevel="suppress"/>
+        <TypeCoercion errorLevel="suppress"/>
+        <DocblockTypeContradiction errorLevel="suppress"/>
+        <MissingClosureParamType errorLevel="suppress"/>
+        <MissingClosureReturnType errorLevel="suppress"/>
         <UndefinedClass>
             <errorLevel type="suppress">
-                <referencedClass name="Memcached" />
-                <referencedClass name="Redis" />
+                <referencedClass name="Memcached"/>
+                <referencedClass name="Redis"/>
             </errorLevel>
         </UndefinedClass>
         <UndefinedDocblockClass>
             <errorLevel type="suppress">
-                <referencedClass name="Memcached" />
-                <referencedClass name="Redis" />
+                <referencedClass name="Memcached"/>
+                <referencedClass name="Redis"/>
             </errorLevel>
         </UndefinedDocblockClass>
-        <PropertyNotSetInConstructor errorLevel="suppress" />
-        <UnresolvableInclude errorLevel="suppress" />
+        <PropertyNotSetInConstructor errorLevel="suppress"/>
+        <UnresolvableInclude errorLevel="suppress"/>
     </issueHandlers>
 </psalm>

+ 1 - 1
src/Database/Query.php

@@ -1751,7 +1751,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      * $expression = $query->newExpr('Table.column = Table2.column'); // Return a raw SQL expression
      * ```
      *
-     * @param mixed $rawExpression A string, array or anything you want wrapped in an expression object
+     * @param string|array|\Cake\Database\ExpressionInterface|null $rawExpression A string, array or anything you want wrapped in an expression object
      * @return \Cake\Database\Expression\QueryExpression
      */
     public function newExpr($rawExpression = null): QueryExpression

+ 4 - 4
src/Datasource/QueryInterface.php

@@ -34,7 +34,7 @@ interface QueryInterface
      * If `true` is passed in the second argument, any previous selections will
      * be overwritten with the list passed in the first argument.
      *
-     * @param mixed $fields Fields to be added to the list.
+     * @param array|string|callable|\Cake\Database\ExpressionInterface|\Cake\ORM\Table|\Cake\ORM\Association $fields Fields.
      * @param bool $overwrite whether to reset fields with passed list or not
      * @return $this
      */
@@ -170,7 +170,7 @@ interface QueryInterface
      * $query->limit($query->newExpr()->add(['1 + 1'])); // LIMIT (1 + 1)
      * ```
      *
-     * @param int|mixed $num number of records to be returned
+     * @param int|\Cake\Database\ExpressionInterface|null $num number of records to be returned
      * @return $this
      */
     public function limit($num);
@@ -190,7 +190,7 @@ interface QueryInterface
      *  $query->offset($query->newExpr()->add(['1 + 1'])); // OFFSET (1 + 1)
      * ```
      *
-     * @param mixed $num number of records to be skipped
+     * @param int|\Cake\Database\ExpressionInterface|null $num number of records to be skipped
      * @return $this
      */
     public function offset($num);
@@ -238,7 +238,7 @@ interface QueryInterface
      * If you need to set complex expressions as order conditions, you
      * should use `orderAsc()` or `orderDesc()`.
      *
-     * @param array|string $fields fields to be added to the list
+     * @param array|\Cake\Database\ExpressionInterface|\Closure|string $fields fields to be added to the list
      * @param bool $overwrite whether to reset order with field list or not
      * @return $this
      */

+ 0 - 15
src/I18n/DateFormatTrait.php

@@ -16,9 +16,7 @@ declare(strict_types=1);
  */
 namespace Cake\I18n;
 
-use Cake\Chronos\Date as ChronosDate;
 use Cake\Chronos\DifferenceFormatterInterface;
-use Cake\Chronos\MutableDate;
 use Closure;
 use DateTime;
 use DateTimeZone;
@@ -59,13 +57,6 @@ trait DateFormatTrait
     protected static $_formatters = [];
 
     /**
-     * Caches whether or not this class is a subclass of a Date or MutableDate
-     *
-     * @var bool
-     */
-    protected static $_isDateInstance;
-
-    /**
      * Gets the default locale.
      *
      * @return string|null The default locale string to be used or null.
@@ -362,12 +353,6 @@ trait DateFormatTrait
             }
         }
 
-        if (static::$_isDateInstance === null) {
-            static::$_isDateInstance =
-                is_subclass_of(static::class, ChronosDate::class) ||
-                is_subclass_of(static::class, MutableDate::class);
-        }
-
         $formatter = datefmt_create(
             (string)static::$defaultLocale,
             $dateFormat ?? 0,

+ 1 - 1
src/Mailer/Message.php

@@ -1134,7 +1134,7 @@ class Message implements JsonSerializable, Serializable
      * ```
      *
      * The `contentId` key allows you to specify an inline attachment. In your email text, you
-     * can use `<img src="cid:abc123" />` to display the image inline.
+     * can use `<img src="cid:abc123"/>` to display the image inline.
      *
      * The `contentDisposition` key allows you to disable the `Content-Disposition` header, this can improve
      * attachment compatibility with outlook email clients.

+ 4 - 1
src/Validation/Validation.php

@@ -526,7 +526,7 @@ class Validation
      *
      * @param mixed $check Value to check
      * @param string|array $dateFormat Format of the date part. See Validation::date() for more information.
-     *   Or `Validation::DATETIME_ISO8601` to valid an ISO8601 datetime value.
+     *   Or `Validation::DATETIME_ISO8601` to validate an ISO8601 datetime value.
      * @param string|null $regex Regex for the date part. If a custom regular expression is used
      *   this is the only validation that will occur.
      * @return bool True if the value is valid, false otherwise
@@ -541,6 +541,9 @@ class Validation
         if (is_object($check)) {
             return false;
         }
+        if (is_array($dateFormat) && count($dateFormat) === 1) {
+            $dateFormat = reset($dateFormat);
+        }
         if ($dateFormat === static::DATETIME_ISO8601 && !static::iso8601($check)) {
             return false;
         }

+ 3 - 3
src/View/Helper/FormHelper.php

@@ -1537,8 +1537,8 @@ class FormHelper extends Helper
 
     /**
      * Missing method handler - implements various simple input types. Is used to create inputs
-     * of various types. e.g. `$this->Form->text();` will create `<input type="text" />` while
-     * `$this->Form->range();` will create `<input type="range" />`
+     * of various types. e.g. `$this->Form->text();` will create `<input type="text"/>` while
+     * `$this->Form->range();` will create `<input type="range"/>`
      *
      * ### Usage
      *
@@ -1548,7 +1548,7 @@ class FormHelper extends Helper
      *
      * Will make an input like:
      *
-     * `<input type="search" id="UserQuery" name="User[query]" value="test" />`
+     * `<input type="search" id="UserQuery" name="User[query]" value="test"/>`
      *
      * The first argument to an input type should always be the fieldname, in `Model.field` format.
      * The second argument should always be an array of attributes for the input.

+ 4 - 1
tests/TestCase/Validation/ValidatorTest.php

@@ -2489,11 +2489,14 @@ class ValidatorTest extends TestCase
      *
      * @return void
      */
-    public function testDateTime()
+    public function testDateTime(): void
     {
         $validator = new Validator();
         $this->assertProxyMethod($validator, 'dateTime', ['ymd'], [['ymd']], 'datetime');
         $this->assertNotEmpty($validator->validate(['username' => 'not a date']));
+
+        $validator = (new Validator())->dateTime('thedate', ['iso8601']);
+        $this->assertEmpty($validator->validate(['thedate' => '2020-05-01T12:34:56Z']));
     }
 
     /**