Fix 5 PHPStan errors
This commit is contained in:
parent
35d95b991b
commit
1820bfc2b3
4 changed files with 47 additions and 26 deletions
|
@ -474,7 +474,7 @@ class Database
|
||||||
*
|
*
|
||||||
* @param string $sql SQL statement
|
* @param string $sql SQL statement
|
||||||
*
|
*
|
||||||
* @return bool|object statement object or result object
|
* @return bool|mysqli_result|mysqli_stmt|object|PDOStatement statement object or result object
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function p(string $sql)
|
public function p(string $sql)
|
||||||
|
|
|
@ -8,36 +8,50 @@
|
||||||
namespace Friendica\Navigation\Notifications\Collection;
|
namespace Friendica\Navigation\Notifications\Collection;
|
||||||
|
|
||||||
use Friendica\BaseCollection;
|
use Friendica\BaseCollection;
|
||||||
use Friendica\Navigation\Notifications\Entity;
|
use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity;
|
||||||
|
|
||||||
class Notifications extends BaseCollection
|
class Notifications extends BaseCollection
|
||||||
{
|
{
|
||||||
/**
|
public function current(): NotificationEntity
|
||||||
* @return Entity\Notification
|
|
||||||
*/
|
|
||||||
public function current(): Entity\Notification
|
|
||||||
{
|
{
|
||||||
return parent::current();
|
return parent::current();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSeen(): Notifications
|
public function setSeen(): Notifications
|
||||||
{
|
{
|
||||||
return $this->map(function (Entity\Notification $Notification) {
|
$class = get_class($this);
|
||||||
$Notification->setSeen();
|
|
||||||
});
|
return new $class(
|
||||||
|
array_map(
|
||||||
|
function (NotificationEntity $notification) {
|
||||||
|
$notification->setSeen();
|
||||||
|
},
|
||||||
|
$this->getArrayCopy()
|
||||||
|
),
|
||||||
|
$this->getTotalCount(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDismissed(): Notifications
|
public function setDismissed(): Notifications
|
||||||
{
|
{
|
||||||
return $this->map(function (Entity\Notification $Notification) {
|
$class = get_class($this);
|
||||||
$Notification->setDismissed();
|
|
||||||
});
|
return new $class(
|
||||||
|
array_map(
|
||||||
|
function (NotificationEntity $notification) {
|
||||||
|
$notification->setDismissed();
|
||||||
|
},
|
||||||
|
$this->getArrayCopy(),
|
||||||
|
),
|
||||||
|
$this->getTotalCount(),
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function countUnseen(): int
|
public function countUnseen(): int
|
||||||
{
|
{
|
||||||
return array_reduce($this->getArrayCopy(), function (int $carry, Entity\Notification $Notification) {
|
return array_reduce($this->getArrayCopy(), function (int $carry, NotificationEntity $notification) {
|
||||||
return $carry + ($Notification->seen ? 0 : 1);
|
return $carry + ($notification->seen ? 0 : 1);
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,22 +8,24 @@
|
||||||
namespace Friendica\Navigation\Notifications\Collection;
|
namespace Friendica\Navigation\Notifications\Collection;
|
||||||
|
|
||||||
use Friendica\BaseCollection;
|
use Friendica\BaseCollection;
|
||||||
use Friendica\Navigation\Notifications\Entity;
|
use Friendica\Navigation\Notifications\Entity\Notify as NotifyEntity;
|
||||||
|
|
||||||
class Notifies extends BaseCollection
|
class Notifies extends BaseCollection
|
||||||
{
|
{
|
||||||
/**
|
public function current(): NotifyEntity
|
||||||
* @return Entity\Notify
|
|
||||||
*/
|
|
||||||
public function current(): Entity\Notify
|
|
||||||
{
|
{
|
||||||
return parent::current();
|
return parent::current();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSeen(): Notifies
|
public function setSeen(): Notifies
|
||||||
{
|
{
|
||||||
return $this->map(function (Entity\Notify $Notify) {
|
$class = get_class($this);
|
||||||
$Notify->setSeen();
|
|
||||||
});
|
return new $class(array_map(
|
||||||
|
function (NotifyEntity $notify) {
|
||||||
|
$notify->setSeen();
|
||||||
|
},
|
||||||
|
$this->getArrayCopy()), $this->getTotalCount(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,12 +162,17 @@ class Notification extends BaseRepository
|
||||||
LIMIT 50
|
LIMIT 50
|
||||||
", ...$values);
|
", ...$values);
|
||||||
|
|
||||||
$Entities = new NotificationsCollection();
|
$entities = new NotificationsCollection();
|
||||||
foreach ($rows as $fields) {
|
|
||||||
$Entities[] = $this->factory->createFromTableRow($fields);
|
if (!is_iterable($rows)) {
|
||||||
|
return $entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $Entities;
|
foreach ($rows as $fields) {
|
||||||
|
$entities[] = $this->factory->createFromTableRow($fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function selectAllForUser(int $uid): NotificationsCollection
|
public function selectAllForUser(int $uid): NotificationsCollection
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue