mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-07 12:34:39 +02:00
remove deprecation of BaseCollection::map(), check return type of BaseCollection::map()
This commit is contained in:
parent
a50383836d
commit
268d564930
4 changed files with 50 additions and 36 deletions
|
@ -83,16 +83,12 @@ class BaseCollection extends \ArrayIterator
|
|||
/**
|
||||
* Apply a callback function on all elements in the collection and returns a new collection with the updated elements
|
||||
*
|
||||
* @deprecated 2025.05 Use `array_map()` instead
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return BaseCollection
|
||||
* @see array_map()
|
||||
*/
|
||||
public function map(callable $callback): BaseCollection
|
||||
{
|
||||
@trigger_error('`' . __METHOD__ . '()` is deprecated since 2025.05 and will be removed after 5 months, use `array_map()` instead.', E_USER_DEPRECATED);
|
||||
|
||||
$class = get_class($this);
|
||||
|
||||
return new $class(array_map($callback, $this->getArrayCopy()), $this->getTotalCount());
|
||||
|
|
|
@ -19,33 +19,38 @@ class Notifications extends BaseCollection
|
|||
|
||||
public function setSeen(): Notifications
|
||||
{
|
||||
$class = get_class($this);
|
||||
$notifications = $this->map(function (NotificationEntity $notification) {
|
||||
$notification->setSeen();
|
||||
});
|
||||
|
||||
return new $class(
|
||||
array_map(
|
||||
function (NotificationEntity $notification) {
|
||||
$notification->setSeen();
|
||||
},
|
||||
$this->getArrayCopy()
|
||||
),
|
||||
$this->getTotalCount(),
|
||||
);
|
||||
if (!$notifications instanceof Notifications) {
|
||||
// Show the possible error explicitly
|
||||
throw new \Exception(sprintf(
|
||||
'BaseCollection::map() should return instance of %s, but returns %s instead.',
|
||||
Notifications::class,
|
||||
get_class($notifications),
|
||||
));
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
public function setDismissed(): Notifications
|
||||
{
|
||||
$class = get_class($this);
|
||||
$notifications = $this->map(function (NotificationEntity $notification) {
|
||||
$notification->setDismissed();
|
||||
});
|
||||
|
||||
return new $class(
|
||||
array_map(
|
||||
function (NotificationEntity $notification) {
|
||||
$notification->setDismissed();
|
||||
},
|
||||
$this->getArrayCopy(),
|
||||
),
|
||||
$this->getTotalCount(),
|
||||
);
|
||||
if (!$notifications instanceof Notifications) {
|
||||
// Show the possible error explicitly
|
||||
throw new \Exception(sprintf(
|
||||
'BaseCollection::map() should return instance of %s, but returns %s instead.',
|
||||
Notifications::class,
|
||||
get_class($notifications),
|
||||
));
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
public function countUnseen(): int
|
||||
|
|
|
@ -19,13 +19,19 @@ class Notifies extends BaseCollection
|
|||
|
||||
public function setSeen(): Notifies
|
||||
{
|
||||
$class = get_class($this);
|
||||
$notifies = $this->map(function (NotifyEntity $notify) {
|
||||
$notify->setSeen();
|
||||
});
|
||||
|
||||
return new $class(array_map(
|
||||
function (NotifyEntity $notify) {
|
||||
$notify->setSeen();
|
||||
},
|
||||
$this->getArrayCopy()), $this->getTotalCount(),
|
||||
);
|
||||
if (!$notifies instanceof Notifies) {
|
||||
// Show the possible error explicitly
|
||||
throw new \Exception(sprintf(
|
||||
'BaseCollection::map() should return instance of %s, but returns %s instead.',
|
||||
Notifies::class,
|
||||
get_class($notifies),
|
||||
));
|
||||
}
|
||||
|
||||
return $notifies;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,15 +19,22 @@ class ProfileFields extends BaseCollection
|
|||
|
||||
public function map(callable $callback): ProfileFields
|
||||
{
|
||||
$class = get_class($this);
|
||||
$profileFields = parent::map($callback);
|
||||
|
||||
return new $class(array_map($callback, $this->getArrayCopy()), $this->getTotalCount());
|
||||
if (!$profileFields instanceof ProfileFields) {
|
||||
// Show the possible error explicitly
|
||||
throw new \Exception(sprintf(
|
||||
'BaseCollection::map() should return instance of %s, but returns %s instead.',
|
||||
ProfileFields::class,
|
||||
get_class($profileFields),
|
||||
));
|
||||
}
|
||||
|
||||
return $profileFields;
|
||||
}
|
||||
|
||||
public function filter(?callable $callback = null, int $flag = 0): ProfileFields
|
||||
{
|
||||
$class = get_class($this);
|
||||
|
||||
return new $class(array_filter($this->getArrayCopy(), $callback, $flag));
|
||||
return new self(array_filter($this->getArrayCopy(), $callback, $flag));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue