forked from GNUsocial/gnu-social
[TOOLS] Fix all issues found by PHPStan level 2
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
@@ -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<string, mixed> $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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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 = [])
|
||||
{
|
||||
|
@@ -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]);
|
||||
|
Reference in New Issue
Block a user