Browse Source

Revert "StaticConfigTrait::getConfig($key) return type"

Mark Story 6 years ago
parent
commit
d9823df260

+ 1 - 1
src/Core/StaticConfigTrait.php

@@ -110,7 +110,7 @@ trait StaticConfigTrait
      * Reads existing configuration.
      *
      * @param string $key The name of the configuration.
-     * @return mixed Configuration data.
+     * @return array|null Array of configuration data.
      */
     public static function getConfig($key)
     {

+ 10 - 10
src/Utility/Hash.php

@@ -928,8 +928,8 @@ class Hash
      *
      * ### Sort directions
      *
-     * - `asc` or `\SORT_ASC` Sort ascending.
-     * - `desc` or `\SORT_DESC` Sort descending.
+     * - `asc` Sort ascending.
+     * - `desc` Sort descending.
      *
      * ### Sort types
      *
@@ -951,7 +951,7 @@ class Hash
      *
      * @param array $data An array of data to sort
      * @param string $path A Set-compatible path to the array value
-     * @param string|int $dir See directions above. Defaults to 'asc'.
+     * @param string $dir See directions above. Defaults to 'asc'.
      * @param array|string $type See direction types above. Defaults to 'regular'.
      * @return array Sorted array of data
      * @link https://book.cakephp.org/3.0/en/core-libraries/hash.html#Cake\Utility\Hash::sort
@@ -985,13 +985,7 @@ class Hash
         $keys = static::extract($result, '{n}.id');
         $values = static::extract($result, '{n}.value');
 
-        if (is_string($dir)) {
-            $dir = strtolower($dir);
-        }
-        if (!in_array($dir, [\SORT_ASC, \SORT_DESC], true)) {
-            $dir = ($dir === 'asc') ? \SORT_ASC : \SORT_DESC;
-        }
-
+        $dir = strtolower($dir);
         $ignoreCase = false;
 
         // $type can be overloaded for case insensitive sort
@@ -1001,6 +995,12 @@ class Hash
             $type = $type['type'];
         }
         $type = strtolower($type);
+
+        if ($dir === 'asc') {
+            $dir = \SORT_ASC;
+        } else {
+            $dir = \SORT_DESC;
+        }
         if ($type === 'numeric') {
             $type = \SORT_NUMERIC;
         } elseif ($type === 'string') {

+ 1 - 2
src/Utility/composer.json

@@ -30,8 +30,7 @@
     },
     "suggest": {
         "ext-intl": "To use Text::transliterate() or Text::slug()",
-        "lib-ICU": "To use Text::transliterate() or Text::slug()",
-        "ext-simplexml": "To use Xml::build(), Xml::loadHtml(), Xml::fromArray(), or Xml::toArray() with default options",
+        "lib-ICU": "To use Text::transliterate() or Text::slug()"
     },
     "autoload": {
         "psr-4": {

+ 0 - 24
tests/TestCase/Utility/HashTest.php

@@ -1849,30 +1849,6 @@ class HashTest extends TestCase
     }
 
     /**
-     * test sorting direction by constants value.
-     *
-     * @return void
-     */
-    public function testSortWithDirectionConst()
-    {
-        $data = [
-            ['class' => 510, 'test' => 2],
-            ['class' => 500, 'test' => 1],
-            ['class' => 600, 'test' => 2],
-            ['class' => 625, 'test' => 4],
-            ['class' => 605, 'test' => 3],
-        ];
-
-        $expected = Hash::sort($data, '{n}.test', 'asc');
-        $result = Hash::sort($data, '{n}.test', \SORT_ASC);
-        $this->assertSame($expected, $result);
-
-        $expected = Hash::sort($data, '{n}.test', 'desc');
-        $result = Hash::sort($data, '{n}.test', \SORT_DESC);
-        $this->assertSame($expected, $result);
-    }
-
-    /**
      * test sorting with string keys.
      *
      * @return void