← All changes
|
includes/sdk/google/ramsey/collection/src/Tool/ValueToStringTrait.php
+7
-12
1.2.2
→
1.4.1
View file →
| @@ -9,12 +9,12 @@ | ||
| 9 | 9 | * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> |
| 10 | 10 | * @license http://opensource.org/licenses/MIT MIT |
| 11 | 11 | */ |
| 12 | 12 | declare (strict_types=1); |
| 13 | -namespace Dudlewebs\WPMCS\Ramsey\Collection\Tool; | |
| 13 | +namespace Dudlewebs\WPMCS\GCP\Ramsey\Collection\Tool; | |
| 14 | 14 | |
| 15 | 15 | use DateTimeInterface; |
| 16 | -use function get_class; | |
| 16 | +use function assert; | |
| 17 | 17 | use function get_resource_type; |
| 18 | 18 | use function is_array; |
| 19 | 19 | use function is_bool; |
| 20 | 20 | use function is_callable; |
| @@ -20,9 +20,8 @@ | ||
| 20 | 20 | use function is_callable; |
| 21 | 21 | use function is_object; |
| 22 | 22 | use function is_resource; |
| 23 | 23 | use function is_scalar; |
| 24 | -use function var_export; | |
| 25 | 24 | /** |
| 26 | 25 | * Provides functionality to express a value as string |
| 27 | 26 | */ |
| 28 | 27 | trait ValueToStringTrait |
| @@ -41,10 +40,9 @@ | ||
| 41 | 40 | * - anonymous function: same as object |
| 42 | 41 | * |
| 43 | 42 | * @param mixed $value the value to return as a string. |
| 44 | 43 | */ |
| 45 | - // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint | |
| 46 | - protected function toolValueToString($value): string | |
| 44 | + protected function toolValueToString(mixed $value) : string | |
| 47 | 45 | { |
| 48 | 46 | // null |
| 49 | 47 | if ($value === null) { |
| 50 | 48 | return 'NULL'; |
| @@ -64,16 +62,14 @@ | ||
| 64 | 62 | // resource |
| 65 | 63 | if (is_resource($value)) { |
| 66 | 64 | return '(' . get_resource_type($value) . ' resource #' . (int) $value . ')'; |
| 67 | 65 | } |
| 68 | - // If we don't know what it is, use var_export(). | |
| 69 | - if (!is_object($value)) { | |
| 70 | - return '(' . var_export($value, \true) . ')'; | |
| 71 | - } | |
| 72 | 66 | // From here, $value should be an object. |
| 67 | + assert(is_object($value)); | |
| 73 | 68 | // __toString() is implemented |
| 74 | 69 | if (is_callable([$value, '__toString'])) { |
| 75 | - return (string) $value->__toString(); | |
| 70 | + /** @var string */ | |
| 71 | + return $value->__toString(); | |
| 76 | 72 | } |
| 77 | 73 | // object of type \DateTime |
| 78 | 74 | if ($value instanceof DateTimeInterface) { |
| 79 | 75 | return $value->format('c'); |
| @@ -78,8 +74,7 @@ | ||
| 78 | 74 | if ($value instanceof DateTimeInterface) { |
| 79 | 75 | return $value->format('c'); |
| 80 | 76 | } |
| 81 | 77 | // unknown type |
| 82 | - // phpcs:ignore SlevomatCodingStandard.Classes.ModernClassNameReference.ClassNameReferencedViaFunctionCall | |
| 83 | - return '(' . get_class($value) . ' Object)'; | |
| 78 | + return '(' . $value::class . ' Object)'; | |
| 84 | 79 | } |
| 85 | 80 | } |