[TOOLS] Continue raising PHPStan to level 6

This commit is contained in:
Hugo Sales 2022-10-19 22:39:17 +01:00
parent e6bb418fe6
commit c31f3d4997
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
25 changed files with 233 additions and 58 deletions

View File

@ -51,6 +51,8 @@ class Avatar extends Component
} }
/** /**
* @param SettingsTabsType $tabs
*
* @throws \App\Util\Exception\ClientException * @throws \App\Util\Exception\ClientException
*/ */
public function onPopulateSettingsTabs(Request $request, string $section, &$tabs): EventResult public function onPopulateSettingsTabs(Request $request, string $section, &$tabs): EventResult
@ -129,6 +131,8 @@ class Avatar extends Component
* *
* Returns the avatar file's hash, mimetype, title and path. * Returns the avatar file's hash, mimetype, title and path.
* Ensures exactly one cached value exists * Ensures exactly one cached value exists
*
* @return array{id: null|int, filename: null|string, title: string, mimetype: string, filepath?: string}
*/ */
public static function getAvatarFileInfo(int $actor_id, string $size = 'medium'): array public static function getAvatarFileInfo(int $actor_id, string $size = 'medium'): array
{ {

View File

@ -54,6 +54,7 @@ use Symfony\Component\HttpFoundation\Request;
*/ */
class Circle extends Component class Circle extends Component
{ {
/** @phpstan-use MetaCollectionTrait<Circle> */
use MetaCollectionTrait; use MetaCollectionTrait;
public const TAG_CIRCLE_REGEX = '/' . Nickname::BEFORE_MENTIONS . '@#([\pL\pN_\-\.]{1,64})/'; public const TAG_CIRCLE_REGEX = '/' . Nickname::BEFORE_MENTIONS . '@#([\pL\pN_\-\.]{1,64})/';
protected const SLUG = 'circle'; protected const SLUG = 'circle';
@ -107,6 +108,9 @@ class Circle extends Component
return Event::next; return Event::next;
} }
/**
* @param Actor[] $targets
*/
public function onPostingFillTargetChoices(Request $request, Actor $actor, array &$targets): EventResult public function onPostingFillTargetChoices(Request $request, Actor $actor, array &$targets): EventResult
{ {
$circles = $actor->getCircles(); $circles = $actor->getCircles();
@ -119,6 +123,9 @@ class Circle extends Component
// Meta Collection ------------------------------------------------------------------- // Meta Collection -------------------------------------------------------------------
/**
* @param array<string, mixed> $vars
*/
private function getActorIdFromVars(array $vars): int private function getActorIdFromVars(array $vars): int
{ {
$id = $vars['request']->get('id', null); $id = $vars['request']->get('id', null);
@ -130,7 +137,7 @@ class Circle extends Component
return $user->getId(); return $user->getId();
} }
public static function createCircle(Actor|int $tagger_id, string $tag): int public static function createCircle(Actor|int $tagger_id, string $tag): int|null
{ {
$tagger_id = \is_int($tagger_id) ? $tagger_id : $tagger_id->getId(); $tagger_id = \is_int($tagger_id) ? $tagger_id : $tagger_id->getId();
$circle = ActorCircle::create([ $circle = ActorCircle::create([
@ -146,7 +153,10 @@ class Circle extends Component
return $circle->getId(); return $circle->getId();
} }
protected function createCollection(Actor $owner, array $vars, string $name) /**
* @param array<string, mixed> $vars
*/
protected function createCollection(Actor $owner, array $vars, string $name): void
{ {
$this->createCircle($owner, $name); $this->createCircle($owner, $name);
DB::persist(ActorTag::create([ DB::persist(ActorTag::create([
@ -156,7 +166,12 @@ class Circle extends Component
])); ]));
} }
protected function removeItem(Actor $owner, array $vars, $items, array $collections) /**
* @param array<string, mixed> $vars
* @param array<int> $items
* @param array<mixed> $collections
*/
protected function removeItem(Actor $owner, array $vars, array $items, array $collections): bool
{ {
$tagger_id = $owner->getId(); $tagger_id = $owner->getId();
$tagged_id = $this->getActorIdFromVars($vars); $tagged_id = $this->getActorIdFromVars($vars);
@ -169,9 +184,15 @@ class Circle extends Component
DB::removeBy(ActorTag::class, ['tagger' => $tagger_id, 'tagged' => $tagged_id, 'tag' => $tag]); DB::removeBy(ActorTag::class, ['tagger' => $tagger_id, 'tagged' => $tagged_id, 'tag' => $tag]);
} }
Cache::delete(Actor::cacheKeys($tagger_id)['circles']); Cache::delete(Actor::cacheKeys($tagger_id)['circles']);
return true;
} }
protected function addItem(Actor $owner, array $vars, $items, array $collections) /**
* @param array<string, mixed> $vars
* @param array<int> $items
* @param array<mixed> $collections
*/
protected function addItem(Actor $owner, array $vars, array $items, array $collections): void
{ {
$tagger_id = $owner->getId(); $tagger_id = $owner->getId();
$tagged_id = $this->getActorIdFromVars($vars); $tagged_id = $this->getActorIdFromVars($vars);
@ -188,8 +209,10 @@ class Circle extends Component
/** /**
* @see MetaCollectionPlugin->shouldAddToRightPanel * @see MetaCollectionPlugin->shouldAddToRightPanel
*
* @param array<string, mixed> $vars
*/ */
protected function shouldAddToRightPanel(Actor $user, $vars, Request $request): bool protected function shouldAddToRightPanel(Actor $user, array $vars, Request $request): bool
{ {
return \in_array($vars['path'], ['actor_view_nickname', 'actor_view_id']); return \in_array($vars['path'], ['actor_view_nickname', 'actor_view_id']);
} }
@ -201,9 +224,11 @@ class Circle extends Component
* Differs from the overwritten method in MetaCollectionsTrait, since retrieved Collections come from the $owner * Differs from the overwritten method in MetaCollectionsTrait, since retrieved Collections come from the $owner
* itself, and from every Actor that is a part of its ActorCircle. * itself, and from every Actor that is a part of its ActorCircle.
* *
* @param Actor $owner the Actor, and by extension its own circle of Actors * @param Actor $owner the Actor, and by extension its own circle of Actors
* @param null|array $vars Page vars sent by AppendRightPanelBlock event * @param null|array<string, mixed> $vars Page vars sent by AppendRightPanelBlock event
* @param bool $ids_only true if only the Collections ids are to be returned * @param bool $ids_only true if only the Collections ids are to be returned
*
* @return Circle[]|int[]
*/ */
protected function getCollectionsBy(Actor $owner, ?array $vars = null, bool $ids_only = false): array protected function getCollectionsBy(Actor $owner, ?array $vars = null, bool $ids_only = false): array
{ {

View File

@ -38,6 +38,8 @@ class Circle extends CircleController
* *
* @throws \App\Util\Exception\ServerException * @throws \App\Util\Exception\ServerException
* @throws ClientException * @throws ClientException
*
* @return ControllerResultType
*/ */
public function circleById(int|ActorCircle $circle_id): array public function circleById(int|ActorCircle $circle_id): array
{ {
@ -57,11 +59,17 @@ class Circle extends CircleController
} }
} }
/**
* @return ControllerResultType
*/
public function circleByTaggerIdAndTag(int $tagger_id, string $tag): array public function circleByTaggerIdAndTag(int $tagger_id, string $tag): array
{ {
return $this->circleById(ActorCircle::getByPK(['tagger' => $tagger_id, 'tag' => $tag])); return $this->circleById(ActorCircle::getByPK(['tagger' => $tagger_id, 'tag' => $tag]));
} }
/**
* @return ControllerResultType
*/
public function circleByTaggerNicknameAndTag(string $tagger_nickname, string $tag): array public function circleByTaggerNicknameAndTag(string $tagger_nickname, string $tag): array
{ {
return $this->circleById(ActorCircle::getByPK(['tagger' => LocalUser::getByNickname($tagger_nickname)->getId(), 'tag' => $tag])); return $this->circleById(ActorCircle::getByPK(['tagger' => LocalUser::getByNickname($tagger_nickname)->getId(), 'tag' => $tag]));

View File

@ -31,16 +31,20 @@ use App\Entity\LocalUser;
use Component\Circle\Entity\ActorCircle; use Component\Circle\Entity\ActorCircle;
use Component\Collection\Util\Controller\MetaCollectionController; use Component\Collection\Util\Controller\MetaCollectionController;
/**
* @extends MetaCollectionController<Circles>
*/
class Circles extends MetaCollectionController class Circles extends MetaCollectionController
{ {
protected const SLUG = 'circle'; protected const SLUG = 'circle';
protected const PLURAL_SLUG = 'circles'; protected const PLURAL_SLUG = 'circles';
protected string $page_title = 'Actor circles'; protected string $page_title = 'Actor circles';
public function createCollection(int $owner_id, string $name) public function createCollection(int $owner_id, string $name): bool
{ {
return \Component\Circle\Circle::createCircle($owner_id, $name); return !\is_null(\Component\Circle\Circle::createCircle($owner_id, $name));
} }
public function getCollectionUrl(int $owner_id, ?string $owner_nickname, int $collection_id): string public function getCollectionUrl(int $owner_id, ?string $owner_nickname, int $collection_id): string
{ {
return Router::url( return Router::url(
@ -49,21 +53,26 @@ class Circles extends MetaCollectionController
); );
} }
public function getCollectionItems(int $owner_id, $collection_id): array /**
* @return Circles[]
*/
public function getCollectionItems(int $owner_id, int $collection_id): array
{ {
$notes = []; // TODO: Use Feed::query return []; // TODO
return [
'_template' => 'collection/notes.html.twig',
'notes' => $notes,
];
} }
/**
* @return Circles[]
*/
public function feedByCircleId(int $circle_id) public function feedByCircleId(int $circle_id)
{ {
// Owner id isn't used // Owner id isn't used
return $this->getCollectionItems(0, $circle_id); return $this->getCollectionItems(0, $circle_id);
} }
/**
* @return Circles[]
*/
public function feedByTaggerIdAndTag(int $tagger_id, string $tag) public function feedByTaggerIdAndTag(int $tagger_id, string $tag)
{ {
// Owner id isn't used // Owner id isn't used
@ -71,6 +80,9 @@ class Circles extends MetaCollectionController
return $this->getCollectionItems($tagger_id, $circle_id); return $this->getCollectionItems($tagger_id, $circle_id);
} }
/**
* @return Circles[]
*/
public function feedByTaggerNicknameAndTag(string $tagger_nickname, string $tag) public function feedByTaggerNicknameAndTag(string $tagger_nickname, string $tag)
{ {
$tagger_id = LocalUser::getByNickname($tagger_nickname)->getId(); $tagger_id = LocalUser::getByNickname($tagger_nickname)->getId();
@ -78,6 +90,9 @@ class Circles extends MetaCollectionController
return $this->getCollectionItems($tagger_id, $circle_id); return $this->getCollectionItems($tagger_id, $circle_id);
} }
/**
* @return ActorCircle[]
*/
public function getCollectionsByActorId(int $owner_id): array public function getCollectionsByActorId(int $owner_id): array
{ {
return DB::findBy(ActorCircle::class, ['tagger' => $owner_id], order_by: ['id' => 'desc']); return DB::findBy(ActorCircle::class, ['tagger' => $owner_id], order_by: ['id' => 'desc']);
@ -87,7 +102,7 @@ class Circles extends MetaCollectionController
return DB::findOneBy(ActorCircle::class, ['id' => $collection_id, 'actor_id' => $owner_id]); return DB::findOneBy(ActorCircle::class, ['id' => $collection_id, 'actor_id' => $owner_id]);
} }
public function setCollectionName(int $actor_id, string $actor_nickname, ActorCircle $collection, string $name) public function setCollectionName(int $actor_id, string $actor_nickname, ActorCircle $collection, string $name): void
{ {
foreach ($collection->getActorTags(db_reference: true) as $at) { foreach ($collection->getActorTags(db_reference: true) as $at) {
$at->setTag($name); $at->setTag($name);
@ -96,7 +111,7 @@ class Circles extends MetaCollectionController
Cache::delete(Actor::cacheKeys($actor_id)['circles']); Cache::delete(Actor::cacheKeys($actor_id)['circles']);
} }
public function removeCollection(int $actor_id, string $actor_nickname, ActorCircle $collection) public function removeCollection(int $actor_id, string $actor_nickname, ActorCircle $collection): void
{ {
foreach ($collection->getActorTags(db_reference: true) as $at) { foreach ($collection->getActorTags(db_reference: true) as $at) {
DB::remove($at); DB::remove($at);

View File

@ -25,6 +25,7 @@ use App\Core\Cache;
use App\Core\DB; use App\Core\DB;
use App\Core\Entity; use App\Core\Entity;
use App\Core\Router; use App\Core\Router;
use App\Entity\Actor;
use DateTimeInterface; use DateTimeInterface;
/** /**
@ -144,6 +145,9 @@ class ActorCircle extends Entity
return $this->tag; return $this->tag;
} }
/**
* @return ActorTag[]
*/
public function getActorTags(bool $db_reference = false): array public function getActorTags(bool $db_reference = false): array
{ {
$handle = fn () => DB::findBy('actor_tag', ['tagger' => $this->getTagger(), 'tag' => $this->getTag()]); $handle = fn () => DB::findBy('actor_tag', ['tagger' => $this->getTagger(), 'tag' => $this->getTag()]);
@ -156,7 +160,10 @@ class ActorCircle extends Entity
); );
} }
public function getTaggedActors() /**
* @return Actor[]
*/
public function getTaggedActors(): array
{ {
return Cache::get( return Cache::get(
"circle-{$this->getId()}-tagged-actors", "circle-{$this->getId()}-tagged-actors",
@ -170,6 +177,9 @@ class ActorCircle extends Entity
); );
} }
/**
* @return Actor[]
*/
public function getSubscribedActors(?int $offset = null, ?int $limit = null): array public function getSubscribedActors(?int $offset = null, ?int $limit = null): array
{ {
return Cache::get( return Cache::get(

View File

@ -7,14 +7,18 @@ namespace Component\Circle\Form;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Util\Form\ArrayTransformer; use App\Util\Form\ArrayTransformer;
use Component\Circle\Entity\ActorTag;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
abstract class SelfTagsForm abstract class SelfTagsForm
{ {
/** /**
* @return array [Form (add), ?Form (existing)] * @param ActorTag[] $actor_self_tags
*
* @return array{FormInterface, ?FormInterface} [Form (add), ?Form (existing)]
*/ */
public static function handleTags( public static function handleTags(
Request $request, Request $request,

View File

@ -23,6 +23,10 @@ class Collection extends Component
* *
* Supports a variety of query terms and is used both in feeds and * Supports a variety of query terms and is used both in feeds and
* in search. Uses query builders to allow for extension * in search. Uses query builders to allow for extension
*
* @param array<string, OrderByType> $note_order_by
* @param array<string, OrderByType> $actor_order_by
* @return array{notes: Note[], actors: Actor[]}
*/ */
public static function query(string $query, int $page, ?string $locale = null, ?Actor $actor = null, array $note_order_by = [], array $actor_order_by = []): array public static function query(string $query, int $page, ?string $locale = null, ?Actor $actor = null, array $note_order_by = [], array $actor_order_by = []): array
{ {

View File

@ -7,14 +7,22 @@ namespace Component\Collection\Util\Controller;
use App\Core\Controller; use App\Core\Controller;
use App\Entity\Actor; use App\Entity\Actor;
use App\Util\Common; use App\Util\Common;
use Component\Collection\Collection as CollectionModule; use Component\Collection\Collection as CollectionComponent;
/**
* @template T
*/
class Collection extends Controller class Collection extends Controller
{ {
/**
* @param array<string, OrderByType> $note_order_by
* @param array<string, OrderByType> $actor_order_by
* @return array<T>
*/
public function query(string $query, ?string $locale = null, ?Actor $actor = null, array $note_order_by = [], array $actor_order_by = []): array public function query(string $query, ?string $locale = null, ?Actor $actor = null, array $note_order_by = [], array $actor_order_by = []): array
{ {
$actor ??= Common::actor(); $actor ??= Common::actor();
$locale ??= Common::currentLanguage()->getLocale(); $locale ??= Common::currentLanguage()->getLocale();
return CollectionModule::query($query, $this->int('page') ?? 1, $locale, $actor, $note_order_by, $actor_order_by); return CollectionComponent::query($query, $this->int('page') ?? 1, $locale, $actor, $note_order_by, $actor_order_by);
} }
} }

View File

@ -44,6 +44,10 @@ abstract class FeedController extends OrderedCollection
* Post-processing of the result of a feed controller, to remove any * Post-processing of the result of a feed controller, to remove any
* notes or actors the user specified, as well as format the raw * notes or actors the user specified, as well as format the raw
* list of notes into a usable format * list of notes into a usable format
*
* @template T of Note|Actor
* @param T[] $result
* @return T[]
*/ */
protected function postProcess(array $result): array protected function postProcess(array $result): array
{ {
@ -58,6 +62,9 @@ abstract class FeedController extends OrderedCollection
return $result; return $result;
} }
/**
* @param Note[] $notes
*/
private static function enforceScope(array &$notes, ?Actor $actor, ?Actor $in = null): void private static function enforceScope(array &$notes, ?Actor $actor, ?Actor $in = null): void
{ {
$notes = F\select($notes, fn (Note $n) => $n->isVisibleTo($actor, $in)); $notes = F\select($notes, fn (Note $n) => $n->isVisibleTo($actor, $in));

View File

@ -41,6 +41,9 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/**
* @template T
*/
abstract class MetaCollectionController extends FeedController abstract class MetaCollectionController extends FeedController
{ {
protected const SLUG = 'collectionsEntry'; protected const SLUG = 'collectionsEntry';
@ -48,17 +51,36 @@ abstract class MetaCollectionController extends FeedController
protected string $page_title = 'Collections'; protected string $page_title = 'Collections';
abstract public function getCollectionUrl(int $owner_id, string $owner_nickname, int $collection_id): string; abstract public function getCollectionUrl(int $owner_id, string $owner_nickname, int $collection_id): string;
abstract public function getCollectionItems(int $owner_id, $collection_id): array;
abstract public function getCollectionsByActorId(int $owner_id): array;
abstract public function getCollectionBy(int $owner_id, int $collection_id);
abstract public function createCollection(int $owner_id, string $name);
/**
* @return T[]
*/
abstract public function getCollectionItems(int $owner_id, int $collection_id): array;
/**
* @return T[]
*/
abstract public function getCollectionsByActorId(int $owner_id): array;
/**
* @return T A collection
*/
abstract public function getCollectionBy(int $owner_id, int $collection_id): object;
abstract public function createCollection(int $owner_id, string $name): bool;
/**
* @return T[]
*/
public function collectionsViewByActorNickname(Request $request, string $nickname): array public function collectionsViewByActorNickname(Request $request, string $nickname): array
{ {
$user = DB::findOneBy(LocalUser::class, ['nickname' => $nickname]); $user = DB::findOneBy(LocalUser::class, ['nickname' => $nickname]);
return self::collectionsView($request, $user->getId(), $nickname); return self::collectionsView($request, $user->getId(), $nickname);
} }
/**
* @return T[]
*/
public function collectionsViewByActorId(Request $request, int $id): array public function collectionsViewByActorId(Request $request, int $id): array
{ {
return self::collectionsView($request, $id, null); return self::collectionsView($request, $id, null);
@ -70,7 +92,7 @@ abstract class MetaCollectionController extends FeedController
* @param int $id actor id * @param int $id actor id
* @param ?string $nickname actor nickname * @param ?string $nickname actor nickname
* *
* @return array twig template options * @return ControllerResultType twig template options
*/ */
public function collectionsView(Request $request, int $id, ?string $nickname): array public function collectionsView(Request $request, int $id, ?string $nickname): array
{ {

View File

@ -45,6 +45,9 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/**
* @template T
* */
trait MetaCollectionTrait trait MetaCollectionTrait
{ {
//protected const SLUG = 'collection'; //protected const SLUG = 'collection';
@ -53,40 +56,42 @@ trait MetaCollectionTrait
/** /**
* create a collection owned by Actor $owner. * create a collection owned by Actor $owner.
* *
* @param Actor $owner The collection's owner * @param Actor $owner The collection's owner
* @param array $vars Page vars sent by AppendRightPanelBlock event * @param array<string, mixed> $vars Page vars sent by AppendRightPanelBlock event
* @param string $name Collection's name * @param string $name Collection's name
*/ */
abstract protected function createCollection(Actor $owner, array $vars, string $name); abstract protected function createCollection(Actor $owner, array $vars, string $name): void;
/** /**
* remove item from collections. * remove item from collections.
* *
* @param Actor $owner Current user * @param Actor $owner Current user
* @param array $vars Page vars sent by AppendRightPanelBlock event * @param array<string, mixed> $vars Page vars sent by AppendRightPanelBlock event
* @param array $items Array of collections's ids to remove the current item from * @param int[] $items Array of collections's ids to remove the current item from
* @param array $collections List of ids of collections owned by $owner * @param int[] $collections List of ids of collections owned by $owner
*/ */
abstract protected function removeItem(Actor $owner, array $vars, array $items, array $collections); abstract protected function removeItem(Actor $owner, array $vars, array $items, array $collections): bool;
/** /**
* add item to collections. * add item to collections.
* *
* @param Actor $owner Current user * @param Actor $owner Current user
* @param array $vars Page vars sent by AppendRightPanelBlock event * @param array<string, mixed> $vars Page vars sent by AppendRightPanelBlock event
* @param array $items Array of collections's ids to add the current item to * @param int[] $items Array of collections's ids to add the current item to
* @param array $collections List of ids of collections owned by $owner * @param int[] $collections List of ids of collections owned by $owner
*/ */
abstract protected function addItem(Actor $owner, array $vars, array $items, array $collections); abstract protected function addItem(Actor $owner, array $vars, array $items, array $collections): void;
/** /**
* Check the route to determine whether the widget should be added * Check the route to determine whether the widget should be added
* @param array<string, mixed> $vars
*/ */
abstract protected function shouldAddToRightPanel(Actor $user, $vars, Request $request): bool; abstract protected function shouldAddToRightPanel(Actor $user, array $vars, Request $request): bool;
/** /**
* Get array of collections's owned by $actor * Get array of collections's owned by $actor
* *
* @param Actor $owner Collection's owner * @param Actor $owner Collection's owner
* @param ?array $vars Page vars sent by AppendRightPanelBlock event * @param null|array<string, mixed> $vars Page vars sent by AppendRightPanelBlock event
* @param bool $ids_only if true, the function must return only the primary key or each collections * @param bool $ids_only if true, the function must return only the primary key or each collections
* @return T[]|int[]
*/ */
abstract protected function getCollectionsBy(Actor $owner, ?array $vars = null, bool $ids_only = false): array; abstract protected function getCollectionsBy(Actor $owner, ?array $vars = null, bool $ids_only = false): array;
@ -94,8 +99,11 @@ trait MetaCollectionTrait
* Append Collections widget to the right panel. * Append Collections widget to the right panel.
* It's compose of two forms: one to select collections to add * It's compose of two forms: one to select collections to add
* the current item to, and another to create a new collection. * the current item to, and another to create a new collection.
*
* @param array<string, mixed> $vars
* @param string[] $res
*/ */
public function onAppendRightPanelBlock(Request $request, $vars, &$res): EventResult public function onAppendRightPanelBlock(Request $request, array $vars, array &$res): EventResult
{ {
$user = Common::actor(); $user = Common::actor();
if (\is_null($user)) { if (\is_null($user)) {
@ -187,6 +195,9 @@ trait MetaCollectionTrait
return Event::next; return Event::next;
} }
/**
* @param string[]
*/
public function onEndShowStyles(array &$styles, string $route): EventResult public function onEndShowStyles(array &$styles, string $route): EventResult
{ {
$styles[] = 'components/Collection/assets/css/widget.css'; $styles[] = 'components/Collection/assets/css/widget.css';

View File

@ -15,6 +15,12 @@ parameters:
earlyTerminatingMethodCalls: earlyTerminatingMethodCalls:
App\Core\Log: App\Core\Log:
- unexpected_exception - unexpected_exception
typeAliases:
ControllerResultType: 'array{_template: string} & array<string, mixed>'
CacheKeysType: 'array<string, string>'
SettingsTabsType: 'array<array{title: string, desc: string, id: string, controller: ControllerResultType}>'
OrderByType: "'ASC' | 'DESC' | 'asc' | 'desc'"
ignoreErrors: ignoreErrors:
- -
message: '/Access to an undefined property App\\Util\\Bitmap::\$\w+/' message: '/Access to an undefined property App\\Util\\Bitmap::\$\w+/'

View File

@ -52,7 +52,7 @@ class AttachmentCollections extends Plugin
use MetaCollectionTrait; use MetaCollectionTrait;
protected const SLUG = 'collection'; protected const SLUG = 'collection';
protected const PLURAL_SLUG = 'collections'; protected const PLURAL_SLUG = 'collections';
protected function createCollection(Actor $owner, array $vars, string $name) protected function createCollection(Actor $owner, array $vars, string $name): void
{ {
$col = AttachmentCollection::create([ $col = AttachmentCollection::create([
'name' => $name, 'name' => $name,
@ -65,7 +65,7 @@ class AttachmentCollections extends Plugin
'attachment_collection_id' => $col->getId(), 'attachment_collection_id' => $col->getId(),
])); ]));
} }
protected function removeItem(Actor $owner, array $vars, array $items, array $collections) protected function removeItem(Actor $owner, array $vars, array $items, array $collections): bool
{ {
return DB::dql(<<<'EOF' return DB::dql(<<<'EOF'
DELETE FROM \Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry AS entry DELETE FROM \Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry AS entry
@ -83,7 +83,7 @@ class AttachmentCollections extends Plugin
]); ]);
} }
protected function addItem(Actor $owner, array $vars, array $items, array $collections) protected function addItem(Actor $owner, array $vars, array $items, array $collections): void
{ {
foreach ($items as $id) { foreach ($items as $id) {
// prevent user from putting something in a collection (s)he doesn't own: // prevent user from putting something in a collection (s)he doesn't own:
@ -102,6 +102,10 @@ class AttachmentCollections extends Plugin
return $vars['path'] === 'note_attachment_show'; return $vars['path'] === 'note_attachment_show';
} }
/**
* @param array<string, mixed> $vars
* @return int[]
*/
protected function getCollectionsBy(Actor $owner, ?array $vars = null, bool $ids_only = false): array protected function getCollectionsBy(Actor $owner, ?array $vars = null, bool $ids_only = false): array
{ {
if (\is_null($vars)) { if (\is_null($vars)) {

View File

@ -30,13 +30,14 @@ use Plugin\AttachmentCollections\Entity\AttachmentCollection;
class AttachmentCollections extends MetaCollectionController class AttachmentCollections extends MetaCollectionController
{ {
public function createCollection(int $owner_id, string $name) public function createCollection(int $owner_id, string $name): bool
{ {
DB::persist(AttachmentCollection::create([ DB::persist(AttachmentCollection::create([
'name' => $name, 'name' => $name,
'actor_id' => $owner_id, 'actor_id' => $owner_id,
])); ]));
} }
public function getCollectionUrl(int $owner_id, ?string $owner_nickname, int $collection_id): string public function getCollectionUrl(int $owner_id, ?string $owner_nickname, int $collection_id): string
{ {
if (\is_null($owner_nickname)) { if (\is_null($owner_nickname)) {

View File

@ -33,7 +33,11 @@ use Symfony\Component\HttpFoundation\Request;
class AttachmentShowRelated extends Plugin class AttachmentShowRelated extends Plugin
{ {
public function onAppendRightPanelBlock(Request $request, $vars, &$res): EventResult /**
* @param array<string, mixed> $vars
* @param string[] $res
*/
public function onAppendRightPanelBlock(Request $request, array $vars, array &$res): EventResult
{ {
if ($vars['path'] === 'note_attachment_show') { if ($vars['path'] === 'note_attachment_show') {
$related_notes = DB::dql('select n from attachment_to_note an ' $related_notes = DB::dql('select n from attachment_to_note an '

View File

@ -36,7 +36,10 @@ class Bundles extends Plugin
protected const SLUG = 'bundle'; protected const SLUG = 'bundle';
protected const PLURAL_SLUG = 'bundles'; protected const PLURAL_SLUG = 'bundles';
protected function createCollection(Actor $owner, array $vars, string $name) /**
* @param array<string, mixed> $vars
*/
protected function createCollection(Actor $owner, array $vars, string $name): void
{ {
$column = BundleCollection::create([ $column = BundleCollection::create([
'name' => $name, 'name' => $name,
@ -49,7 +52,11 @@ class Bundles extends Plugin
])); ]));
} }
protected function removeItem(Actor $owner, array $vars, array $items, array $collections) /**
* @param array<string, mixed> $vars
* @param array<int> $items
*/
protected function removeItem(Actor $owner, array $vars, array $items, array $collections): bool
{ {
return DB::dql(<<<'EOF' return DB::dql(<<<'EOF'
DELETE FROM \Plugin\BlogCollections\Entity\BlogCollectionEntry AS entry DELETE FROM \Plugin\BlogCollections\Entity\BlogCollectionEntry AS entry
@ -66,7 +73,12 @@ class Bundles extends Plugin
]); ]);
} }
protected function addItem(Actor $owner, array $vars, array $items, array $collections) /**
* @param array<string, mixed> $vars
* @param array<int> $items
* @param array<int> $collections
*/
protected function addItem(Actor $owner, array $vars, array $items, array $collections): void
{ {
foreach ($items as $id) { foreach ($items as $id) {
// prevent user from putting something in a collection (s)he doesn't own: // prevent user from putting something in a collection (s)he doesn't own:
@ -79,12 +91,19 @@ class Bundles extends Plugin
} }
} }
protected function shouldAddToRightPanel(Actor $user, $vars, Request $request): bool /**
* @param array<string, mixed> $vars
*/
protected function shouldAddToRightPanel(Actor $user, array $vars, Request $request): bool
{ {
// TODO: Implement shouldAddToRightPanel() method. // TODO: Implement shouldAddToRightPanel() method.
return false; return false;
} }
/**
* @param array<string, mixed> $vars
* @retrun int[]
*/
protected function getCollectionsBy(Actor $owner, ?array $vars = null, bool $ids_only = false): array protected function getCollectionsBy(Actor $owner, ?array $vars = null, bool $ids_only = false): array
{ {
if (\is_null($vars)) { if (\is_null($vars)) {

View File

@ -68,16 +68,18 @@ class BundleCollections extends MetaCollectionController
return DB::findBy(BundleCollection::class, ['actor_id' => $owner_id], order_by: ['id' => 'desc']); return DB::findBy(BundleCollection::class, ['actor_id' => $owner_id], order_by: ['id' => 'desc']);
} }
public function getCollectionBy(int $owner_id, int $collection_id) public function getCollectionBy(int $owner_id, int $collection_id): BundleCollection
{ {
return DB::findOneBy(BundleCollection::class, ['id' => $collection_id]); return DB::findOneBy(BundleCollection::class, ['id' => $collection_id]);
} }
public function createCollection(int $owner_id, string $name) public function createCollection(int $owner_id, string $name): bool
{ {
DB::persist(BundleCollection::create([ DB::persist(BundleCollection::create([
'name' => $name, 'name' => $name,
'actor_id' => $owner_id, 'actor_id' => $owner_id,
])); ]));
return true;
} }
} }

View File

@ -53,6 +53,9 @@ class Cover extends Plugin
return Event::next; return Event::next;
} }
/**
* @param SettingsTabsType $tabs
*/
public function onPopulateSettingsTabs(Request $request, string $section, &$tabs): EventResult public function onPopulateSettingsTabs(Request $request, string $section, &$tabs): EventResult
{ {
if ($section === 'profile') { if ($section === 'profile') {

View File

@ -62,6 +62,7 @@ class Oomox extends Plugin
* Populates an additional profile user panel section * Populates an additional profile user panel section
* Used in 'person/settings.html.twig' * Used in 'person/settings.html.twig'
* *
* @param SettingsTabsType $tabs
* @throws \App\Util\Exception\NoLoggedInUser * @throws \App\Util\Exception\NoLoggedInUser
* @throws RedirectException * @throws RedirectException
* @throws ServerException * @throws ServerException

View File

@ -69,6 +69,9 @@ class Pinboard extends Plugin
return Event::next; return Event::next;
} }
/**
* @param SettingsTabsType $tabs
*/
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
{ {
if ($section === 'api') { if ($section === 'api') {

View File

@ -57,6 +57,7 @@ class ProfileColor extends Plugin
} }
/** /**
* @param SettingsTabsType $tabs
* @throws RedirectException * @throws RedirectException
* @throws ServerException * @throws ServerException
*/ */

View File

@ -104,6 +104,9 @@ class TagBasedFiltering extends Plugin
return Event::next; return Event::next;
} }
/**
* @param SettingsTabsType $tabs
*/
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
{ {
if ($section === 'muting') { if ($section === 'muting') {

View File

@ -50,6 +50,9 @@ use Symfony\Component\HttpFoundation\Request;
*/ */
class UnboundGroup extends Plugin class UnboundGroup extends Plugin
{ {
/**
* @param SettingsTabsType $tabs
*/
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
{ {
if ($section === 'profile' && $request->get('_route') === 'group_actor_settings') { if ($section === 'profile' && $request->get('_route') === 'group_actor_settings') {

View File

@ -54,6 +54,9 @@ class WebHooks extends Plugin
return EventResult::next; return EventResult::next;
} }
/**
* @param SettingsTabsType $tabs
*/
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
{ {
if ($section === 'api') { if ($section === 'api') {

View File

@ -53,7 +53,11 @@ use Symfony\Component\HttpFoundation\Request;
class WebMonetization extends Plugin class WebMonetization extends Plugin
{ {
public function onAppendRightPanelBlock(Request $request, $vars, &$res): EventResult /**
* @param array<string, mixed> $vars
* @param string[] $res
*/
public function onAppendRightPanelBlock(Request $request, array $vars, array &$res): EventResult
{ {
$user = Common::actor(); $user = Common::actor();
if (\is_null($user)) { if (\is_null($user)) {