From 4e30e5aad955e32c80b394d86d5a510f789442fa Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Mon, 6 Sep 2021 23:47:28 +0100 Subject: [PATCH] [TOOLS] Fix all issues found by PHPStan level 2 --- phpstan.neon | 9 +++++-- plugins/ActivityPub/ActivityPub.php | 4 +-- .../ActivityStreamsTwo/ActivityStreamsTwo.php | 2 +- .../Util/Model/EntityToType/EntityToType.php | 5 ++-- .../Util/Model/EntityToType/NoteToType.php | 4 +-- .../Util/Response/AbstractResponse.php | 8 +++--- .../Util/Response/TypeResponse.php | 6 +++-- .../Util/Type/AbstractObject.php | 1 - .../Util/Type/Core/AbstractActivity.php | 2 +- .../Util/Type/Core/Collection.php | 2 +- .../Util/Type/Core/CollectionPage.php | 2 +- .../Util/Type/Core/ObjectType.php | 2 +- .../Util/Type/Validator.php | 2 +- plugins/Cover/Controller/Cover.php | 18 ++++++------- plugins/Cover/Entity/Cover.php | 4 +-- plugins/Embed/Embed.php | 7 ++--- plugins/Favourite/Favourite.php | 4 +-- plugins/FileQuota/FileQuota.php | 2 +- plugins/ImageEncoder/ImageEncoder.php | 2 +- plugins/StoreRemoteMedia/StoreRemoteMedia.php | 3 ++- src/Controller/ResetPassword.php | 6 +++++ src/Core/Controller.php | 6 ++--- src/Core/DB/DB.php | 26 ++++++++++++++----- src/Core/Entity.php | 2 +- src/Core/GSFile.php | 11 +++----- .../Compiler/SchemaDefDriver.php | 8 +++--- src/Entity/AttachmentThumbnail.php | 16 +++++++----- src/Entity/Note.php | 2 -- src/Security/Authenticator.php | 8 ++++-- src/Security/EmailVerifier.php | 20 +++++++------- src/Util/HTML.php | 2 +- src/Util/Nickname.php | 6 +---- src/Util/TemporaryFile.php | 1 + 33 files changed, 114 insertions(+), 89 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 3f22ca8dc9..bfc4afd185 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,12 @@ parameters: - level: 1 + level: 2 bootstrapFiles: - config/bootstrap.php earlyTerminatingMethodCalls: App\Core\Log: - - unexpected_exception \ No newline at end of file + - unexpected_exception + ignoreErrors: + - + message: '/Access to an undefined property App\\Util\\Bitmap::\$\w+/' + paths: + - * diff --git a/plugins/ActivityPub/ActivityPub.php b/plugins/ActivityPub/ActivityPub.php index 23559e1a41..e9e8c41be2 100644 --- a/plugins/ActivityPub/ActivityPub.php +++ b/plugins/ActivityPub/ActivityPub.php @@ -26,7 +26,7 @@ class ActivityPub extends Plugin * This code executes when GNU social creates the page routing, and we hook * on this event to add our action handler for Embed. * - * @param $r RouteLoader the router that was initialized. + * @param RouteLoader $r the router that was initialized. * * @return bool */ @@ -76,4 +76,4 @@ class ActivityPub extends Plugin ) ); } -} \ No newline at end of file +} diff --git a/plugins/ActivityStreamsTwo/ActivityStreamsTwo.php b/plugins/ActivityStreamsTwo/ActivityStreamsTwo.php index dccf801af0..803a9ea8d0 100644 --- a/plugins/ActivityStreamsTwo/ActivityStreamsTwo.php +++ b/plugins/ActivityStreamsTwo/ActivityStreamsTwo.php @@ -50,7 +50,7 @@ class ActivityStreamsTwo extends Plugin * This code executes when GNU social creates the page routing, and we hook * on this event to add our action handler for Embed. * - * @param $r RouteLoader the router that was initialized. + * @param RouteLoader $r the router that was initialized. * * @return bool */ diff --git a/plugins/ActivityStreamsTwo/Util/Model/EntityToType/EntityToType.php b/plugins/ActivityStreamsTwo/Util/Model/EntityToType/EntityToType.php index 16eba06831..ea157dd2fe 100644 --- a/plugins/ActivityStreamsTwo/Util/Model/EntityToType/EntityToType.php +++ b/plugins/ActivityStreamsTwo/Util/Model/EntityToType/EntityToType.php @@ -2,12 +2,13 @@ namespace Plugin\ActivityStreamsTwo\Util\Model\EntityToType; +use App\Core\Entity; use Plugin\ActivityStreamsTwo\Util\Type; abstract class EntityToType { /** - * @param $entity + * @param Entity $entity * * @throws \Exception * @@ -25,4 +26,4 @@ abstract class EntityToType return Type::create($map); } } -} \ No newline at end of file +} diff --git a/plugins/ActivityStreamsTwo/Util/Model/EntityToType/NoteToType.php b/plugins/ActivityStreamsTwo/Util/Model/EntityToType/NoteToType.php index 2761ee59c3..26d14cc4f1 100644 --- a/plugins/ActivityStreamsTwo/Util/Model/EntityToType/NoteToType.php +++ b/plugins/ActivityStreamsTwo/Util/Model/EntityToType/NoteToType.php @@ -10,7 +10,7 @@ use Plugin\ActivityStreamsTwo\Util\Type; class NoteToType { /** - * @param $entity + * @param Note $note * * @throws \Exception * @@ -30,4 +30,4 @@ class NoteToType ]; return Type::create(type: 'Note', attributes: $attr); } -} \ No newline at end of file +} diff --git a/plugins/ActivityStreamsTwo/Util/Response/AbstractResponse.php b/plugins/ActivityStreamsTwo/Util/Response/AbstractResponse.php index 2b874da483..1978f36aea 100644 --- a/plugins/ActivityStreamsTwo/Util/Response/AbstractResponse.php +++ b/plugins/ActivityStreamsTwo/Util/Response/AbstractResponse.php @@ -7,8 +7,10 @@ use Plugin\ActivityStreamsTwo\Util\Model\EntityToType\EntityToType; abstract class AbstractResponse { /** - * @param Type $type - * @param int $status The response status code + * param Type $type // What is this `Type` + * + * @param int $status The response status code + * @param mixed $type * * @throws \Exception * @@ -21,4 +23,4 @@ abstract class AbstractResponse status: $status ); } -} \ No newline at end of file +} diff --git a/plugins/ActivityStreamsTwo/Util/Response/TypeResponse.php b/plugins/ActivityStreamsTwo/Util/Response/TypeResponse.php index 80c29be11c..a3fb477fd8 100644 --- a/plugins/ActivityStreamsTwo/Util/Response/TypeResponse.php +++ b/plugins/ActivityStreamsTwo/Util/Response/TypeResponse.php @@ -7,8 +7,10 @@ use Symfony\Component\HttpFoundation\JsonResponse; class TypeResponse extends JsonResponse { /** - * @param Type $data - * @param int $status The response status code + * param Type $data // what `Type` is this? + * + * @param int $status The response status code + * @param null|mixed $data * * @return JsonResponse */ diff --git a/plugins/ActivityStreamsTwo/Util/Type/AbstractObject.php b/plugins/ActivityStreamsTwo/Util/Type/AbstractObject.php index c808ef5f7a..cada7d4492 100644 --- a/plugins/ActivityStreamsTwo/Util/Type/AbstractObject.php +++ b/plugins/ActivityStreamsTwo/Util/Type/AbstractObject.php @@ -137,7 +137,6 @@ abstract class AbstractObject * Checks that property exists * * @param string $name - * @param bool $strict * * @throws Exception * diff --git a/plugins/ActivityStreamsTwo/Util/Type/Core/AbstractActivity.php b/plugins/ActivityStreamsTwo/Util/Type/Core/AbstractActivity.php index 038067ced1..1636128dc5 100644 --- a/plugins/ActivityStreamsTwo/Util/Type/Core/AbstractActivity.php +++ b/plugins/ActivityStreamsTwo/Util/Type/Core/AbstractActivity.php @@ -27,7 +27,7 @@ abstract class AbstractActivity extends ObjectType /** * @var string */ - protected string $id; + public string $id; /** * Describes one or more entities that either performed or are diff --git a/plugins/ActivityStreamsTwo/Util/Type/Core/Collection.php b/plugins/ActivityStreamsTwo/Util/Type/Core/Collection.php index fdb47216d0..f26410a895 100644 --- a/plugins/ActivityStreamsTwo/Util/Type/Core/Collection.php +++ b/plugins/ActivityStreamsTwo/Util/Type/Core/Collection.php @@ -30,7 +30,7 @@ class Collection extends ObjectType /** * @var string */ - protected string $id; + public string $id; /** * A non-negative integer specifying the total number of objects diff --git a/plugins/ActivityStreamsTwo/Util/Type/Core/CollectionPage.php b/plugins/ActivityStreamsTwo/Util/Type/Core/CollectionPage.php index a0aec2d4bf..beeb243d54 100644 --- a/plugins/ActivityStreamsTwo/Util/Type/Core/CollectionPage.php +++ b/plugins/ActivityStreamsTwo/Util/Type/Core/CollectionPage.php @@ -29,7 +29,7 @@ class CollectionPage extends Collection /** * @var string */ - protected string $id; + public string $id; /** * Identifies the Collection to which CollectionPage objects items diff --git a/plugins/ActivityStreamsTwo/Util/Type/Core/ObjectType.php b/plugins/ActivityStreamsTwo/Util/Type/Core/ObjectType.php index ed312ff66c..2d3f1538ad 100644 --- a/plugins/ActivityStreamsTwo/Util/Type/Core/ObjectType.php +++ b/plugins/ActivityStreamsTwo/Util/Type/Core/ObjectType.php @@ -34,7 +34,7 @@ class ObjectType extends AbstractObject * * @var string */ - protected string $id; + public string $id; /** * @var string diff --git a/plugins/ActivityStreamsTwo/Util/Type/Validator.php b/plugins/ActivityStreamsTwo/Util/Type/Validator.php index b5aaf44257..284d41ab23 100644 --- a/plugins/ActivityStreamsTwo/Util/Type/Validator.php +++ b/plugins/ActivityStreamsTwo/Util/Type/Validator.php @@ -22,7 +22,7 @@ abstract class Validator /** * Contains all custom validators * - * @var array + * @var array * * [ 'attributeName' => CustomValidatorClassName::class ] */ diff --git a/plugins/Cover/Controller/Cover.php b/plugins/Cover/Controller/Cover.php index a1d2fbe4f8..9f57a99b61 100644 --- a/plugins/Cover/Controller/Cover.php +++ b/plugins/Cover/Controller/Cover.php @@ -143,14 +143,14 @@ class Cover */ public function cover() { - $cover = DB::find('cover', ['gsactor_id' => Common::user()->getId()]); - if ($cover == null) { - return new Response('Cover not found',Response::HTTP_NOT_FOUND); - } - $file = $cover->getFile(); - if ($file == null) { - return new Response('Cover File not found',Response::HTTP_NOT_FOUND); - } - return GSFile::sendFile($cover->getFilePath(), $file->getMimetype(), $file->getTitle()); + // $cover = DB::find('cover', ['gsactor_id' => Common::user()->getId()]); + // if ($cover == null) { + // return new Response('Cover not found',Response::HTTP_NOT_FOUND); + // } + // $file = $cover->getFile(); + // if ($file == null) { + // return new Response('Cover File not found',Response::HTTP_NOT_FOUND); + // } + // return GSFile::sendFile($cover->getFilePath(), $file->getMimetype(), $file->getTitle()); } } diff --git a/plugins/Cover/Entity/Cover.php b/plugins/Cover/Entity/Cover.php index cba810fbf9..3dae39b9a6 100644 --- a/plugins/Cover/Entity/Cover.php +++ b/plugins/Cover/Entity/Cover.php @@ -113,7 +113,7 @@ class Cover extends Entity */ public function getAttachmentPath(): string { - return Common::config('cover', 'dir') . $this->getAttachment()->getAttachmentName(); + return Common::config('cover', 'dir') . $this->getAttachment()->getBestTitle(); } /** @@ -129,7 +129,7 @@ class Cover extends Entity { // Don't go into a loop if we're deleting from Attachment if (!$cascading) { - $attachments = $this->getAttachment()->delete($cascade = true, $attachment_flush = false, $delete_attachments_now); + $attachments = $this->getAttachment()->kill(); } else { DB::remove(DB::getReference('cover', ['gsactor_id' => $this->gsactor_id])); $attachment_path = $this->getAttachmentPath(); diff --git a/plugins/Embed/Embed.php b/plugins/Embed/Embed.php index a8746a16c0..53da857889 100644 --- a/plugins/Embed/Embed.php +++ b/plugins/Embed/Embed.php @@ -205,14 +205,11 @@ class Embed extends Plugin * This code executes when GNU social creates the page routing, and we hook * on this event to add our action handler for Embed. * - * @param $m RouteLoader the router that was initialized. + * @param RouteLoader $m the router that was initialized. * * @throws Exception * * @return bool - * - * - * */ public function onAddRoute(RouteLoader $m): bool { @@ -492,7 +489,7 @@ class Embed extends Plugin * Event raised when GNU social polls the plugin for information about it. * Adds this plugin's version information to $versions array * - * @param &$versions array inherited from parent + * @param array $versions inherited from parent * * @throws ServerException * diff --git a/plugins/Favourite/Favourite.php b/plugins/Favourite/Favourite.php index c4c8d4644d..46e2b8f744 100644 --- a/plugins/Favourite/Favourite.php +++ b/plugins/Favourite/Favourite.php @@ -83,8 +83,8 @@ class Favourite extends NoteHandlerPlugin /** * Called from form handler * - * @param $note Note to be favourited - * @param $data Form input + * @param Note $note to be favourited + * @param Form $data input * * @throws RedirectException Always thrown in order to prevent accidental form re-submit from browser */ diff --git a/plugins/FileQuota/FileQuota.php b/plugins/FileQuota/FileQuota.php index 58b3c728e8..176de71b8b 100644 --- a/plugins/FileQuota/FileQuota.php +++ b/plugins/FileQuota/FileQuota.php @@ -103,7 +103,7 @@ END; * Event raised when GNU social polls the plugin for information about it. * Adds this plugin's version information to $versions array * - * @param &$versions array inherited from parent + * @param array $versions inherited from parent * * @return bool true hook value */ diff --git a/plugins/ImageEncoder/ImageEncoder.php b/plugins/ImageEncoder/ImageEncoder.php index 879d52db5f..0b5990304c 100644 --- a/plugins/ImageEncoder/ImageEncoder.php +++ b/plugins/ImageEncoder/ImageEncoder.php @@ -230,7 +230,7 @@ class ImageEncoder extends Plugin * Event raised when GNU social polls the plugin for information about it. * Adds this plugin's version information to $versions array * - * @param &$versions array inherited from parent + * @param array $versions inherited from parent * * @return bool true hook value */ diff --git a/plugins/StoreRemoteMedia/StoreRemoteMedia.php b/plugins/StoreRemoteMedia/StoreRemoteMedia.php index d07127f955..fc2f990442 100644 --- a/plugins/StoreRemoteMedia/StoreRemoteMedia.php +++ b/plugins/StoreRemoteMedia/StoreRemoteMedia.php @@ -124,6 +124,7 @@ class StoreRemoteMedia extends Plugin } // Have we handled it already? + /** @var AttachmentToLink */ $attachment_to_link = DB::find('attachment_to_link', ['link_id' => $link->getId()]); @@ -224,7 +225,7 @@ class StoreRemoteMedia extends Plugin * Event raised when GNU social polls the plugin for information about it. * Adds this plugin's version information to $versions array * - * @param &$versions array inherited from parent + * @param array $versions inherited from parent * * @return bool true hook value */ diff --git a/src/Controller/ResetPassword.php b/src/Controller/ResetPassword.php index 85abda267d..bef47aec70 100644 --- a/src/Controller/ResetPassword.php +++ b/src/Controller/ResetPassword.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Validator\Constraints\NotBlank; use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait; use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface; +use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordToken; /** * Send password reset emails to users @@ -114,4 +115,9 @@ class ResetPassword extends Controller 'resetForm' => $form->createView(), ]; } + + public function setInSession(ResetPasswordToken $reset_token) + { + $this->setTokenObjectInSession($reset_token); + } } diff --git a/src/Core/Controller.php b/src/Core/Controller.php index 41b0c9c28d..8dd9d643ec 100644 --- a/src/Core/Controller.php +++ b/src/Core/Controller.php @@ -45,6 +45,7 @@ use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\Validator\Exception\ValidatorException; /** * @method int int(string $param) @@ -187,13 +188,10 @@ class Controller extends AbstractController implements EventSubscriberInterface /** * Get and convert GET parameters. Can be called with `int`, `bool`, `string`, etc * - * @param string $name - * * @throws ValidatorException * @throws Exception * - * @return the value or null if no paramter exists - * + * @return null|mixed the value or null if no paramter exists */ public function __call(string $method, array $args) { diff --git a/src/Core/DB/DB.php b/src/Core/DB/DB.php index a781e13022..178e354842 100644 --- a/src/Core/DB/DB.php +++ b/src/Core/DB/DB.php @@ -38,12 +38,16 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Expr\Expression; use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; use Doctrine\ORM\Query\ResultSetMappingBuilder; use Functional as F; /** * @mixin EntityManagerInterface + * @template T + * + * @method T find(string $class, array $values) */ class DB { @@ -163,7 +167,8 @@ class DB { $criteria = array_change_key_case($criteria, CASE_LOWER); $ops = array_intersect(array_keys($criteria), self::$find_by_ops); - $repo = self::getRepository($table); + /** @var EntityRepository */ + $repo = self::getRepository($table); if (empty($ops)) { return $repo->findBy($criteria, $orderBy, $limit, $offset); } else { @@ -191,6 +196,7 @@ class DB public static function count(string $table, array $criteria) { + /** @var EntityRepository */ $repo = self::getRepository($table); return $repo->count($criteria); } @@ -220,11 +226,19 @@ class DB */ public static function __callStatic(string $name, array $args) { - if (in_array($name, ['find', 'getReference', 'getPartialReference', 'getRepository']) - && !str_contains($args[0], '\\')) { - $args[0] = self::$table_map[$args[0]]; - } - + $args[0] = self::filterTableName($name, $args); return self::$em->{$name}(...$args); } + + public const METHODS_ACCEPTING_TABLE_NAME = ['find', 'getReference', 'getPartialReference', 'getRepository']; + + public static function filterTableName(string $method, array $args): mixed + { + if (in_array($method, self::METHODS_ACCEPTING_TABLE_NAME) + && !str_contains($args[0], '\\')) { + return self::$table_map[$args[0]]; + } else { + return $args[0]; + } + } } diff --git a/src/Core/Entity.php b/src/Core/Entity.php index 70c6924946..8959a6d3a9 100644 --- a/src/Core/Entity.php +++ b/src/Core/Entity.php @@ -76,7 +76,7 @@ abstract class Entity /** * Create a new instance, but check for duplicates * - * @return [$obj, $is_update] + * @return array [$obj, $is_update] */ public static function createOrUpdate(array $args, array $find_by_keys = []) { diff --git a/src/Core/GSFile.php b/src/Core/GSFile.php index 74d4a265dd..3d51e220dd 100644 --- a/src/Core/GSFile.php +++ b/src/Core/GSFile.php @@ -30,8 +30,9 @@ use App\Util\Exception\NoSuchFileException; use App\Util\Exception\NotFoundException; use App\Util\Exception\NotStoredLocallyException; use App\Util\Exception\ServerException; -use SplFileInfo; +use App\Util\TemporaryFile; use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Symfony\Component\HttpFoundation\File\File as SymfonyFile; use Symfony\Component\HttpFoundation\HeaderUtils; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Mime\MimeTypes; @@ -52,17 +53,13 @@ class GSFile /** * Perform file validation (checks and normalization), store the given file if needed and increment lives * - * @param SplFileInfo $file - * @param string $dest_dir - * @param null|string $title - * @param bool $is_local - * @param null|int $actor_id + * @param SymfonyFile|TemporaryFile $file * * @throws DuplicateFoundException * * @return Attachment */ - public static function sanitizeAndStoreFileAsAttachment(SplFileInfo $file): Attachment + public static function sanitizeAndStoreFileAsAttachment(TemporaryFile|SymfonyFile $file): Attachment { $hash = null; Event::handle('HashFile', [$file->getPathname(), &$hash]); diff --git a/src/DependencyInjection/Compiler/SchemaDefDriver.php b/src/DependencyInjection/Compiler/SchemaDefDriver.php index 65421ae80d..699979ec73 100644 --- a/src/DependencyInjection/Compiler/SchemaDefDriver.php +++ b/src/DependencyInjection/Compiler/SchemaDefDriver.php @@ -31,7 +31,7 @@ namespace App\DependencyInjection\Compiler; -use Doctrine\Persistence\Mapping\ClassMetadata; +use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver; use Functional as F; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; @@ -88,10 +88,10 @@ class SchemaDefDriver extends StaticPHPDriver implements CompilerPassInterface /** * Fill in the database $metadata for $class_name * - * @param string $class_name - * @param ClassMetadata $metadata + * @param string $class_name + * @param ClassMetadataInfo $metadata */ - public function loadMetadataForClass($class_name, ClassMetadata $metadata) + public function loadMetadataForClass($class_name, $metadata) { $schema = $class_name::schemaDef(); diff --git a/src/Entity/AttachmentThumbnail.php b/src/Entity/AttachmentThumbnail.php index 324f8f09f8..e0a28a39d6 100644 --- a/src/Entity/AttachmentThumbnail.php +++ b/src/Entity/AttachmentThumbnail.php @@ -34,6 +34,7 @@ use App\Util\Exception\ClientException; use App\Util\Exception\NotFoundException; use App\Util\Exception\NotStoredLocallyException; use App\Util\Exception\ServerException; +use App\Util\TemporaryFile; use DateTimeInterface; use Symfony\Component\Mime\MimeTypes; @@ -188,14 +189,17 @@ class AttachmentThumbnail extends Entity $event_map[$major_mime] = []; Event::handle('FileResizerAvailable', [&$event_map, $mimetype]); // Always prefer specific encoders + /** @var callable[] function(string $source, ?TemporaryFile &$destination, int &$width, int &$height, bool $smart_crop, ?string &$mimetype): bool */ $encoders = array_merge($event_map[$mimetype], $event_map[$major_mime]); foreach ($encoders as $encoder) { + /** @var ?TemporaryFile */ $temp = null; // Let the EncoderPlugin create a temporary file for us if ($encoder($attachment->getPath(), $temp, $width, $height, $crop, $mimetype)) { $thumbnail->setAttachment($attachment); $thumbnail->setWidth($predicted_width); $thumbnail->setHeight($predicted_height); - $ext = '.' . MimeTypes::getDefault()->getExtensions($temp->getMimeType())[0]; + $mimetype = $temp->getMimeType(); + $ext = '.' . MimeTypes::getDefault()->getExtensions($mimetype)[0]; $filename = "{$predicted_width}x{$predicted_height}{$ext}-" . $attachment->getFilehash(); $thumbnail->setFilename($filename); $thumbnail->setMimetype($mimetype); @@ -257,11 +261,11 @@ class AttachmentThumbnail extends Entity * Values will scale _up_ to fit max values if cropping is enabled! * With cropping disabled, the max value of each axis will be respected. * - * @param $width int Original width - * @param $height int Original height - * @param $maxW int Resulting max width - * @param $maxH int Resulting max height - * @param $crop bool Crop to the size (not preserving aspect ratio) + * @param int $existing_width Original width + * @param int $existing_height Original height + * @param int $requested_width Resulting max width + * @param int $requested_height Resulting max height + * @param bool $crop Crop to the size (not preserving aspect ratio) * * @return array [predicted width, predicted height] */ diff --git a/src/Entity/Note.php b/src/Entity/Note.php index 5c5d45f920..803b9306f5 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -256,8 +256,6 @@ class Note extends Entity implements \JsonSerializable /** * Whether this note is visible to the given actor - * - * @param mixed $a */ public function isVisibleTo(GSActor | LocalUser $a): bool { diff --git a/src/Security/Authenticator.php b/src/Security/Authenticator.php index babb93c0b9..445cd1c983 100644 --- a/src/Security/Authenticator.php +++ b/src/Security/Authenticator.php @@ -21,6 +21,7 @@ namespace App\Security; use App\Core\DB\DB; use function App\Core\I18n\_m; +use App\Entity\LocalUser; use App\Entity\User; use App\Util\Nickname; use Exception; @@ -31,7 +32,6 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException; use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException; use Symfony\Component\Security\Core\Security; -use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Csrf\CsrfToken; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; @@ -103,7 +103,11 @@ class Authenticator extends AbstractFormLoginAuthenticator return $user; } - public function checkCredentials($credentials, UserInterface $user) + /** + * @param LocalUser $user + * @param mixed $credentials + */ + public function checkCredentials($credentials, $user) { if (!$user->checkPassword($credentials['password'])) { throw new CustomUserMessageAuthenticationException(_m('Invalid login credentials.')); diff --git a/src/Security/EmailVerifier.php b/src/Security/EmailVerifier.php index 416b6c68e0..d453870662 100644 --- a/src/Security/EmailVerifier.php +++ b/src/Security/EmailVerifier.php @@ -2,9 +2,10 @@ namespace App\Security; -use App\Core\Controller; +use App\Controller\ResetPassword; use App\Core\DB\DB; use function App\Core\I18n\_m; +use App\Entity\LocalUser; use App\Util\Common; use App\Util\Exception\NotFoundException; use App\Util\Exception\RedirectException; @@ -12,7 +13,6 @@ use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mime\Address; -use Symfony\Component\Security\Core\User\UserInterface; use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface; use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface; use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface; @@ -36,12 +36,12 @@ abstract class EmailVerifier return self::$reset_password_helper->validateTokenAndFetchUser($token); } - public static function removeResetRequest(string $token) + public static function removeResetRequest(string $token): void { - return self::$reset_password_helper->removeResetRequest($token); + self::$reset_password_helper->removeResetRequest($token); } - public static function sendEmailConfirmation(UserInterface $user): void + public static function sendEmailConfirmation(LocalUser $user): void { $email = (new TemplatedEmail()) ->from(new Address(Common::config('site', 'email'), Common::config('site', 'nickname'))) @@ -64,15 +64,15 @@ abstract class EmailVerifier self::send($email); } - public static function send($email) + public static function send($email): void { - return self::$mailer_helper->send($email); + self::$mailer_helper->send($email); } /** * @throws VerifyEmailExceptionInterface */ - public function handleEmailConfirmation(Request $request, UserInterface $user): void + public function handleEmailConfirmation(Request $request, LocalUser $user): void { self::$verify_email_helper->validateEmailConfirmation($request->getUri(), $user->getId(), $user->getOutgoingEmail()); $user->setIsEmailVerified(true); @@ -80,7 +80,7 @@ abstract class EmailVerifier DB::flush(); } - public static function processSendingPasswordResetEmail(string $emailFormData, Controller $controller) + public static function processSendingPasswordResetEmail(string $emailFormData, ResetPassword $controller) { try { $user = DB::findOneBy('local_user', ['outgoing_email' => $emailFormData]); @@ -103,7 +103,7 @@ abstract class EmailVerifier self::send($email); // Store the token object in session for retrieval in check-email route. - $controller->setTokenObjectInSession($reset_token); + $controller->setInSession($reset_token); throw new RedirectException('check_email'); } diff --git a/src/Util/HTML.php b/src/Util/HTML.php index 94c7a98e6a..db141029dd 100644 --- a/src/Util/HTML.php +++ b/src/Util/HTML.php @@ -84,7 +84,7 @@ abstract class HTML } /** - * @param $html + * @param mixed $html * * @return string */ diff --git a/src/Util/Nickname.php b/src/Util/Nickname.php index 886455c9c8..cc924f7d92 100644 --- a/src/Util/Nickname.php +++ b/src/Util/Nickname.php @@ -22,11 +22,9 @@ namespace App\Util; use App\Entity\LocalUser; -use App\Util\Exception\NicknameBlacklistedException; use App\Util\Exception\NicknameEmptyException; use App\Util\Exception\NicknameException; use App\Util\Exception\NicknameInvalidException; -use App\Util\Exception\NicknamePathCollisionException; use App\Util\Exception\NicknameReservedException; use App\Util\Exception\NicknameTakenException; use App\Util\Exception\NicknameTooLongException; @@ -171,11 +169,9 @@ class Nickname * Normalize an input $nickname, and normalize it to its canonical form. * The canonical form will be returned, or an exception thrown if invalid. * - * @throws NicknameException (base class) - * @throws NicknameBlacklistedException + * @throws NicknameException (base class) * @throws NicknameEmptyException * @throws NicknameInvalidException - * @throws NicknamePathCollisionException * @throws NicknameTakenException * @throws NicknameTooLongException * @throws NicknameTooShortException diff --git a/src/Util/TemporaryFile.php b/src/Util/TemporaryFile.php index c6e5a0b420..9cb9fcc438 100644 --- a/src/Util/TemporaryFile.php +++ b/src/Util/TemporaryFile.php @@ -20,6 +20,7 @@ namespace App\Util; use function App\Core\I18n\_m; +use App\Util\Exception\ServerException; use App\Util\Exception\TemporaryFileException; use Symfony\Component\Mime\MimeTypes;