Browse Source

Backport 4.next changes to 3.next

mscherer 5 years ago
parent
commit
409fa5a241

+ 7 - 0
src/Database/Expression/TupleComparison.php

@@ -24,6 +24,13 @@ use Cake\Database\ValueBinder;
 class TupleComparison extends Comparison
 {
     /**
+     * The type to be used for casting the value to a database representation
+     *
+     * @var array
+     */
+    protected $_type;
+
+    /**
      * Constructor
      *
      * @param string|array|\Cake\Database\ExpressionInterface $fields the fields to use to form a tuple

+ 2 - 2
src/I18n/Time.php

@@ -168,11 +168,11 @@ class Time extends MutableDateTime implements JsonSerializable
      * Returns the quarter
      *
      * @param bool $range Range.
-     * @return int|array 1, 2, 3, or 4 quarter of year, or array if $range true
+     * @return string[]|int 1, 2, 3, or 4 quarter of year, or array if $range true
      */
     public function toQuarter($range = false)
     {
-        $quarter = (int)ceil($this->format('m') / 3);
+        $quarter = (int)ceil((int)$this->format('m') / 3);
         if ($range === false) {
             return $quarter;
         }

+ 4 - 2
src/Mailer/TransportRegistry.php

@@ -58,7 +58,7 @@ class TransportRegistry extends ObjectRegistry
      * Part of the template method for Cake\Core\ObjectRegistry::load()
      *
      * @param string $class The classname that is missing.
-     * @param string $plugin The plugin the cache is missing in.
+     * @param string|null $plugin The plugin the cache is missing in.
      * @return void
      * @throws \BadMethodCallException
      */
@@ -103,10 +103,12 @@ class TransportRegistry extends ObjectRegistry
      * Remove a single adapter from the registry.
      *
      * @param string $name The adapter name.
-     * @return void
+     * @return $this
      */
     public function unload($name)
     {
         unset($this->_loaded[$name]);
+
+        return $this;
     }
 }

+ 1 - 1
src/ORM/AssociationsNormalizerTrait.php

@@ -24,7 +24,7 @@ trait AssociationsNormalizerTrait
      * Returns an array out of the original passed associations list where dot notation
      * is transformed into nested arrays so that they can be parsed by other routines
      *
-     * @param array $associations The array of included associations.
+     * @param array|string $associations The array of included associations.
      * @return array An array having dot notation transformed into nested arrays
      */
     protected function _normalizeAssociations($associations)

+ 2 - 2
src/ORM/Behavior/TimestampBehavior.php

@@ -86,7 +86,7 @@ class TimestampBehavior extends Behavior
      * @param \Cake\Event\Event $event Event instance.
      * @param \Cake\Datasource\EntityInterface $entity Entity instance.
      * @throws \UnexpectedValueException if a field's when value is misdefined
-     * @return bool Returns true irrespective of the behavior logic, the save will not be prevented.
+     * @return true Returns true irrespective of the behavior logic, the save will not be prevented.
      * @throws \UnexpectedValueException When the value for an event is not 'always', 'new' or 'existing'
      */
     public function handleEvent(Event $event, EntityInterface $entity)
@@ -174,7 +174,7 @@ class TimestampBehavior extends Behavior
         $refresh = $this->_config['refreshTimestamp'];
 
         foreach ($events[$eventName] as $field => $when) {
-            if (in_array($when, ['always', 'existing'])) {
+            if (in_array($when, ['always', 'existing'], true)) {
                 $return = true;
                 $entity->setDirty($field, false);
                 $this->_updateField($entity, $field, $refresh);

+ 2 - 2
src/ORM/Behavior/TreeBehavior.php

@@ -876,7 +876,7 @@ class TreeBehavior extends Behavior
             ->orderDesc($rightField)
             ->first();
 
-        if (empty($edge->{$field})) {
+        if ($edge === null || empty($edge[$field])) {
             return 0;
         }
 
@@ -986,7 +986,7 @@ class TreeBehavior extends Behavior
      * Returns the depth level of a node in the tree.
      *
      * @param int|string|\Cake\Datasource\EntityInterface $entity The entity or primary key get the level of.
-     * @return int|bool Integer of the level or false if the node does not exist.
+     * @return int|false Integer of the level or false if the node does not exist.
      */
     public function getLevel($entity)
     {

+ 3 - 3
src/Utility/Xml.php

@@ -95,7 +95,7 @@ class Xml
      *
      * If using array as input, you can pass `options` from Xml::fromArray.
      *
-     * @param string|array $input XML string, a path to a file, a URL or an array
+     * @param string|array|object $input XML string, a path to a file, a URL or an array
      * @param array $options The options to use
      * @return \SimpleXMLElement|\DOMDocument SimpleXMLElement or DOMDocument
      * @throws \Cake\Utility\Exception\XmlException
@@ -246,8 +246,8 @@ class Xml
      *
      * `<root><tag id="1" value="defect">description</tag></root>`
      *
-     * @param array|\Cake\Collection\Collection $input Array with data or a collection instance.
-     * @param string|array $options The options to use or a string to use as format.
+     * @param array|object $input Array with data or a collection instance.
+     * @param array $options The options to use.
      * @return \SimpleXMLElement|\DOMDocument SimpleXMLElement or DOMDocument
      * @throws \Cake\Utility\Exception\XmlException
      */

+ 2 - 2
src/Validation/ValidationRule.php

@@ -104,7 +104,7 @@ class ValidationRule
      *   new record
      * - data: The full data that was passed to the validation process
      * - field: The name of the field that is being processed
-     * @return bool|string
+     * @return bool|string|array
      * @throws \InvalidArgumentException when the supplied rule is not a valid
      * callable for the configured scope
      */
@@ -192,7 +192,7 @@ class ValidationRule
                 $this->_pass = array_slice($value, 1);
                 $value = array_shift($value);
             }
-            if (in_array($key, ['rule', 'on', 'message', 'last', 'provider', 'pass'])) {
+            if (in_array($key, ['rule', 'on', 'message', 'last', 'provider', 'pass'], true)) {
                 $this->{"_$key"} = $value;
             }
         }

+ 2 - 0
src/Validation/ValidationSet.php

@@ -130,6 +130,8 @@ class ValidationSet implements ArrayAccess, IteratorAggregate, Countable
         if (!empty($this->_rules[$name])) {
             return $this->_rules[$name];
         }
+
+        return null;
     }
 
     /**

+ 1 - 1
src/Validation/ValidatorAwareTrait.php

@@ -207,7 +207,7 @@ trait ValidatorAwareTrait
      */
     public function setValidator($name, Validator $validator)
     {
-        $validator->setProvider(self::VALIDATOR_PROVIDER_NAME, $this);
+        $validator->setProvider(static::VALIDATOR_PROVIDER_NAME, $this);
         $this->_validators[$name] = $validator;
 
         return $this;

+ 26 - 0
src/View/Helper/TextHelper.php

@@ -401,6 +401,32 @@ class TextHelper extends Helper
     }
 
     /**
+     * Returns a string with all spaces converted to dashes (by default),
+     * characters transliterated to ASCII characters, and non word characters removed.
+     *
+     * ### Options:
+     *
+     * - `replacement`: Replacement string. Default '-'.
+     * - `transliteratorId`: A valid transliterator id string.
+     *   If `null` (default) the transliterator (identifier) set via
+     *   `Text::setTransliteratorId()` or `Text::setTransliterator()` will be used.
+     *   If `false` no transliteration will be done, only non words will be removed.
+     * - `preserve`: Specific non-word character to preserve. Default `null`.
+     *   For e.g. this option can be set to '.' to generate clean file names.
+     *
+     * @param string $string the string you want to slug
+     * @param array|string $options If string it will be use as replacement character
+     *   or an array of options.
+     * @return string
+     * @see \Cake\Utility\Text::setTransliterator()
+     * @see \Cake\Utility\Text::setTransliteratorId()
+     */
+    public function slug($string, $options = [])
+    {
+        return $this->_engine->slug($string, $options);
+    }
+
+    /**
      * Event listeners.
      *
      * @return array

+ 2 - 2
src/View/ViewBlock.php

@@ -216,9 +216,9 @@ class ViewBlock
     }
 
     /**
-     * Get the names of the unclosed/active blocks.
+     * Get the unclosed/active blocks. Key is name, value is mode.
      *
-     * @return array An array of unclosed blocks.
+     * @return string[] An array of unclosed blocks.
      */
     public function unclosed()
     {

+ 1 - 1
src/View/Widget/WidgetInterface.php

@@ -35,7 +35,7 @@ interface WidgetInterface
      * this widget. Fields are in the form of Model[field][suffix]
      *
      * @param array $data The data to render.
-     * @return array Array of fields to secure.
+     * @return string[] Array of fields to secure.
      */
     public function secureFields(array $data);
 }

+ 32 - 0
tests/TestCase/View/Helper/TextHelperTest.php

@@ -630,4 +630,36 @@ TEXT;
         $result = $this->Text->autoParagraph($text);
         $this->assertTextEquals($expected, $result);
     }
+
+    /**
+     * testSlug method
+     *
+     * @param string $string String
+     * @param array $options Options
+     * @param String $expected Expected string
+     * @return void
+     * @dataProvider slugInputProvider
+     */
+    public function testSlug($string, $options, $expected)
+    {
+        $result = $this->Text->slug($string, $options);
+        $this->assertSame($expected, $result);
+    }
+
+    /**
+     * @return array
+     */
+    public function slugInputProvider()
+    {
+        return [
+            [
+                'Foo Bar: Not just for breakfast any-more', [],
+                'Foo-Bar-Not-just-for-breakfast-any-more',
+            ],
+            [
+                'Foo Bar: Not just for breakfast any-more', ['replacement' => false],
+                'FooBarNotjustforbreakfastanymore',
+            ],
+        ];
+    }
 }