[TOOLS] Continue raising PHPStan to level 6

This commit is contained in:
2022-10-19 22:39:17 +01:00
parent e6bb418fe6
commit c31f3d4997
25 changed files with 233 additions and 58 deletions

View File

@@ -7,14 +7,22 @@ namespace Component\Collection\Util\Controller;
use App\Core\Controller;
use App\Entity\Actor;
use App\Util\Common;
use Component\Collection\Collection as CollectionModule;
use Component\Collection\Collection as CollectionComponent;
/**
* @template T
*/
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
{
$actor ??= Common::actor();
$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
* notes or actors the user specified, as well as format the raw
* list of notes into a usable format
*
* @template T of Note|Actor
* @param T[] $result
* @return T[]
*/
protected function postProcess(array $result): array
{
@@ -58,6 +62,9 @@ abstract class FeedController extends OrderedCollection
return $result;
}
/**
* @param Note[] $notes
*/
private static function enforceScope(array &$notes, ?Actor $actor, ?Actor $in = null): void
{
$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\HttpFoundation\Request;
/**
* @template T
*/
abstract class MetaCollectionController extends FeedController
{
protected const SLUG = 'collectionsEntry';
@@ -48,17 +51,36 @@ abstract class MetaCollectionController extends FeedController
protected string $page_title = 'Collections';
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
{
$user = DB::findOneBy(LocalUser::class, ['nickname' => $nickname]);
return self::collectionsView($request, $user->getId(), $nickname);
}
/**
* @return T[]
*/
public function collectionsViewByActorId(Request $request, int $id): array
{
return self::collectionsView($request, $id, null);
@@ -70,7 +92,7 @@ abstract class MetaCollectionController extends FeedController
* @param int $id actor id
* @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
{