[TOOLS] Fix errors found by PHPStan

This commit is contained in:
Hugo Sales 2021-12-21 12:17:51 +00:00
parent fa863d9e03
commit da8c41e094
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 19 additions and 6 deletions

View File

@ -87,9 +87,9 @@ class Actor extends ActorController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
Log::info( Log::info(
_m( _m(
'Actor id:{actor_id} nick:{actor_nick} created the group {nickname}', 'Actor id:{actor_id} nick:{actor_nick} created the group {nickname}',
['{actor_id}' => $actor->getId(), 'actor_nick' => $actor->getNickname(), 'nickname' => $nickname], ['{actor_id}' => $actor->getId(), 'actor_nick' => $actor->getNickname(), 'nickname' => $nickname],
), ),
); );
$group = E\Actor::create([ $group = E\Actor::create([
@ -112,8 +112,8 @@ class Actor extends ActorController
'is_admin' => true, 'is_admin' => true,
])); ]));
DB::flush(); DB::flush();
Cache::delete(self::cacheKeys($actor->getId())['subscriber']); Cache::delete(E\Actor::cacheKeys($actor->getId())['subscriber']);
Cache::delete(self::cacheKeys($actor->getId())['subscribed']); Cache::delete(E\Actor::cacheKeys($actor->getId())['subscribed']);
throw new RedirectException; throw new RedirectException;
} }

View File

@ -33,6 +33,10 @@ declare(strict_types = 1);
namespace App\Core\Controller; namespace App\Core\Controller;
use App\Core\Controller; use App\Core\Controller;
use App\Core\DB\DB;
use function App\Core\I18n\_m;
use App\Util\Exception\ClientException;
use App\Util\Exception\RedirectException;
abstract class ActorController extends Controller abstract class ActorController extends Controller
{ {
@ -43,7 +47,7 @@ abstract class ActorController extends Controller
{ {
$actor = DB::findOneBy('actor', ['id' => $id]); $actor = DB::findOneBy('actor', ['id' => $id]);
if ($actor->getIsLocal()) { if ($actor->getIsLocal()) {
return new RedirectResponse($actor->getUrl()); throw new RedirectException($actor->getUrl());
} }
if (empty($actor)) { if (empty($actor)) {
throw new ClientException(_m('No such actor.'), 404); throw new ClientException(_m('No such actor.'), 404);

View File

@ -29,6 +29,7 @@ use App\Core\Entity;
use App\Core\Event; use App\Core\Event;
use App\Core\Router\Router; use App\Core\Router\Router;
use App\Core\UserRoles; use App\Core\UserRoles;
use App\Util\Exception\BugFoundException;
use App\Util\Exception\DuplicateFoundException; use App\Util\Exception\DuplicateFoundException;
use App\Util\Exception\NicknameException; use App\Util\Exception\NicknameException;
use App\Util\Exception\NotFoundException; use App\Util\Exception\NotFoundException;
@ -501,6 +502,9 @@ class Actor extends Entity
break; break;
case self::GROUP: case self::GROUP:
$uri = Router::url('group_actor_view_id', ['id' => $this->getId()], $type); $uri = Router::url('group_actor_view_id', ['id' => $this->getId()], $type);
// no break
default:
throw new BugFoundException('Actor type added but `Actor::getUri` was not updated');
} }
Event::handle('EndGetActorUri', [$this, $type, &$uri]); Event::handle('EndGetActorUri', [$this, $type, &$uri]);
} }
@ -521,6 +525,9 @@ class Actor extends Entity
break; break;
case self::GROUP: case self::GROUP:
$url = Router::url('group_actor_view_nickname', ['nickname' => $this->getNickname()], $type); $url = Router::url('group_actor_view_nickname', ['nickname' => $this->getNickname()], $type);
// no break
default:
throw new BugFoundException('Actor type added but `Actor::getUrl` was not updated');
} }
} else { } else {
return $this->getUri($type); return $this->getUri($type);
@ -540,6 +547,8 @@ class Actor extends Entity
return Router::url('actor_view_nickname', ['nickname' => $nickname], $uri_type); return Router::url('actor_view_nickname', ['nickname' => $nickname], $uri_type);
case self::GROUP: case self::GROUP:
return Router::url('group_actor_view_nickname', ['nickname' => $nickname], $uri_type); return Router::url('group_actor_view_nickname', ['nickname' => $nickname], $uri_type);
default:
throw new BugFoundException('Actor type added but `Actor::getPlaceholderUri` was not updated');
} }
} }