[TOOLS] Continue raising PHPStan level to 6
This commit is contained in:
@@ -4,6 +4,9 @@ declare(strict_types = 1);
|
||||
|
||||
namespace Component\Collection\Util\Controller;
|
||||
|
||||
/**
|
||||
* @extends OrderedCollection<\Component\Circle\Entity\ActorCircle>
|
||||
*/
|
||||
class CircleController extends OrderedCollection
|
||||
{
|
||||
}
|
||||
|
||||
@@ -6,18 +6,20 @@ namespace Component\Collection\Util\Controller;
|
||||
|
||||
use App\Core\Controller;
|
||||
use App\Entity\Actor;
|
||||
use App\Entity\Note;
|
||||
use App\Util\Common;
|
||||
use Component\Collection\Collection as CollectionComponent;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
class Collection extends Controller
|
||||
abstract class Collection extends Controller
|
||||
{
|
||||
/**
|
||||
* @param array<string, OrderByType> $note_order_by
|
||||
* @param array<string, OrderByType> $actor_order_by
|
||||
* @return array<T>
|
||||
*
|
||||
* @return array{notes: null|Note[], actors: null|Actor[]}
|
||||
*/
|
||||
public function query(string $query, ?string $locale = null, ?Actor $actor = null, array $note_order_by = [], array $actor_order_by = []): array
|
||||
{
|
||||
|
||||
@@ -38,6 +38,11 @@ use App\Entity\Note;
|
||||
use App\Util\Common;
|
||||
use Functional as F;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
*
|
||||
* @extends OrderedCollection<T>
|
||||
*/
|
||||
abstract class FeedController extends OrderedCollection
|
||||
{
|
||||
/**
|
||||
@@ -45,9 +50,11 @@ abstract class FeedController extends OrderedCollection
|
||||
* 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[]
|
||||
* @template NA of Note|Actor
|
||||
*
|
||||
* @param NA[] $result
|
||||
*
|
||||
* @return NA[]
|
||||
*/
|
||||
protected function postProcess(array $result): array
|
||||
{
|
||||
|
||||
@@ -39,10 +39,13 @@ use App\Util\Common;
|
||||
use App\Util\Exception\RedirectException;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template T of object
|
||||
*
|
||||
* @extends FeedController<T>
|
||||
*/
|
||||
abstract class MetaCollectionController extends FeedController
|
||||
{
|
||||
@@ -70,7 +73,7 @@ abstract class MetaCollectionController extends FeedController
|
||||
abstract public function createCollection(int $owner_id, string $name): bool;
|
||||
|
||||
/**
|
||||
* @return T[]
|
||||
* @return ControllerResultType
|
||||
*/
|
||||
public function collectionsViewByActorNickname(Request $request, string $nickname): array
|
||||
{
|
||||
@@ -79,7 +82,7 @@ abstract class MetaCollectionController extends FeedController
|
||||
}
|
||||
|
||||
/**
|
||||
* @return T[]
|
||||
* @return ControllerResultType
|
||||
*/
|
||||
public function collectionsViewByActorId(Request $request, int $id): array
|
||||
{
|
||||
@@ -135,34 +138,23 @@ abstract class MetaCollectionController extends FeedController
|
||||
// the functions and passing that class to the template.
|
||||
// This is suggested at https://web.archive.org/web/20220226132328/https://stackoverflow.com/questions/3595727/twig-pass-function-into-template/50364502
|
||||
$fn = new class($id, $nickname, $request, $this, static::SLUG) {
|
||||
private $id;
|
||||
private $nick;
|
||||
private $request;
|
||||
private $parent;
|
||||
private $slug;
|
||||
|
||||
public function __construct($id, $nickname, $request, $parent, $slug)
|
||||
public function __construct(private int $id, private string $nickname, private Request $request, private object $parent, private string $slug)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->nick = $nickname;
|
||||
$this->request = $request;
|
||||
$this->parent = $parent;
|
||||
$this->slug = $slug;
|
||||
}
|
||||
// there's already an injected function called path,
|
||||
// that maps to Router::url(name, args), but since
|
||||
// I want to preserve nicknames, I think it's better
|
||||
// to use that getUrl function
|
||||
public function getUrl($cid)
|
||||
public function getUrl(int $cid): string
|
||||
{
|
||||
return $this->parent->getCollectionUrl($this->id, $this->nick, $cid);
|
||||
return $this->parent->getCollectionUrl($this->id, $this->nickname, $cid);
|
||||
}
|
||||
// There are many collections in this page and we need two
|
||||
// forms for each one of them: one form to edit the collection's
|
||||
// name and another to remove the collection.
|
||||
|
||||
// creating the edit form
|
||||
public function editForm($collection)
|
||||
public function editForm(object $collection): FormView
|
||||
{
|
||||
$edit = Form::create([
|
||||
['name', TextType::class, [
|
||||
@@ -181,7 +173,7 @@ abstract class MetaCollectionController extends FeedController
|
||||
]);
|
||||
$edit->handleRequest($this->request);
|
||||
if ($edit->isSubmitted() && $edit->isValid()) {
|
||||
$this->parent->setCollectionName($this->id, $this->nick, $collection, $edit->getData()['name']);
|
||||
$this->parent->setCollectionName($this->id, $this->nickname, $collection, $edit->getData()['name']);
|
||||
DB::flush();
|
||||
throw new RedirectException();
|
||||
}
|
||||
@@ -189,7 +181,7 @@ abstract class MetaCollectionController extends FeedController
|
||||
}
|
||||
|
||||
// creating the remove form
|
||||
public function rmForm($collection)
|
||||
public function rmForm(object $collection): FormView
|
||||
{
|
||||
$rm = Form::create([
|
||||
['remove_' . $collection->getId(), SubmitType::class, [
|
||||
@@ -202,7 +194,7 @@ abstract class MetaCollectionController extends FeedController
|
||||
]);
|
||||
$rm->handleRequest($this->request);
|
||||
if ($rm->isSubmitted()) {
|
||||
$this->parent->removeCollection($this->id, $this->nick, $collection);
|
||||
$this->parent->removeCollection($this->id, $this->nickname, $collection);
|
||||
DB::flush();
|
||||
throw new RedirectException();
|
||||
}
|
||||
@@ -220,12 +212,18 @@ abstract class MetaCollectionController extends FeedController
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ControllerResultType
|
||||
*/
|
||||
public function collectionsEntryViewNotesByNickname(Request $request, string $nickname, int $cid): array
|
||||
{
|
||||
$user = DB::findOneBy(LocalUser::class, ['nickname' => $nickname]);
|
||||
return self::collectionsEntryViewNotesByActorId($request, $user->getId(), $cid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ControllerResultType
|
||||
*/
|
||||
public function collectionsEntryViewNotesByActorId(Request $request, int $id, int $cid): array
|
||||
{
|
||||
$collection = $this->getCollectionBy($id, $cid);
|
||||
|
||||
@@ -4,6 +4,11 @@ declare(strict_types = 1);
|
||||
|
||||
namespace Component\Collection\Util\Controller;
|
||||
|
||||
class OrderedCollection extends Collection
|
||||
/**
|
||||
* @template T
|
||||
*
|
||||
* @extends Collection<T>
|
||||
*/
|
||||
abstract class OrderedCollection extends Collection
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,9 +56,9 @@ trait MetaCollectionTrait
|
||||
/**
|
||||
* create a collection owned by Actor $owner.
|
||||
*
|
||||
* @param Actor $owner The collection's owner
|
||||
* @param array<string, mixed> $vars Page vars sent by AppendRightPanelBlock event
|
||||
* @param string $name Collection's name
|
||||
* @param Actor $owner The collection's owner
|
||||
* @param array<string, mixed> $vars Page vars sent by AppendRightPanelBlock event
|
||||
* @param string $name Collection's name
|
||||
*/
|
||||
abstract protected function createCollection(Actor $owner, array $vars, string $name): void;
|
||||
/**
|
||||
@@ -82,6 +82,7 @@ trait MetaCollectionTrait
|
||||
|
||||
/**
|
||||
* Check the route to determine whether the widget should be added
|
||||
*
|
||||
* @param array<string, mixed> $vars
|
||||
*/
|
||||
abstract protected function shouldAddToRightPanel(Actor $user, array $vars, Request $request): bool;
|
||||
@@ -91,7 +92,8 @@ trait MetaCollectionTrait
|
||||
* @param Actor $owner Collection's owner
|
||||
* @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
|
||||
* @return T[]|int[]
|
||||
*
|
||||
* @return int[]|T[]
|
||||
*/
|
||||
abstract protected function getCollectionsBy(Actor $owner, ?array $vars = null, bool $ids_only = false): array;
|
||||
|
||||
@@ -101,7 +103,7 @@ trait MetaCollectionTrait
|
||||
* the current item to, and another to create a new collection.
|
||||
*
|
||||
* @param array<string, mixed> $vars
|
||||
* @param string[] $res
|
||||
* @param string[] $res
|
||||
*/
|
||||
public function onAppendRightPanelBlock(Request $request, array $vars, array &$res): EventResult
|
||||
{
|
||||
@@ -146,7 +148,7 @@ trait MetaCollectionTrait
|
||||
if ($add_form->isSubmitted() && $add_form->isValid()) {
|
||||
$selected = $add_form->getData()['collections'];
|
||||
$removed = array_filter($already_selected, fn ($x) => !\in_array($x, $selected));
|
||||
$added = array_filter($selected, fn ($x) => !\in_array($x, $already_selected));
|
||||
$added = array_filter($selected, fn ($x) => !\in_array($x, $already_selected));
|
||||
if (\count($removed) > 0) {
|
||||
$this->removeItem($user, $vars, $removed, $collections);
|
||||
}
|
||||
@@ -196,7 +198,7 @@ trait MetaCollectionTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[]
|
||||
* @param string[] $styles
|
||||
*/
|
||||
public function onEndShowStyles(array &$styles, string $route): EventResult
|
||||
{
|
||||
|
||||
@@ -32,6 +32,9 @@ abstract class Parser
|
||||
{
|
||||
/**
|
||||
* Merge $parts into $criteria_arr
|
||||
*
|
||||
* @param mixed[] $parts
|
||||
* @param Criteria[] $criteria_arr
|
||||
*/
|
||||
private static function connectParts(array &$parts, array &$criteria_arr, string $last_op, mixed $eb, bool $force = false): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user