[COMPONENTS][Posting] No error to ignore was reported on line 161, removed ignore

[PLUGINS][Directory] Further documentation work

[CORE][Controller] Separating workflows, setting proper return types

[TWIG][Security] Removing unused stylesheet calls
This commit is contained in:
Eliseu Amaro 2022-01-26 20:54:55 +00:00
parent 16e7d6cff7
commit adf484f58a
Signed by: eliseuamaro
GPG Key ID: 96DA09D4B97BC2D5
5 changed files with 48 additions and 59 deletions

View File

@ -158,7 +158,7 @@ class Posting extends Component
content_type: $content_type, content_type: $content_type,
locale: $data['language'], locale: $data['language'],
scope: VisibilityScope::from($data['visibility']), scope: VisibilityScope::from($data['visibility']),
target: $target ?? null, // @phpstan-ignore-line target: $target ?? null,
reply_to_id: $data['reply_to_id'], reply_to_id: $data['reply_to_id'],
attachments: $data['attachments'], attachments: $data['attachments'],
process_note_content_extra_args: $extra_args, process_note_content_extra_args: $extra_args,

View File

@ -37,8 +37,8 @@ use Symfony\Component\HttpFoundation\Request;
class Directory extends Plugin class Directory extends Plugin
{ {
/** /**
* Map URLs to Controllers * Map Directory routes to its corresponding Controllers
* @param RouteLoader $r *
* @return bool * @return bool
*/ */
public function onAddRoute(RouteLoader $r) public function onAddRoute(RouteLoader $r)
@ -50,9 +50,8 @@ class Directory extends Plugin
} }
/** /**
* Add Links to menu * Add Links to main navigation card
* *
* @param array $vars
* @param array $res out menu items * @param array $res out menu items
* *
* @return bool hook value; true means continue processing, false means stop * @return bool hook value; true means continue processing, false means stop
@ -67,12 +66,12 @@ class Directory extends Plugin
/** /**
* Prepend various widgets to Actors Collection template * Prepend various widgets to Actors Collection template
* *
* @param Request $request * @param array $elements array of widgets to be prepended
* @param $elements array of widgets to be prepended
* *
* @return bool EventHook
* @throws RedirectException * @throws RedirectException
* @throws ServerException * @throws ServerException
*
* @return bool EventHook
*/ */
public function onPrependActorsCollection(Request $request, array &$elements): bool public function onPrependActorsCollection(Request $request, array &$elements): bool
{ {

View File

@ -41,13 +41,13 @@ use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
use Component\Collection\Util\Controller\FeedController; use Component\Collection\Util\Controller\FeedController;
use Exception; use Exception;
use RuntimeException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\HttpKernel\Event\ViewEvent;
@ -61,6 +61,8 @@ use Throwable;
* @method ?string string(string $param, ?\Throwable $throw = null) * @method ?string string(string $param, ?\Throwable $throw = null)
* @method ?string params(string $param) * @method ?string params(string $param)
* @method mixed handle(Request $request, mixed ...$extra) * @method mixed handle(Request $request, mixed ...$extra)
*
* @return array
*/ */
abstract class Controller extends AbstractController implements EventSubscriberInterface abstract class Controller extends AbstractController implements EventSubscriberInterface
{ {
@ -85,15 +87,15 @@ abstract class Controller extends AbstractController implements EventSubscriberI
$attributes = array_diff_key($request->attributes->get('_route_params'), array_flip(['_format', '_fragment', '_locale', 'template', 'accept', 'is_system_path'])); $attributes = array_diff_key($request->attributes->get('_route_params'), array_flip(['_format', '_fragment', '_locale', 'template', 'accept', 'is_system_path']));
if (method_exists($class, $method)) { if (method_exists($class, $method)) {
return $this->{$method}($request, ...$attributes); return $this->{$method}($request, ...$attributes);
} else {
return $this->handle($request, ...$attributes);
} }
return $this->handle($request, ...$attributes);
} }
/** /**
* Symfony event when it's searching for which controller to use * Symfony event when it's searching for which controller to use
*/ */
public function onKernelController(ControllerEvent $event) public function onKernelController(ControllerEvent $event): ControllerEvent
{ {
$controller = $event->getController(); $controller = $event->getController();
$request = $event->getRequest(); $request = $event->getRequest();
@ -116,7 +118,7 @@ abstract class Controller extends AbstractController implements EventSubscriberI
* @throws ClientException * @throws ClientException
* @throws ServerException * @throws ServerException
*/ */
public function onKernelView(ViewEvent $event) public function onKernelView(ViewEvent $event): ViewEvent
{ {
$request = $event->getRequest(); $request = $event->getRequest();
$response = $event->getControllerResult(); $response = $event->getControllerResult();
@ -154,19 +156,14 @@ abstract class Controller extends AbstractController implements EventSubscriberI
'vars' => $this->vars, 'vars' => $this->vars,
'response' => &$potential_response, 'response' => &$potential_response,
]) !== Event::stop) { ]) !== Event::stop) {
switch ($format) { if ($format === 'json') {
case 'json':
$event->setResponse(new JsonResponse($response)); $event->setResponse(new JsonResponse($response));
break; } elseif ($redirect !== false) {
default: // html (assume if not specified) $event->setResponse(new RedirectResponse($redirect));
if ($redirect !== false) { } elseif (!\is_null($template)) {
$event->setResponse(new RedirectResponse($redirect)); $event->setResponse($this->render($template, $this->vars));
} elseif (!\is_null($template)) { } else {
$event->setResponse($this->render($template, $this->vars)); throw new ClientException(_m('Unsupported format: {format}', ['format' => $format]), 406); // 406 Not Acceptable
break;
} else {
throw new ClientException(_m('Unsupported format: {format}', ['format' => $format]), 406); // 406 Not Acceptable
}
} }
} else { } else {
if (\is_null($potential_response)) { if (\is_null($potential_response)) {
@ -197,7 +194,7 @@ abstract class Controller extends AbstractController implements EventSubscriberI
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function onKernelException(ExceptionEvent $event) public function onKernelException(ExceptionEvent $event): ExceptionEvent
{ {
$except = $event->getThrowable(); $except = $event->getThrowable();
if ($_ENV['APP_ENV'] !== 'dev') { if ($_ENV['APP_ENV'] !== 'dev') {
@ -206,13 +203,13 @@ abstract class Controller extends AbstractController implements EventSubscriberI
} }
do { do {
if ($except instanceof RedirectException) { if ($except instanceof RedirectException) {
if (($redir = $except->redirect_response) != null) { if (($redir = $except->redirect_response) !== null) {
$event->setResponse($redir); $event->setResponse($redir);
} else { } else {
$event->setResponse(new RedirectResponse($event->getRequest()->getPathInfo())); $event->setResponse(new RedirectResponse($event->getRequest()->getPathInfo()));
} }
} }
} while ($except != null && ($except = $except->getPrevious()) != null); } while (($except = $except->getPrevious()) !== null);
Event::handle('CleanupModule'); Event::handle('CleanupModule');
@ -222,7 +219,7 @@ abstract class Controller extends AbstractController implements EventSubscriberI
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public static function getSubscribedEvents() public static function getSubscribedEvents(): array
{ {
return [ return [
KernelEvents::CONTROLLER => 'onKernelController', KernelEvents::CONTROLLER => 'onKernelController',
@ -235,6 +232,7 @@ abstract class Controller extends AbstractController implements EventSubscriberI
* Get and convert GET parameters. Can be called with `int`, `bool`, `string`, etc * Get and convert GET parameters. Can be called with `int`, `bool`, `string`, etc
* *
* @throws Exception * @throws Exception
* @throws Throwable
* @throws ValidatorException * @throws ValidatorException
* *
* @return null|array|bool|int|string the value or null if no parameter exists * @return null|array|bool|int|string the value or null if no parameter exists
@ -242,27 +240,29 @@ abstract class Controller extends AbstractController implements EventSubscriberI
public function __call(string $method, array $args): array|bool|int|string|null public function __call(string $method, array $args): array|bool|int|string|null
{ {
switch ($method) { switch ($method) {
case 'int': case 'int':
case 'bool': case 'bool':
case 'string': case 'string':
if ($this->request->query->has($args[0])) { if ($this->request->query->has($args[0])) {
return match ($method) { return match ($method) {
'int' => $this->request->query->getInt($args[0]), 'int' => $this->request->query->getInt($args[0]),
'bool' => $this->request->query->getBoolean($args[0]), 'bool' => $this->request->query->getBoolean($args[0]),
'string' => $this->request->query->get($args[0]), 'string' => $this->request->query->get($args[0]),
default => throw new BugFoundException('Inconsistent switch/match spotted'), default => throw new BugFoundException('Inconsistent switch/match spotted'),
}; };
} elseif (\array_key_exists(1, $args) && $args[1] instanceof Throwable) { }
throw $args[1];
} else { if (\array_key_exists(1, $args) && ($args[1] instanceof Throwable)) {
throw $args[1];
}
return null; return null;
} case 'params':
case 'params': return $this->request->query->all();
return $this->request->query->all(); default:
default: // @codeCoverageIgnoreStart
// @codeCoverageIgnoreStart Log::critical($m = "Method '{$method}' on class App\\Core\\Controller not found (__call)");
Log::critical($m = "Method '{$method}' on class App\\Core\\Controller not found (__call)"); throw new RuntimeException($m);
throw new Exception($m);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
} }

View File

@ -1,10 +1,5 @@
{% extends 'stdgrid.html.twig' %} {% extends 'stdgrid.html.twig' %}
{% block stylesheets %}
{{ parent() }}
<link rel='stylesheet' type='text/css' href="{{ asset('assets/css/security/security.css') }}">
{% endblock %}
{% block title %}{{ "Log in!" | trans }}{% endblock %} {% block title %}{{ "Log in!" | trans }}{% endblock %}
{% block body %} {% block body %}

View File

@ -1,10 +1,5 @@
{% extends 'stdgrid.html.twig' %} {% extends 'stdgrid.html.twig' %}
{% block stylesheets %}
{{ parent() }}
<link rel='stylesheet' type='text/css' href="{{ asset('assets/css/security/security.css') }}">
{% endblock %}
{% block title %}Register{% endblock %} {% block title %}Register{% endblock %}
{% block body %} {% block body %}