aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-03-14 10:13:22 +0000
committerMario <mario@mariovavti.com>2024-03-14 10:13:22 +0000
commit55097c47c5534d4453f7494f8a1542f7beb4d588 (patch)
tree399f81bbd03fcb4bb713339d06512eee962ec8f6 /vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php
parent97b82fc77b424d051b2a472ab2318fd768151bdd (diff)
downloadvolse-hubzilla-55097c47c5534d4453f7494f8a1542f7beb4d588.tar.gz
volse-hubzilla-55097c47c5534d4453f7494f8a1542f7beb4d588.tar.bz2
volse-hubzilla-55097c47c5534d4453f7494f8a1542f7beb4d588.zip
Revert "composer update and use the fixed streams php-jcs library until the floats issue will be fixed upstream. see here for reference https://codeberg.org/streams/streams/issues/151"
This reverts commit 6bf61dfa6b585db01b607a79bd64ec9c583a9c10.
Diffstat (limited to 'vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php')
-rw-r--r--vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php57
1 files changed, 17 insertions, 40 deletions
diff --git a/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php b/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php
index 44c422252..f9be1be28 100644
--- a/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php
+++ b/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php
@@ -14,11 +14,9 @@ declare(strict_types=1);
namespace Ramsey\Collection\Tool;
-use Ramsey\Collection\Exception\InvalidPropertyOrMethod;
-use Ramsey\Collection\Exception\UnsupportedOperationException;
+use Ramsey\Collection\Exception\ValueExtractionException;
-use function is_array;
-use function is_object;
+use function get_class;
use function method_exists;
use function property_exists;
use function sprintf;
@@ -29,53 +27,32 @@ use function sprintf;
trait ValueExtractorTrait
{
/**
- * Extracts the value of the given property, method, or array key from the
- * element.
+ * Extracts the value of the given property or method from the object.
*
- * If `$propertyOrMethod` is `null`, we return the element as-is.
- *
- * @param mixed $element The element to extract the value from.
- * @param string | null $propertyOrMethod The property or method for which the
+ * @param mixed $object The object to extract the value from.
+ * @param string $propertyOrMethod The property or method for which the
* value should be extracted.
*
- * @return mixed the value extracted from the specified property, method,
- * or array key, or the element itself.
+ * @return mixed the value extracted from the specified property or method.
*
- * @throws InvalidPropertyOrMethod
- * @throws UnsupportedOperationException
+ * @throws ValueExtractionException if the method or property is not defined.
*/
- protected function extractValue(mixed $element, ?string $propertyOrMethod): mixed
+ protected function extractValue($object, string $propertyOrMethod)
{
- if ($propertyOrMethod === null) {
- return $element;
- }
-
- if (!is_object($element) && !is_array($element)) {
- throw new UnsupportedOperationException(sprintf(
- 'The collection type "%s" does not support the $propertyOrMethod parameter',
- $this->getType(),
- ));
- }
-
- if (is_array($element)) {
- return $element[$propertyOrMethod] ?? throw new InvalidPropertyOrMethod(sprintf(
- 'Key or index "%s" not found in collection elements',
- $propertyOrMethod,
- ));
+ if (!is_object($object)) {
+ throw new ValueExtractionException('Unable to extract a value from a non-object');
}
- if (property_exists($element, $propertyOrMethod)) {
- return $element->$propertyOrMethod;
+ if (property_exists($object, $propertyOrMethod)) {
+ return $object->$propertyOrMethod;
}
- if (method_exists($element, $propertyOrMethod)) {
- return $element->{$propertyOrMethod}();
+ if (method_exists($object, $propertyOrMethod)) {
+ return $object->{$propertyOrMethod}();
}
- throw new InvalidPropertyOrMethod(sprintf(
- 'Method or property "%s" not defined in %s',
- $propertyOrMethod,
- $element::class,
- ));
+ throw new ValueExtractionException(
+ sprintf('Method or property "%s" not defined in %s', $propertyOrMethod, get_class($object))
+ );
}
}