From eb0cdf796099dd814adfd7d2c91996d4bcc80b79 Mon Sep 17 00:00:00 2001 From: Johan Kasselman Date: Fri, 4 Aug 2023 10:03:38 +0200 Subject: [PATCH 01/17] 1. Implemented the AsCommand attributes for final $defaultName 2. Removed support for PHP <8.0 3. Reworked the __construct methods to be on-par with php >=8.0 4. Removed all rferences to GetMasterRequest - using only getMainRequest now 5. Fixed custom_uploader.md documentation to use getMainRequest --- composer.json | 2 +- doc/custom_uploader.md | 10 ++-- src/Command/ClearChunkCommand.php | 6 ++- src/Command/ClearOrphansCommand.php | 4 ++ src/Controller/AbstractController.php | 36 +-------------- src/Event/PostChunkUploadEvent.php | 46 +++---------------- src/Event/PostPersistEvent.php | 37 ++------------- src/Event/PostUploadEvent.php | 37 ++------------- src/Event/PreUploadEvent.php | 39 +++------------- src/Event/ValidationEvent.php | 37 ++------------- src/Routing/RouteLoader.php | 9 +--- src/Templating/Helper/UploaderHelper.php | 15 ++---- src/Twig/Extension/UploaderExtension.php | 8 +--- src/Uploader/Chunk/ChunkManager.php | 15 ++---- .../Chunk/Storage/FilesystemStorage.php | 8 +--- .../Chunk/Storage/FlysystemStorage.php | 31 +++---------- .../Chunk/Storage/GaufretteStorage.php | 16 ++----- .../ErrorHandler/BlueimpErrorHandler.php | 8 +--- src/Uploader/File/FlysystemFile.php | 15 ++---- src/Uploader/File/GaufretteFile.php | 14 +++--- src/Uploader/Orphanage/OrphanageManager.php | 14 +----- src/Uploader/Response/AbstractResponse.php | 8 +--- .../Response/FineUploaderResponse.php | 18 ++------ src/Uploader/Response/MooUploadResponse.php | 16 +------ .../Storage/FilesystemOrphanageStorage.php | 30 +++--------- src/Uploader/Storage/FilesystemStorage.php | 8 +--- .../Storage/FlysystemOrphanageStorage.php | 30 +++--------- src/Uploader/Storage/FlysystemStorage.php | 22 ++------- .../Storage/GaufretteOrphanageStorage.php | 30 +++--------- src/Uploader/Storage/GaufretteStorage.php | 9 ++-- 30 files changed, 118 insertions(+), 460 deletions(-) diff --git a/composer.json b/composer.json index f170b073..05b2ecd0 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "symfony/asset": "^4.4 || ^5.4 || ^6.0", "symfony/event-dispatcher-contracts": "^1.0 || ^2.0 || ^3.0", "symfony/finder": "^4.4 || ^5.4 || ^6.0", diff --git a/doc/custom_uploader.md b/doc/custom_uploader.md index 5e267f58..93a3a16f 100644 --- a/doc/custom_uploader.md +++ b/doc/custom_uploader.md @@ -33,14 +33,18 @@ namespace Acme\DemoBundle\Controller; use Symfony\Component\HttpFoundation\File\Exception\UploadException; use Symfony\Component\HttpFoundation\JsonResponse; use Oneup\UploaderBundle\Controller\UploaderController; -use Oneup\UploaderBundle\Uploader\Response\EmptyResponse; +use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;use Symfony\Component\HttpFoundation\RequestStack; class CustomUploader extends UploaderController { + + public function __construct(protected RequestStack $requestStack) { + } + public function upload() { // get some basic stuff together - $request = $this->container->get('request_stack')->getMasterRequest(); + $request = $this->requestStack->getMainRequest(); $response = new EmptyResponse(); // get file from request (your own logic) @@ -100,7 +104,7 @@ class FineUploaderResponse extends AbstractResponse public function assemble() { // explicitly overwrite success and error key - // as these keys are used internaly by the + // as these keys are used internally by the // frontend uploader $data = $this->data; $data['success'] = $this->success; diff --git a/src/Command/ClearChunkCommand.php b/src/Command/ClearChunkCommand.php index 4385071e..eda3ee69 100644 --- a/src/Command/ClearChunkCommand.php +++ b/src/Command/ClearChunkCommand.php @@ -5,14 +5,16 @@ namespace Oneup\UploaderBundle\Command; use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'oneup:uploader:clear-chunks' +)] class ClearChunkCommand extends Command { - protected static $defaultName = 'oneup:uploader:clear-chunks'; // Make command lazy load - /** * @var ChunkManager */ diff --git a/src/Command/ClearOrphansCommand.php b/src/Command/ClearOrphansCommand.php index 80b78141..717c59fc 100644 --- a/src/Command/ClearOrphansCommand.php +++ b/src/Command/ClearOrphansCommand.php @@ -5,10 +5,14 @@ namespace Oneup\UploaderBundle\Command; use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'oneup:uploader:clear-orphans' +)] class ClearOrphansCommand extends Command { protected static $defaultName = 'oneup:uploader:clear-orphans'; diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index 8d77b507..b454d51d 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -24,38 +24,8 @@ abstract class AbstractController { - /** - * @var ErrorHandlerInterface - */ - protected $errorHandler; - - /** - * @var ContainerInterface - */ - protected $container; - - /** - * @var StorageInterface - */ - protected $storage; - - /** - * @var array - */ - protected $config; - - /** - * @var string - */ - protected $type; - - public function __construct(ContainerInterface $container, StorageInterface $storage, ErrorHandlerInterface $errorHandler, array $config, string $type) + public function __construct(protected ContainerInterface $container, protected StorageInterface $storage, protected ErrorHandlerInterface $errorHandler, protected array $config, protected string $type) { - $this->errorHandler = $errorHandler; - $this->container = $container; - $this->storage = $storage; - $this->config = $config; - $this->type = $type; } abstract public function upload(): JsonResponse; @@ -223,9 +193,7 @@ protected function getRequest(): Request $requestStack = $this->container->get('request_stack'); /** @var Request $request */ - $request = method_exists($requestStack, 'getMainRequest') - ? $requestStack->getMainRequest() - : $requestStack->getMasterRequest(); + $request = $requestStack->getMainRequest(); return $request; } diff --git a/src/Event/PostChunkUploadEvent.php b/src/Event/PostChunkUploadEvent.php index 83f9292f..4ab7d1ce 100644 --- a/src/Event/PostChunkUploadEvent.php +++ b/src/Event/PostChunkUploadEvent.php @@ -13,53 +13,21 @@ class PostChunkUploadEvent extends Event { public const NAME = UploadEvents::POST_CHUNK_UPLOAD; - /** - * @var mixed - */ - protected $chunk; - - /** - * @var Request - */ - protected $request; - - /** - * @var string - */ - protected $type; - - /** - * @var ResponseInterface - */ - protected $response; - - /** - * @var array - */ - protected $config; - - /** - * @var bool - */ - protected $isLast; - /** * @param mixed $chunk + * @param ResponseInterface $response + * @param Request $request + * @param bool $isLast + * @param string $type + * @param array $config */ - public function __construct($chunk, ResponseInterface $response, Request $request, bool $isLast, string $type, array $config) - { - $this->chunk = $chunk; - $this->request = $request; - $this->response = $response; - $this->isLast = $isLast; - $this->type = $type; - $this->config = $config; + public function __construct(protected mixed $chunk, protected ResponseInterface $response, protected Request $request, protected bool $isLast, protected string $type, protected array $config) { } /** * @return mixed */ - public function getChunk() + public function getChunk(): mixed { return $this->chunk; } diff --git a/src/Event/PostPersistEvent.php b/src/Event/PostPersistEvent.php index d5db86c6..9a7e98a4 100644 --- a/src/Event/PostPersistEvent.php +++ b/src/Event/PostPersistEvent.php @@ -15,41 +15,14 @@ class PostPersistEvent extends Event { public const NAME = UploadEvents::POST_PERSIST; - /** - * @var FileInterface|File - */ - protected $file; - - /** - * @var Request - */ - protected $request; - - /** - * @var string - */ - protected $type; - - /** - * @var ResponseInterface - */ - protected $response; - - /** - * @var array - */ - protected $config; - /** * @param FileInterface|File $file + * @param ResponseInterface $response + * @param Request $request + * @param string $type + * @param array $config */ - public function __construct($file, ResponseInterface $response, Request $request, string $type, array $config) - { - $this->file = $file; - $this->request = $request; - $this->response = $response; - $this->type = $type; - $this->config = $config; + public function __construct(protected FileInterface|File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) { } /** diff --git a/src/Event/PostUploadEvent.php b/src/Event/PostUploadEvent.php index 31495474..2f68483b 100644 --- a/src/Event/PostUploadEvent.php +++ b/src/Event/PostUploadEvent.php @@ -15,41 +15,14 @@ class PostUploadEvent extends Event { public const NAME = UploadEvents::POST_UPLOAD; - /** - * @var FileInterface|File - */ - protected $file; - - /** - * @var Request - */ - protected $request; - - /** - * @var string - */ - protected $type; - - /** - * @var ResponseInterface - */ - protected $response; - - /** - * @var array - */ - protected $config; - /** * @param FileInterface|File $file + * @param ResponseInterface $response + * @param Request $request + * @param string $type + * @param array $config */ - public function __construct($file, ResponseInterface $response, Request $request, string $type, array $config) - { - $this->file = $file; - $this->request = $request; - $this->response = $response; - $this->type = $type; - $this->config = $config; + public function __construct(protected FileInterface|File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) { } /** diff --git a/src/Event/PreUploadEvent.php b/src/Event/PreUploadEvent.php index 9398907f..7a80a4c1 100644 --- a/src/Event/PreUploadEvent.php +++ b/src/Event/PreUploadEvent.php @@ -16,40 +16,13 @@ class PreUploadEvent extends Event public const NAME = UploadEvents::PRE_UPLOAD; /** - * @var FileInterface|File + * @param File|FileInterface $file + * @param ResponseInterface $response + * @param Request $request + * @param string $type + * @param array $config */ - protected $file; - - /** - * @var Request - */ - protected $request; - - /** - * @var string - */ - protected $type; - - /** - * @var ResponseInterface - */ - protected $response; - - /** - * @var array - */ - protected $config; - - /** - * @param FileInterface|File $file - */ - public function __construct($file, ResponseInterface $response, Request $request, string $type, array $config) - { - $this->file = $file; - $this->request = $request; - $this->response = $response; - $this->type = $type; - $this->config = $config; + public function __construct(protected File|FileInterface $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) { } /** diff --git a/src/Event/ValidationEvent.php b/src/Event/ValidationEvent.php index 1481b00a..24dd4b59 100644 --- a/src/Event/ValidationEvent.php +++ b/src/Event/ValidationEvent.php @@ -15,41 +15,14 @@ class ValidationEvent extends Event { public const NAME = UploadEvents::VALIDATION; - /** - * @var FileInterface|File - */ - protected $file; - - /** - * @var array - */ - protected $config; - - /** - * @var string - */ - protected $type; - - /** - * @var Request - */ - protected $request; - - /** - * @var ResponseInterface|null - */ - protected $response; - /** * @param FileInterface|File $file + * @param Request $request + * @param array $config + * @param string $type + * @param ResponseInterface|null $response */ - public function __construct($file, Request $request, array $config, string $type, ResponseInterface $response = null) - { - $this->file = $file; - $this->config = $config; - $this->type = $type; - $this->request = $request; - $this->response = $response; + public function __construct(protected FileInterface|File $file, protected Request $request, protected array $config, protected string $type, protected ?ResponseInterface $response = null) { } /** diff --git a/src/Routing/RouteLoader.php b/src/Routing/RouteLoader.php index 0f388439..e9aecb85 100644 --- a/src/Routing/RouteLoader.php +++ b/src/Routing/RouteLoader.php @@ -10,14 +10,9 @@ class RouteLoader extends Loader { - /** - * @var array - */ - protected $controllers; - public function __construct(array $controllers) - { - $this->controllers = $controllers; + public function __construct(protected array $controllers) { + parent::__construct(); } /** diff --git a/src/Templating/Helper/UploaderHelper.php b/src/Templating/Helper/UploaderHelper.php index 6fb06644..73c36861 100644 --- a/src/Templating/Helper/UploaderHelper.php +++ b/src/Templating/Helper/UploaderHelper.php @@ -10,19 +10,10 @@ class UploaderHelper extends Helper { /** - * @var RouterInterface + * @param RouterInterface $router + * @param array $maxsize */ - protected $router; - - /** - * @var array - */ - protected $maxsize; - - public function __construct(RouterInterface $router, array $maxsize) - { - $this->router = $router; - $this->maxsize = $maxsize; + public function __construct(protected RouterInterface $router, protected array $maxsize) { } public function getName(): string diff --git a/src/Twig/Extension/UploaderExtension.php b/src/Twig/Extension/UploaderExtension.php index 6e291e60..f0e025b3 100644 --- a/src/Twig/Extension/UploaderExtension.php +++ b/src/Twig/Extension/UploaderExtension.php @@ -11,13 +11,9 @@ class UploaderExtension extends AbstractExtension { /** - * @var UploaderHelper + * @param UploaderHelper $helper */ - protected $helper; - - public function __construct(UploaderHelper $helper) - { - $this->helper = $helper; + public function __construct(protected UploaderHelper $helper){ } public function getName(): string diff --git a/src/Uploader/Chunk/ChunkManager.php b/src/Uploader/Chunk/ChunkManager.php index 9d52e139..892b5e68 100644 --- a/src/Uploader/Chunk/ChunkManager.php +++ b/src/Uploader/Chunk/ChunkManager.php @@ -10,19 +10,10 @@ class ChunkManager implements ChunkManagerInterface { /** - * @var array + * @param array $configuration + * @param ChunkStorageInterface $storage */ - protected $configuration; - - /** - * @var ChunkStorageInterface - */ - protected $storage; - - public function __construct(array $configuration, ChunkStorageInterface $storage) - { - $this->configuration = $configuration; - $this->storage = $storage; + public function __construct(protected array $configuration, protected ChunkStorageInterface $storage) { } public function clear(): void diff --git a/src/Uploader/Chunk/Storage/FilesystemStorage.php b/src/Uploader/Chunk/Storage/FilesystemStorage.php index 760084d5..7d56676c 100644 --- a/src/Uploader/Chunk/Storage/FilesystemStorage.php +++ b/src/Uploader/Chunk/Storage/FilesystemStorage.php @@ -13,13 +13,9 @@ class FilesystemStorage implements ChunkStorageInterface { /** - * @var string + * @param string $directory */ - protected $directory; - - public function __construct(string $directory) - { - $this->directory = $directory; + public function __construct(protected string $directory) { } public function clear(int $maxAge): void diff --git a/src/Uploader/Chunk/Storage/FlysystemStorage.php b/src/Uploader/Chunk/Storage/FlysystemStorage.php index 9b3a6421..b8878292 100644 --- a/src/Uploader/Chunk/Storage/FlysystemStorage.php +++ b/src/Uploader/Chunk/Storage/FlysystemStorage.php @@ -14,36 +14,17 @@ class FlysystemStorage implements ChunkStorageInterface { /** - * @var int - */ - public $bufferSize; - - /** - * @var array + * @var array|null */ protected $unhandledChunk; /** - * @var string - */ - protected $prefix; - - /** - * @var string + * @param Filesystem $filesystem + * @param int $bufferSize + * @param string $streamWrapperPrefix + * @param string $prefix */ - protected $streamWrapperPrefix; - - /** - * @var FilesystemOperator - */ - private $filesystem; - - public function __construct(Filesystem $filesystem, int $bufferSize, string $streamWrapperPrefix, string $prefix) - { - $this->filesystem = $filesystem; - $this->bufferSize = $bufferSize; - $this->prefix = $prefix; - $this->streamWrapperPrefix = $streamWrapperPrefix; + public function __construct(protected Filesystem $filesystem, public int $bufferSize, protected string $streamWrapperPrefix, protected string $prefix) { } public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): void diff --git a/src/Uploader/Chunk/Storage/GaufretteStorage.php b/src/Uploader/Chunk/Storage/GaufretteStorage.php index 581adeac..ebc24d8c 100644 --- a/src/Uploader/Chunk/Storage/GaufretteStorage.php +++ b/src/Uploader/Chunk/Storage/GaufretteStorage.php @@ -21,16 +21,12 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface protected $unhandledChunk; /** - * @var string + * @param FilesystemInterface $filesystem + * @param int $bufferSize + * @param string|null $streamWrapperPrefix + * @param string $prefix */ - protected $prefix; - - /** - * @var string|null - */ - protected $streamWrapperPrefix; - - public function __construct(FilesystemInterface $filesystem, int $bufferSize, ?string $streamWrapperPrefix, string $prefix) + public function __construct(FilesystemInterface $filesystem, int $bufferSize, protected ?string $streamWrapperPrefix, protected string $prefix) { $base = interface_exists(FilesystemInterface::class) ? FilesystemInterface::class @@ -45,8 +41,6 @@ public function __construct(FilesystemInterface $filesystem, int $bufferSize, ?s } $this->filesystem = $filesystem; $this->buffersize = $bufferSize; - $this->prefix = $prefix; - $this->streamWrapperPrefix = $streamWrapperPrefix; } /** diff --git a/src/Uploader/ErrorHandler/BlueimpErrorHandler.php b/src/Uploader/ErrorHandler/BlueimpErrorHandler.php index 2af40b46..e2a46665 100644 --- a/src/Uploader/ErrorHandler/BlueimpErrorHandler.php +++ b/src/Uploader/ErrorHandler/BlueimpErrorHandler.php @@ -11,13 +11,9 @@ class BlueimpErrorHandler implements ErrorHandlerInterface { /** - * @var TranslatorInterface + * @param TranslatorInterface $translator */ - private $translator; - - public function __construct(TranslatorInterface $translator) - { - $this->translator = $translator; + public function __construct(private TranslatorInterface $translator){ } public function addException(AbstractResponse $response, Exception $exception): void diff --git a/src/Uploader/File/FlysystemFile.php b/src/Uploader/File/FlysystemFile.php index ab179a95..b3cb6752 100644 --- a/src/Uploader/File/FlysystemFile.php +++ b/src/Uploader/File/FlysystemFile.php @@ -9,16 +9,11 @@ class FlysystemFile implements FileInterface { - /** @var string */ - private $pathname; - - /** @var FilesystemOperator */ - private $filesystem; - - public function __construct(string $pathname, FilesystemOperator $filesystem) - { - $this->pathname = $pathname; - $this->filesystem = $filesystem; + /** + * @param string $pathname + * @param FilesystemOperator $filesystem + */ + public function __construct(private string $pathname, private FilesystemOperator $filesystem) { } /** diff --git a/src/Uploader/File/GaufretteFile.php b/src/Uploader/File/GaufretteFile.php index 82c76645..198c7c55 100644 --- a/src/Uploader/File/GaufretteFile.php +++ b/src/Uploader/File/GaufretteFile.php @@ -11,21 +11,19 @@ class GaufretteFile extends File implements FileInterface { - /** - * @var string|null - */ - protected $streamWrapperPrefix; - /** * @var string */ protected $mimeType; - public function __construct(File $file, FilesystemInterface $filesystem, string $streamWrapperPrefix = null) + /** + * @param File $file + * @param FilesystemInterface $filesystem + * @param string|null $streamWrapperPrefix + */ + public function __construct(File $file, FilesystemInterface $filesystem, protected ?string $streamWrapperPrefix = null) { parent::__construct($file->getKey(), $filesystem); - - $this->streamWrapperPrefix = $streamWrapperPrefix; } /** diff --git a/src/Uploader/Orphanage/OrphanageManager.php b/src/Uploader/Orphanage/OrphanageManager.php index 8a15620d..6d7aa35c 100644 --- a/src/Uploader/Orphanage/OrphanageManager.php +++ b/src/Uploader/Orphanage/OrphanageManager.php @@ -12,20 +12,8 @@ class OrphanageManager { - /** - * @var ContainerInterface - */ - protected $container; - - /** - * @var array - */ - protected $config; - public function __construct(ContainerInterface $container, array $config) - { - $this->container = $container; - $this->config = $config; + public function __construct(protected ContainerInterface $container, protected array $config) { } public function has(string $key): bool diff --git a/src/Uploader/Response/AbstractResponse.php b/src/Uploader/Response/AbstractResponse.php index e2507e05..f6af027e 100644 --- a/src/Uploader/Response/AbstractResponse.php +++ b/src/Uploader/Response/AbstractResponse.php @@ -7,13 +7,9 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface { /** - * @var array + * @param array $data */ - protected $data; - - public function __construct() - { - $this->data = []; + public function __construct(protected array $data = []){ } /** diff --git a/src/Uploader/Response/FineUploaderResponse.php b/src/Uploader/Response/FineUploaderResponse.php index 907a7bca..8fdce58a 100644 --- a/src/Uploader/Response/FineUploaderResponse.php +++ b/src/Uploader/Response/FineUploaderResponse.php @@ -7,27 +7,17 @@ class FineUploaderResponse extends AbstractResponse { /** - * @var bool + * @param bool $success + * @param string|null $error */ - protected $success; - - /** - * @var string|null - */ - protected $error; - - public function __construct() - { - $this->success = true; - $this->error = null; - + public function __construct(protected bool $success = true, protected ?string $error = null) { parent::__construct(); } public function assemble(): array { // explicitly overwrite success and error key - // as these keys are used internaly by the + // as these keys are used internally by the // frontend uploader $data = $this->data; $data['success'] = $this->success; diff --git a/src/Uploader/Response/MooUploadResponse.php b/src/Uploader/Response/MooUploadResponse.php index f566c9ca..af72defb 100644 --- a/src/Uploader/Response/MooUploadResponse.php +++ b/src/Uploader/Response/MooUploadResponse.php @@ -21,26 +21,12 @@ class MooUploadResponse extends AbstractResponse */ protected $size; - /** - * @var int - */ - protected $error; - - /** - * @var bool - */ - protected $finish; - /** * @var string */ protected $uploadedName; - public function __construct() - { - $this->finish = true; - $this->error = 0; - + public function __construct(protected bool $finish = true, protected int $error = 0) { parent::__construct(); } diff --git a/src/Uploader/Storage/FilesystemOrphanageStorage.php b/src/Uploader/Storage/FilesystemOrphanageStorage.php index 7ed19a37..b3227932 100644 --- a/src/Uploader/Storage/FilesystemOrphanageStorage.php +++ b/src/Uploader/Storage/FilesystemOrphanageStorage.php @@ -15,43 +15,25 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageStorageInterface { - /** - * @var StorageInterface - */ - protected $storage; - /** * @var SessionInterface */ protected $session; /** - * @var ChunkStorage - */ - protected $chunkStorage; - - /** - * @var array + * @param StorageInterface $storage + * @param RequestStack $requestStack + * @param ChunkStorage $chunkStorage + * @param array $config + * @param string $type */ - protected $config; - - /** - * @var string - */ - protected $type; - - public function __construct(StorageInterface $storage, RequestStack $requestStack, ChunkStorage $chunkStorage, array $config, string $type) + public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected ChunkStorage $chunkStorage, protected array $config, protected string $type) { parent::__construct($config['directory']); /** @var Request $request */ $request = $requestStack->getCurrentRequest(); - - $this->storage = $storage; $this->session = $request->getSession(); - $this->chunkStorage = $chunkStorage; - $this->config = $config; - $this->type = $type; } /** diff --git a/src/Uploader/Storage/FilesystemStorage.php b/src/Uploader/Storage/FilesystemStorage.php index 3bcd28c9..781d54e7 100644 --- a/src/Uploader/Storage/FilesystemStorage.php +++ b/src/Uploader/Storage/FilesystemStorage.php @@ -11,13 +11,9 @@ class FilesystemStorage implements StorageInterface { /** - * @var string + * @param string $directory */ - protected $directory; - - public function __construct(string $directory) - { - $this->directory = $directory; + public function __construct(protected string $directory){ } /** diff --git a/src/Uploader/Storage/FlysystemOrphanageStorage.php b/src/Uploader/Storage/FlysystemOrphanageStorage.php index 49307c88..ce4addb3 100644 --- a/src/Uploader/Storage/FlysystemOrphanageStorage.php +++ b/src/Uploader/Storage/FlysystemOrphanageStorage.php @@ -16,32 +16,19 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageStorageInterface { - /** - * @var StorageInterface - */ - protected $storage; - /** * @var SessionInterface */ protected $session; /** - * @var ChunkStorage - */ - protected $chunkStorage; - - /** - * @var array + * @param StorageInterface $storage + * @param RequestStack $requestStack + * @param ChunkStorage $chunkStorage + * @param array $config + * @param string $type */ - protected $config; - - /** - * @var string - */ - protected $type; - - public function __construct(StorageInterface $storage, RequestStack $requestStack, ChunkStorage $chunkStorage, array $config, string $type) + public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected ChunkStorage $chunkStorage, protected array $config, protected string $type) { /* * initiate the storage on the chunk storage's filesystem @@ -51,12 +38,7 @@ public function __construct(StorageInterface $storage, RequestStack $requestStac /** @var Request $request */ $request = $requestStack->getCurrentRequest(); - - $this->storage = $storage; - $this->chunkStorage = $chunkStorage; $this->session = $request->getSession(); - $this->config = $config; - $this->type = $type; } /** diff --git a/src/Uploader/Storage/FlysystemStorage.php b/src/Uploader/Storage/FlysystemStorage.php index 854757dd..3ae2f1a4 100644 --- a/src/Uploader/Storage/FlysystemStorage.php +++ b/src/Uploader/Storage/FlysystemStorage.php @@ -15,25 +15,11 @@ class FlysystemStorage implements StorageInterface { /** - * @var string|null + * @param FilesystemOperator $filesystem + * @param int $bufferSize + * @param string|null $streamWrapperPrefix */ - protected $streamWrapperPrefix; - - /** - * @var int - */ - protected $bufferSize; - - /** - * @var FilesystemOperator - */ - private $filesystem; - - public function __construct(FilesystemOperator $filesystem, int $bufferSize, ?string $streamWrapperPrefix = null) - { - $this->filesystem = $filesystem; - $this->bufferSize = $bufferSize; - $this->streamWrapperPrefix = $streamWrapperPrefix; + public function __construct(private FilesystemOperator $filesystem, protected int $bufferSize, protected ?string $streamWrapperPrefix = null) { } /** diff --git a/src/Uploader/Storage/GaufretteOrphanageStorage.php b/src/Uploader/Storage/GaufretteOrphanageStorage.php index cfab590b..5a0a5e4b 100644 --- a/src/Uploader/Storage/GaufretteOrphanageStorage.php +++ b/src/Uploader/Storage/GaufretteOrphanageStorage.php @@ -14,32 +14,19 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageStorageInterface { - /** - * @var StorageInterface - */ - protected $storage; - /** * @var SessionInterface */ protected $session; /** - * @var GaufretteChunkStorage - */ - protected $chunkStorage; - - /** - * @var array + * @param StorageInterface $storage + * @param RequestStack $requestStack + * @param GaufretteChunkStorage $chunkStorage + * @param array $config + * @param string $type */ - protected $config; - - /** - * @var string - */ - protected $type; - - public function __construct(StorageInterface $storage, RequestStack $requestStack, GaufretteChunkStorage $chunkStorage, array $config, string $type) + public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected GaufretteChunkStorage $chunkStorage, protected array $config, protected string $type) { /* * initiate the storage on the chunk storage's filesystem @@ -49,12 +36,7 @@ public function __construct(StorageInterface $storage, RequestStack $requestStac /** @var Request $request */ $request = $requestStack->getCurrentRequest(); - - $this->storage = $storage; - $this->chunkStorage = $chunkStorage; $this->session = $request->getSession(); - $this->config = $config; - $this->type = $type; } /** diff --git a/src/Uploader/Storage/GaufretteStorage.php b/src/Uploader/Storage/GaufretteStorage.php index 98e02671..1f598cf7 100644 --- a/src/Uploader/Storage/GaufretteStorage.php +++ b/src/Uploader/Storage/GaufretteStorage.php @@ -15,11 +15,11 @@ class GaufretteStorage extends StreamManager implements StorageInterface { /** - * @var string|null + * @param FilesystemInterface $filesystem + * @param int $bufferSize + * @param string|null $streamWrapperPrefix */ - protected $streamWrapperPrefix; - - public function __construct(FilesystemInterface $filesystem, int $bufferSize, ?string $streamWrapperPrefix = null) + public function __construct(FilesystemInterface $filesystem, int $bufferSize, protected ?string $streamWrapperPrefix = null) { $base = interface_exists(FilesystemInterface::class) ? FilesystemInterface::class @@ -31,7 +31,6 @@ public function __construct(FilesystemInterface $filesystem, int $bufferSize, ?s $this->filesystem = $filesystem; $this->buffersize = $bufferSize; - $this->streamWrapperPrefix = $streamWrapperPrefix; } /** From 9cda6c32e304068b0aa3f75617fb14b6871ad41a Mon Sep 17 00:00:00 2001 From: Johan Kasselman Date: Fri, 4 Aug 2023 10:16:22 +0200 Subject: [PATCH 02/17] Changed the ci.yml fot gihub actions --- .github/workflows/ci.yml | 134 +++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b04960fa..8c35c6f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,80 +1,80 @@ name: CI on: - pull_request: ~ - push: - branches: - - master - tags: - - '*' + pull_request: ~ + push: + branches: + - master + tags: + - '*' jobs: - coding-style: - name: Coding Style - runs-on: ubuntu-latest - steps: - - name: Setup PHP - uses: shivammathur/setup-php@2.9.0 - with: - php-version: 7.4 - extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo, zlib - coverage: none + coding-style: + name: Coding Style + runs-on: ubuntu-latest + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo, zlib + coverage: none - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v3 - - name: Install the dependencies - run: composer install --no-interaction --no-suggest - - name: Check the coding style - run: vendor/bin/php-cs-fixer fix --diff --dry-run - - name: Analyze the code - run: vendor/bin/phpstan analyze src/ tests/ --level=max + - name: Install the dependencies + run: composer install --no-interaction --no-suggest + - name: Check the coding style + run: vendor/bin/php-cs-fixer fix --diff --dry-run + - name: Analyze the code + run: vendor/bin/phpstan analyze - tests: - name: PHP ${{ matrix.php }} / SF ^${{ matrix.symfony }} - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - php: [7.4, 8.0] - symfony: [4.4, 5.4, 6.0] - exclude: - # Symfony 6.0 does not supports php <8.0 - - php: 7.4 - symfony: 6.0 - steps: - - name: Setup PHP - uses: shivammathur/setup-php@2.9.0 - with: - php-version: ${{ matrix.php }} - extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib - coverage: none + tests: + name: PHP ${{ matrix.php }} / SF ^${{ matrix.symfony }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: [8.0, 8.1] + symfony: [5.4, 6.0, 6.1] + exclude: + # Symfony 6.1 does not support php <8.1 + - php: 8.0 + symfony: 6.1 + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib + coverage: none - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v3 - - name: Install the dependencies - run: | - composer require symfony/framework-bundle:^${{ matrix.symfony }} symfony/http-foundation:^${{ matrix.symfony }} - composer install --no-interaction --no-suggest - - name: Run the unit tests - run: vendor/bin/phpunit --colors=always + - name: Install the dependencies + run: | + composer require symfony/framework-bundle:^${{ matrix.symfony }} symfony/http-foundation:^${{ matrix.symfony }} + composer install --no-interaction --no-suggest + - name: Run the unit tests + run: vendor/bin/phpunit --colors=always - prefer-lowest: - name: Prefer Lowest - runs-on: ubuntu-latest - steps: - - name: Setup PHP - uses: shivammathur/setup-php@2.7.0 - with: - php-version: 7.4 - extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib - coverage: none + prefer-lowest: + name: Prefer Lowest + runs-on: ubuntu-latest + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib + coverage: none - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v3 - - name: Install the dependencies - run: composer update --prefer-lowest --prefer-stable --no-interaction --no-suggest - - name: Run the unit tests - run: vendor/bin/phpunit --colors=always + - name: Install the dependencies + run: composer update --prefer-lowest --prefer-stable --no-interaction --no-suggest + - name: Run the unit tests + run: vendor/bin/phpunit --colors=always \ No newline at end of file From 32f19d9b24d5825b018afea580ac1ba32086ee2c Mon Sep 17 00:00:00 2001 From: Johan Kasselman Date: Fri, 4 Aug 2023 10:20:02 +0200 Subject: [PATCH 03/17] Ran php cs fixer for code style Reran testes, all passes --- .../OneupUploaderExtension.php | 4 ++-- src/Event/PostChunkUploadEvent.php | 16 +++++++--------- src/Event/PostPersistEvent.php | 11 ++++++----- src/Event/PostUploadEvent.php | 11 ++++++----- src/Event/PreUploadEvent.php | 11 ++++++----- src/Event/ValidationEvent.php | 11 ++++++----- src/Routing/RouteLoader.php | 4 ++-- src/Templating/Helper/UploaderHelper.php | 5 +++-- src/Twig/Extension/UploaderExtension.php | 3 ++- src/Uploader/Chunk/ChunkManager.php | 5 +++-- src/Uploader/Chunk/Storage/FilesystemStorage.php | 3 ++- src/Uploader/Chunk/Storage/FlysystemStorage.php | 9 +++++---- src/Uploader/Chunk/Storage/GaufretteStorage.php | 4 +--- .../ErrorHandler/BlueimpErrorHandler.php | 3 ++- src/Uploader/File/FlysystemFile.php | 5 +++-- src/Uploader/File/GaufretteFile.php | 2 -- src/Uploader/Orphanage/OrphanageManager.php | 4 ++-- src/Uploader/Response/AbstractResponse.php | 3 ++- src/Uploader/Response/FineUploaderResponse.php | 5 +++-- src/Uploader/Response/MooUploadResponse.php | 3 ++- .../Storage/FilesystemOrphanageStorage.php | 7 +++---- src/Uploader/Storage/FilesystemStorage.php | 3 ++- .../Storage/FlysystemOrphanageStorage.php | 7 +++---- src/Uploader/Storage/FlysystemStorage.php | 7 ++++--- .../Storage/GaufretteOrphanageStorage.php | 7 +++---- src/Uploader/Storage/GaufretteStorage.php | 4 +--- 26 files changed, 81 insertions(+), 76 deletions(-) diff --git a/src/DependencyInjection/OneupUploaderExtension.php b/src/DependencyInjection/OneupUploaderExtension.php index 56195e54..da8e0bcf 100644 --- a/src/DependencyInjection/OneupUploaderExtension.php +++ b/src/DependencyInjection/OneupUploaderExtension.php @@ -81,7 +81,7 @@ protected function processOrphanageConfig(): void ; } - protected function processMapping(string $key, array &$mapping): array + protected function processMapping(string $key, array & $mapping): array { $mapping['max_size'] = $mapping['max_size'] < 0 || \is_string($mapping['max_size']) ? $this->getMaxUploadSize($mapping['max_size']) : @@ -188,7 +188,7 @@ protected function createChunkStorageService(): void } } - protected function createStorageService(array &$config, string $key, bool $orphanage = false): Reference + protected function createStorageService(array & $config, string $key, bool $orphanage = false): Reference { $storageService = null; diff --git a/src/Event/PostChunkUploadEvent.php b/src/Event/PostChunkUploadEvent.php index 4ab7d1ce..691993d9 100644 --- a/src/Event/PostChunkUploadEvent.php +++ b/src/Event/PostChunkUploadEvent.php @@ -14,19 +14,17 @@ class PostChunkUploadEvent extends Event public const NAME = UploadEvents::POST_CHUNK_UPLOAD; /** - * @param mixed $chunk + * @param mixed $chunk * @param ResponseInterface $response - * @param Request $request - * @param bool $isLast - * @param string $type - * @param array $config + * @param Request $request + * @param bool $isLast + * @param string $type + * @param array $config */ - public function __construct(protected mixed $chunk, protected ResponseInterface $response, protected Request $request, protected bool $isLast, protected string $type, protected array $config) { + public function __construct(protected mixed $chunk, protected ResponseInterface $response, protected Request $request, protected bool $isLast, protected string $type, protected array $config) + { } - /** - * @return mixed - */ public function getChunk(): mixed { return $this->chunk; diff --git a/src/Event/PostPersistEvent.php b/src/Event/PostPersistEvent.php index 9a7e98a4..156eea88 100644 --- a/src/Event/PostPersistEvent.php +++ b/src/Event/PostPersistEvent.php @@ -17,12 +17,13 @@ class PostPersistEvent extends Event /** * @param FileInterface|File $file - * @param ResponseInterface $response - * @param Request $request - * @param string $type - * @param array $config + * @param ResponseInterface $response + * @param Request $request + * @param string $type + * @param array $config */ - public function __construct(protected FileInterface|File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) { + public function __construct(protected FileInterface | File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) + { } /** diff --git a/src/Event/PostUploadEvent.php b/src/Event/PostUploadEvent.php index 2f68483b..7e58b9fe 100644 --- a/src/Event/PostUploadEvent.php +++ b/src/Event/PostUploadEvent.php @@ -17,12 +17,13 @@ class PostUploadEvent extends Event /** * @param FileInterface|File $file - * @param ResponseInterface $response - * @param Request $request - * @param string $type - * @param array $config + * @param ResponseInterface $response + * @param Request $request + * @param string $type + * @param array $config */ - public function __construct(protected FileInterface|File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) { + public function __construct(protected FileInterface | File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) + { } /** diff --git a/src/Event/PreUploadEvent.php b/src/Event/PreUploadEvent.php index 7a80a4c1..ccac59f3 100644 --- a/src/Event/PreUploadEvent.php +++ b/src/Event/PreUploadEvent.php @@ -17,12 +17,13 @@ class PreUploadEvent extends Event /** * @param File|FileInterface $file - * @param ResponseInterface $response - * @param Request $request - * @param string $type - * @param array $config + * @param ResponseInterface $response + * @param Request $request + * @param string $type + * @param array $config */ - public function __construct(protected File|FileInterface $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) { + public function __construct(protected File | FileInterface $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) + { } /** diff --git a/src/Event/ValidationEvent.php b/src/Event/ValidationEvent.php index 24dd4b59..97304d9f 100644 --- a/src/Event/ValidationEvent.php +++ b/src/Event/ValidationEvent.php @@ -16,13 +16,14 @@ class ValidationEvent extends Event public const NAME = UploadEvents::VALIDATION; /** - * @param FileInterface|File $file - * @param Request $request - * @param array $config - * @param string $type + * @param FileInterface|File $file + * @param Request $request + * @param array $config + * @param string $type * @param ResponseInterface|null $response */ - public function __construct(protected FileInterface|File $file, protected Request $request, protected array $config, protected string $type, protected ?ResponseInterface $response = null) { + public function __construct(protected FileInterface | File $file, protected Request $request, protected array $config, protected string $type, protected ?ResponseInterface $response = null) + { } /** diff --git a/src/Routing/RouteLoader.php b/src/Routing/RouteLoader.php index e9aecb85..5b4da560 100644 --- a/src/Routing/RouteLoader.php +++ b/src/Routing/RouteLoader.php @@ -10,8 +10,8 @@ class RouteLoader extends Loader { - - public function __construct(protected array $controllers) { + public function __construct(protected array $controllers) + { parent::__construct(); } diff --git a/src/Templating/Helper/UploaderHelper.php b/src/Templating/Helper/UploaderHelper.php index 73c36861..7392f5be 100644 --- a/src/Templating/Helper/UploaderHelper.php +++ b/src/Templating/Helper/UploaderHelper.php @@ -11,9 +11,10 @@ class UploaderHelper extends Helper { /** * @param RouterInterface $router - * @param array $maxsize + * @param array $maxsize */ - public function __construct(protected RouterInterface $router, protected array $maxsize) { + public function __construct(protected RouterInterface $router, protected array $maxsize) + { } public function getName(): string diff --git a/src/Twig/Extension/UploaderExtension.php b/src/Twig/Extension/UploaderExtension.php index f0e025b3..e87fedbd 100644 --- a/src/Twig/Extension/UploaderExtension.php +++ b/src/Twig/Extension/UploaderExtension.php @@ -13,7 +13,8 @@ class UploaderExtension extends AbstractExtension /** * @param UploaderHelper $helper */ - public function __construct(protected UploaderHelper $helper){ + public function __construct(protected UploaderHelper $helper) + { } public function getName(): string diff --git a/src/Uploader/Chunk/ChunkManager.php b/src/Uploader/Chunk/ChunkManager.php index 892b5e68..e91ae4dc 100644 --- a/src/Uploader/Chunk/ChunkManager.php +++ b/src/Uploader/Chunk/ChunkManager.php @@ -10,10 +10,11 @@ class ChunkManager implements ChunkManagerInterface { /** - * @param array $configuration + * @param array $configuration * @param ChunkStorageInterface $storage */ - public function __construct(protected array $configuration, protected ChunkStorageInterface $storage) { + public function __construct(protected array $configuration, protected ChunkStorageInterface $storage) + { } public function clear(): void diff --git a/src/Uploader/Chunk/Storage/FilesystemStorage.php b/src/Uploader/Chunk/Storage/FilesystemStorage.php index 7d56676c..e9a9ca25 100644 --- a/src/Uploader/Chunk/Storage/FilesystemStorage.php +++ b/src/Uploader/Chunk/Storage/FilesystemStorage.php @@ -15,7 +15,8 @@ class FilesystemStorage implements ChunkStorageInterface /** * @param string $directory */ - public function __construct(protected string $directory) { + public function __construct(protected string $directory) + { } public function clear(int $maxAge): void diff --git a/src/Uploader/Chunk/Storage/FlysystemStorage.php b/src/Uploader/Chunk/Storage/FlysystemStorage.php index b8878292..9f8f3a09 100644 --- a/src/Uploader/Chunk/Storage/FlysystemStorage.php +++ b/src/Uploader/Chunk/Storage/FlysystemStorage.php @@ -20,11 +20,12 @@ class FlysystemStorage implements ChunkStorageInterface /** * @param Filesystem $filesystem - * @param int $bufferSize - * @param string $streamWrapperPrefix - * @param string $prefix + * @param int $bufferSize + * @param string $streamWrapperPrefix + * @param string $prefix */ - public function __construct(protected Filesystem $filesystem, public int $bufferSize, protected string $streamWrapperPrefix, protected string $prefix) { + public function __construct(protected Filesystem $filesystem, public int $bufferSize, protected string $streamWrapperPrefix, protected string $prefix) + { } public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): void diff --git a/src/Uploader/Chunk/Storage/GaufretteStorage.php b/src/Uploader/Chunk/Storage/GaufretteStorage.php index ebc24d8c..9392b94c 100644 --- a/src/Uploader/Chunk/Storage/GaufretteStorage.php +++ b/src/Uploader/Chunk/Storage/GaufretteStorage.php @@ -21,10 +21,8 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface protected $unhandledChunk; /** - * @param FilesystemInterface $filesystem - * @param int $bufferSize * @param string|null $streamWrapperPrefix - * @param string $prefix + * @param string $prefix */ public function __construct(FilesystemInterface $filesystem, int $bufferSize, protected ?string $streamWrapperPrefix, protected string $prefix) { diff --git a/src/Uploader/ErrorHandler/BlueimpErrorHandler.php b/src/Uploader/ErrorHandler/BlueimpErrorHandler.php index e2a46665..01b3f11c 100644 --- a/src/Uploader/ErrorHandler/BlueimpErrorHandler.php +++ b/src/Uploader/ErrorHandler/BlueimpErrorHandler.php @@ -13,7 +13,8 @@ class BlueimpErrorHandler implements ErrorHandlerInterface /** * @param TranslatorInterface $translator */ - public function __construct(private TranslatorInterface $translator){ + public function __construct(private TranslatorInterface $translator) + { } public function addException(AbstractResponse $response, Exception $exception): void diff --git a/src/Uploader/File/FlysystemFile.php b/src/Uploader/File/FlysystemFile.php index b3cb6752..e26622c9 100644 --- a/src/Uploader/File/FlysystemFile.php +++ b/src/Uploader/File/FlysystemFile.php @@ -10,10 +10,11 @@ class FlysystemFile implements FileInterface { /** - * @param string $pathname + * @param string $pathname * @param FilesystemOperator $filesystem */ - public function __construct(private string $pathname, private FilesystemOperator $filesystem) { + public function __construct(private string $pathname, private FilesystemOperator $filesystem) + { } /** diff --git a/src/Uploader/File/GaufretteFile.php b/src/Uploader/File/GaufretteFile.php index 198c7c55..656ce938 100644 --- a/src/Uploader/File/GaufretteFile.php +++ b/src/Uploader/File/GaufretteFile.php @@ -17,8 +17,6 @@ class GaufretteFile extends File implements FileInterface protected $mimeType; /** - * @param File $file - * @param FilesystemInterface $filesystem * @param string|null $streamWrapperPrefix */ public function __construct(File $file, FilesystemInterface $filesystem, protected ?string $streamWrapperPrefix = null) diff --git a/src/Uploader/Orphanage/OrphanageManager.php b/src/Uploader/Orphanage/OrphanageManager.php index 6d7aa35c..500e6f16 100644 --- a/src/Uploader/Orphanage/OrphanageManager.php +++ b/src/Uploader/Orphanage/OrphanageManager.php @@ -12,8 +12,8 @@ class OrphanageManager { - - public function __construct(protected ContainerInterface $container, protected array $config) { + public function __construct(protected ContainerInterface $container, protected array $config) + { } public function has(string $key): bool diff --git a/src/Uploader/Response/AbstractResponse.php b/src/Uploader/Response/AbstractResponse.php index f6af027e..2cf2ed91 100644 --- a/src/Uploader/Response/AbstractResponse.php +++ b/src/Uploader/Response/AbstractResponse.php @@ -9,7 +9,8 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface /** * @param array $data */ - public function __construct(protected array $data = []){ + public function __construct(protected array $data = []) + { } /** diff --git a/src/Uploader/Response/FineUploaderResponse.php b/src/Uploader/Response/FineUploaderResponse.php index 8fdce58a..bb9c9fe2 100644 --- a/src/Uploader/Response/FineUploaderResponse.php +++ b/src/Uploader/Response/FineUploaderResponse.php @@ -7,10 +7,11 @@ class FineUploaderResponse extends AbstractResponse { /** - * @param bool $success + * @param bool $success * @param string|null $error */ - public function __construct(protected bool $success = true, protected ?string $error = null) { + public function __construct(protected bool $success = true, protected ?string $error = null) + { parent::__construct(); } diff --git a/src/Uploader/Response/MooUploadResponse.php b/src/Uploader/Response/MooUploadResponse.php index af72defb..af8f66a9 100644 --- a/src/Uploader/Response/MooUploadResponse.php +++ b/src/Uploader/Response/MooUploadResponse.php @@ -26,7 +26,8 @@ class MooUploadResponse extends AbstractResponse */ protected $uploadedName; - public function __construct(protected bool $finish = true, protected int $error = 0) { + public function __construct(protected bool $finish = true, protected int $error = 0) + { parent::__construct(); } diff --git a/src/Uploader/Storage/FilesystemOrphanageStorage.php b/src/Uploader/Storage/FilesystemOrphanageStorage.php index b3227932..0decbc51 100644 --- a/src/Uploader/Storage/FilesystemOrphanageStorage.php +++ b/src/Uploader/Storage/FilesystemOrphanageStorage.php @@ -22,10 +22,9 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageS /** * @param StorageInterface $storage - * @param RequestStack $requestStack - * @param ChunkStorage $chunkStorage - * @param array $config - * @param string $type + * @param ChunkStorage $chunkStorage + * @param array $config + * @param string $type */ public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected ChunkStorage $chunkStorage, protected array $config, protected string $type) { diff --git a/src/Uploader/Storage/FilesystemStorage.php b/src/Uploader/Storage/FilesystemStorage.php index 781d54e7..40f6fee6 100644 --- a/src/Uploader/Storage/FilesystemStorage.php +++ b/src/Uploader/Storage/FilesystemStorage.php @@ -13,7 +13,8 @@ class FilesystemStorage implements StorageInterface /** * @param string $directory */ - public function __construct(protected string $directory){ + public function __construct(protected string $directory) + { } /** diff --git a/src/Uploader/Storage/FlysystemOrphanageStorage.php b/src/Uploader/Storage/FlysystemOrphanageStorage.php index ce4addb3..6134249d 100644 --- a/src/Uploader/Storage/FlysystemOrphanageStorage.php +++ b/src/Uploader/Storage/FlysystemOrphanageStorage.php @@ -23,10 +23,9 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto /** * @param StorageInterface $storage - * @param RequestStack $requestStack - * @param ChunkStorage $chunkStorage - * @param array $config - * @param string $type + * @param ChunkStorage $chunkStorage + * @param array $config + * @param string $type */ public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected ChunkStorage $chunkStorage, protected array $config, protected string $type) { diff --git a/src/Uploader/Storage/FlysystemStorage.php b/src/Uploader/Storage/FlysystemStorage.php index 3ae2f1a4..ff4806d0 100644 --- a/src/Uploader/Storage/FlysystemStorage.php +++ b/src/Uploader/Storage/FlysystemStorage.php @@ -16,10 +16,11 @@ class FlysystemStorage implements StorageInterface { /** * @param FilesystemOperator $filesystem - * @param int $bufferSize - * @param string|null $streamWrapperPrefix + * @param int $bufferSize + * @param string|null $streamWrapperPrefix */ - public function __construct(private FilesystemOperator $filesystem, protected int $bufferSize, protected ?string $streamWrapperPrefix = null) { + public function __construct(private FilesystemOperator $filesystem, protected int $bufferSize, protected ?string $streamWrapperPrefix = null) + { } /** diff --git a/src/Uploader/Storage/GaufretteOrphanageStorage.php b/src/Uploader/Storage/GaufretteOrphanageStorage.php index 5a0a5e4b..d5b0e145 100644 --- a/src/Uploader/Storage/GaufretteOrphanageStorage.php +++ b/src/Uploader/Storage/GaufretteOrphanageStorage.php @@ -20,11 +20,10 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto protected $session; /** - * @param StorageInterface $storage - * @param RequestStack $requestStack + * @param StorageInterface $storage * @param GaufretteChunkStorage $chunkStorage - * @param array $config - * @param string $type + * @param array $config + * @param string $type */ public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected GaufretteChunkStorage $chunkStorage, protected array $config, protected string $type) { diff --git a/src/Uploader/Storage/GaufretteStorage.php b/src/Uploader/Storage/GaufretteStorage.php index 1f598cf7..91af3fb6 100644 --- a/src/Uploader/Storage/GaufretteStorage.php +++ b/src/Uploader/Storage/GaufretteStorage.php @@ -15,11 +15,9 @@ class GaufretteStorage extends StreamManager implements StorageInterface { /** - * @param FilesystemInterface $filesystem - * @param int $bufferSize * @param string|null $streamWrapperPrefix */ - public function __construct(FilesystemInterface $filesystem, int $bufferSize, protected ?string $streamWrapperPrefix = null) + public function __construct(FilesystemInterface $filesystem, int $bufferSize, protected ?string $streamWrapperPrefix = null) { $base = interface_exists(FilesystemInterface::class) ? FilesystemInterface::class From 2b6072702448576b172c5f71737d09328821312b Mon Sep 17 00:00:00 2001 From: Johan Kasselman Date: Fri, 4 Aug 2023 10:36:41 +0200 Subject: [PATCH 04/17] Updated php_cs_fixer to v4 Changed the config file to work with the new version Ran php_cs_fixer on codebase Tests still pass --- .github/workflows/ci.yml | 4 ++-- .php_cs.dist => .php-cs-fixer.dist.php | 14 +++++------- composer.json | 2 +- src/Controller/AbstractController.php | 20 ++++++++--------- src/Controller/BlueimpController.php | 4 ++-- src/Controller/DropzoneController.php | 2 +- src/DependencyInjection/Configuration.php | 4 +--- .../OneupUploaderExtension.php | 22 +++++++------------ src/Event/PostChunkUploadEvent.php | 8 ------- src/Event/PostPersistEvent.php | 9 +------- src/Event/PostUploadEvent.php | 9 +------- src/Event/PreUploadEvent.php | 9 +------- src/Event/ValidationEvent.php | 9 +------- src/Routing/RouteLoader.php | 2 -- src/Templating/Helper/UploaderHelper.php | 9 +------- src/Twig/Extension/UploaderExtension.php | 6 ----- src/Uploader/Chunk/ChunkManager.php | 4 ---- src/Uploader/Chunk/ChunkManagerInterface.php | 11 ++-------- .../Chunk/Storage/ChunkStorageInterface.php | 11 ---------- .../Chunk/Storage/FilesystemStorage.php | 3 --- .../Chunk/Storage/FlysystemStorage.php | 8 +------ .../Chunk/Storage/GaufretteStorage.php | 6 +---- .../ErrorHandler/BlueimpErrorHandler.php | 6 +---- .../ErrorHandler/DropzoneErrorHandler.php | 3 +-- .../ErrorHandler/ErrorHandlerInterface.php | 3 +-- .../ErrorHandler/NoopErrorHandler.php | 3 +-- .../ErrorHandler/PluploadErrorHandler.php | 3 +-- src/Uploader/File/FileInterface.php | 3 --- src/Uploader/File/FlysystemFile.php | 4 ---- src/Uploader/File/GaufretteFile.php | 3 --- src/Uploader/Response/AbstractResponse.php | 17 -------------- .../Response/FineUploaderResponse.php | 4 ---- src/Uploader/Response/MooUploadResponse.php | 9 -------- .../Storage/FilesystemOrphanageStorage.php | 15 +++++-------- src/Uploader/Storage/FilesystemStorage.php | 3 --- .../Storage/FlysystemOrphanageStorage.php | 6 ----- src/Uploader/Storage/FlysystemStorage.php | 5 ----- .../Storage/GaufretteOrphanageStorage.php | 6 ----- src/Uploader/Storage/GaufretteStorage.php | 5 +---- tests/Controller/AbstractUploadTest.php | 3 --- tests/Controller/AbstractValidationTest.php | 16 ++------------ tests/Controller/BlueimpValidationTest.php | 4 ++-- tests/Controller/FileBagExtractorTest.php | 3 --- .../OneupUploaderExtensionTest.php | 4 ++-- tests/Uploader/File/FilesystemFileTest.php | 2 +- tests/Uploader/File/GaufretteFileTest.php | 2 +- tests/Uploader/Naming/UrlSafeNamerTest.php | 2 +- .../Storage/FlysystemOrphanageStorageTest.php | 2 +- .../Storage/GaufretteAmazonS3StorageTest.php | 6 ++--- .../Storage/GaufretteOrphanageStorageTest.php | 4 ++-- tests/bootstrap.php | 14 ++++++------ 51 files changed, 72 insertions(+), 264 deletions(-) rename .php_cs.dist => .php-cs-fixer.dist.php (84%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c35c6f5..d1a58fcf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: uses: actions/checkout@v3 - name: Install the dependencies - run: composer install --no-interaction --no-suggest + run: composer install --no-interaction - name: Check the coding style run: vendor/bin/php-cs-fixer fix --diff --dry-run - name: Analyze the code @@ -75,6 +75,6 @@ jobs: uses: actions/checkout@v3 - name: Install the dependencies - run: composer update --prefer-lowest --prefer-stable --no-interaction --no-suggest + run: composer update --prefer-lowest --prefer-stable --no-interaction - name: Run the unit tests run: vendor/bin/phpunit --colors=always \ No newline at end of file diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 84% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 428e683f..9b9b5f77 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -1,17 +1,19 @@ in([__DIR__ . '/src', __DIR__ . '/tests']) ->exclude(['App/cache', 'App/var']) ; -return PhpCsFixer\Config::create() +$config = new Config(); +return $config ->setRules([ '@DoctrineAnnotation' => true, '@Symfony' => true, '@Symfony:risky' => true, - '@PHP71Migration' => true, - '@PHP71Migration:risky' => true, + '@PHP80Migration' => true, + '@PHP80Migration:risky' => true, '@PHPUnit60Migration:risky' => true, '@PHPUnit75Migration:risky' => true, 'align_multiline_comment' => true, @@ -21,11 +23,7 @@ ], 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, - 'general_phpdoc_annotation_remove' => [ - 'author', - 'expectedException', - 'expectedExceptionMessage', - ], + 'general_phpdoc_annotation_remove' => true, 'heredoc_to_nowdoc' => true, 'linebreak_after_opening_tag' => true, 'list_syntax' => ['syntax' => 'short'], diff --git a/composer.json b/composer.json index 05b2ecd0..dc0257de 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ "amazonwebservices/aws-sdk-for-php": "1.5.*", "doctrine/common": "^2.12 || ^3.0", "doctrine/doctrine-bundle": "^2.4", - "friendsofphp/php-cs-fixer": "^2.16", + "friendsofphp/php-cs-fixer": "3.22.*", "knplabs/gaufrette": "^0.9", "oneup/flysystem-bundle": "^4.1", "phpstan/phpstan": "^0.12.10", diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index b454d51d..be85c1a0 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -36,8 +36,8 @@ public function progress(): JsonResponse $session = $request->getSession(); - $prefix = (string) ini_get('session.upload_progress.prefix'); - $name = (string) ini_get('session.upload_progress.name'); + $prefix = (string) \ini_get('session.upload_progress.prefix'); + $name = (string) \ini_get('session.upload_progress.name'); // assemble session key // ref: http://php.net/manual/en/session.upload-progress.php @@ -53,8 +53,8 @@ public function cancel(): JsonResponse $session = $request->getSession(); - $prefix = (string) ini_get('session.upload_progress.prefix'); - $name = (string) ini_get('session.upload_progress.name'); + $prefix = (string) \ini_get('session.upload_progress.prefix'); + $name = (string) \ini_get('session.upload_progress.name'); $key = sprintf('%s.%s', $prefix, $request->get($name)); @@ -97,7 +97,7 @@ protected function getFiles(FileBag $bag): array * * Note: The return value differs when * - * @param mixed $file The file to upload + * @param mixed $file The file to upload */ protected function handleUpload($file, ResponseInterface $response, Request $request): void { @@ -126,9 +126,9 @@ protected function handleUpload($file, ResponseInterface $response, Request $req /** * This function is a helper function which dispatches pre upload event. * - * @param FileInterface $uploaded the uploaded file - * @param ResponseInterface $response a response object - * @param Request $request the request object + * @param FileInterface $uploaded the uploaded file + * @param ResponseInterface $response a response object + * @param Request $request the request object */ protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInterface $response, Request $request): void { @@ -142,7 +142,7 @@ protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInter * This function is a helper function which dispatches post upload * and post persist events. * - * @param mixed $uploaded the uploaded file + * @param mixed $uploaded the uploaded file */ protected function dispatchPostEvents($uploaded, ResponseInterface $response, Request $request): void { @@ -171,8 +171,6 @@ protected function validate(FileInterface $file, Request $request, ResponseInter * * On top of that, if the client does not support the application/json type, * then the content type of the response will be set to text/plain instead. - * - * @param mixed $data */ protected function createSupportedJsonResponse($data, int $statusCode = 200): JsonResponse { diff --git a/src/Controller/BlueimpController.php b/src/Controller/BlueimpController.php index aa1c7783..5c53ae0c 100644 --- a/src/Controller/BlueimpController.php +++ b/src/Controller/BlueimpController.php @@ -39,8 +39,8 @@ public function progress(): JsonResponse $session = $request->getSession(); - $prefix = (string) ini_get('session.upload_progress.prefix'); - $name = (string) ini_get('session.upload_progress.name'); + $prefix = (string) \ini_get('session.upload_progress.prefix'); + $name = (string) \ini_get('session.upload_progress.name'); // ref: https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-Session-Upload-Progress $key = sprintf('%s.%s', $prefix, $request->get($name)); diff --git a/src/Controller/DropzoneController.php b/src/Controller/DropzoneController.php index 3b642f81..da6a15ed 100644 --- a/src/Controller/DropzoneController.php +++ b/src/Controller/DropzoneController.php @@ -29,7 +29,7 @@ public function upload(): JsonResponse $this->handleUpload($file, $response, $request) ; } catch (UploadException $e) { - $statusCode = 500; //Dropzone displays error if HTTP response is 40x or 50x + $statusCode = 500; // Dropzone displays error if HTTP response is 40x or 50x $this->errorHandler->addException($response, $e); /** @var TranslatorInterface $translator */ diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index ae0ac4ac..e8fff458 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -106,9 +106,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->prototype('scalar') ->beforeNormalization() ->ifString() - ->then(function ($v) { - return strtolower($v); - }) + ->then(fn ($v) => strtolower($v)) ->end() ->end() ->end() diff --git a/src/DependencyInjection/OneupUploaderExtension.php b/src/DependencyInjection/OneupUploaderExtension.php index da8e0bcf..bcff9c74 100644 --- a/src/DependencyInjection/OneupUploaderExtension.php +++ b/src/DependencyInjection/OneupUploaderExtension.php @@ -81,7 +81,7 @@ protected function processOrphanageConfig(): void ; } - protected function processMapping(string $key, array & $mapping): array + protected function processMapping(string $key, array &$mapping): array { $mapping['max_size'] = $mapping['max_size'] < 0 || \is_string($mapping['max_size']) ? $this->getMaxUploadSize($mapping['max_size']) : @@ -188,7 +188,7 @@ protected function createChunkStorageService(): void } } - protected function createStorageService(array & $config, string $key, bool $orphanage = false): Reference + protected function createStorageService(array &$config, string $key, bool $orphanage = false): Reference { $storageService = null; @@ -271,7 +271,7 @@ protected function registerFilesystem(string $type, string $key, string $class, break; } - if (\strlen($filesystem) <= 0) { + if ('' === $filesystem) { throw new ServiceNotFoundException('Empty service name'); } @@ -285,14 +285,11 @@ protected function registerFilesystem(string $type, string $key, string $class, ->addArgument($prefix); } - /** - * @param mixed $input - */ protected function getMaxUploadSize($input): int { $input = $this->getValueInBytes($input); - $maxPost = $this->getValueInBytes(ini_get('upload_max_filesize')); - $maxFile = $this->getValueInBytes(ini_get('post_max_size')); + $maxPost = $this->getValueInBytes(\ini_get('upload_max_filesize')); + $maxFile = $this->getValueInBytes(\ini_get('post_max_size')); if ($input < 0) { return min($maxPost, $maxFile); @@ -301,9 +298,6 @@ protected function getMaxUploadSize($input): int return min(min($input, $maxPost), $maxFile); } - /** - * @param mixed $input - */ protected function getValueInBytes($input): int { // see: http://www.php.net/manual/en/function.ini-get.php @@ -313,12 +307,12 @@ protected function getValueInBytes($input): int switch ($last) { case 'g': $numericInput *= 1024; - // no break + // no break case 'm': $numericInput *= 1024; - // no break + // no break case 'k': $numericInput *= 1024; - return (int) $numericInput; + return (int) $numericInput; } return (int) $input; diff --git a/src/Event/PostChunkUploadEvent.php b/src/Event/PostChunkUploadEvent.php index 691993d9..fe2014e9 100644 --- a/src/Event/PostChunkUploadEvent.php +++ b/src/Event/PostChunkUploadEvent.php @@ -13,14 +13,6 @@ class PostChunkUploadEvent extends Event { public const NAME = UploadEvents::POST_CHUNK_UPLOAD; - /** - * @param mixed $chunk - * @param ResponseInterface $response - * @param Request $request - * @param bool $isLast - * @param string $type - * @param array $config - */ public function __construct(protected mixed $chunk, protected ResponseInterface $response, protected Request $request, protected bool $isLast, protected string $type, protected array $config) { } diff --git a/src/Event/PostPersistEvent.php b/src/Event/PostPersistEvent.php index 156eea88..5cc6b60b 100644 --- a/src/Event/PostPersistEvent.php +++ b/src/Event/PostPersistEvent.php @@ -15,14 +15,7 @@ class PostPersistEvent extends Event { public const NAME = UploadEvents::POST_PERSIST; - /** - * @param FileInterface|File $file - * @param ResponseInterface $response - * @param Request $request - * @param string $type - * @param array $config - */ - public function __construct(protected FileInterface | File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) + public function __construct(protected FileInterface|File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) { } diff --git a/src/Event/PostUploadEvent.php b/src/Event/PostUploadEvent.php index 7e58b9fe..f1b575c7 100644 --- a/src/Event/PostUploadEvent.php +++ b/src/Event/PostUploadEvent.php @@ -15,14 +15,7 @@ class PostUploadEvent extends Event { public const NAME = UploadEvents::POST_UPLOAD; - /** - * @param FileInterface|File $file - * @param ResponseInterface $response - * @param Request $request - * @param string $type - * @param array $config - */ - public function __construct(protected FileInterface | File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) + public function __construct(protected FileInterface|File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) { } diff --git a/src/Event/PreUploadEvent.php b/src/Event/PreUploadEvent.php index ccac59f3..158be01a 100644 --- a/src/Event/PreUploadEvent.php +++ b/src/Event/PreUploadEvent.php @@ -15,14 +15,7 @@ class PreUploadEvent extends Event { public const NAME = UploadEvents::PRE_UPLOAD; - /** - * @param File|FileInterface $file - * @param ResponseInterface $response - * @param Request $request - * @param string $type - * @param array $config - */ - public function __construct(protected File | FileInterface $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) + public function __construct(protected File|FileInterface $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config) { } diff --git a/src/Event/ValidationEvent.php b/src/Event/ValidationEvent.php index 97304d9f..d41a05b1 100644 --- a/src/Event/ValidationEvent.php +++ b/src/Event/ValidationEvent.php @@ -15,14 +15,7 @@ class ValidationEvent extends Event { public const NAME = UploadEvents::VALIDATION; - /** - * @param FileInterface|File $file - * @param Request $request - * @param array $config - * @param string $type - * @param ResponseInterface|null $response - */ - public function __construct(protected FileInterface | File $file, protected Request $request, protected array $config, protected string $type, protected ?ResponseInterface $response = null) + public function __construct(protected FileInterface|File $file, protected Request $request, protected array $config, protected string $type, protected ?ResponseInterface $response = null) { } diff --git a/src/Routing/RouteLoader.php b/src/Routing/RouteLoader.php index 5b4da560..8a61adcd 100644 --- a/src/Routing/RouteLoader.php +++ b/src/Routing/RouteLoader.php @@ -16,7 +16,6 @@ public function __construct(protected array $controllers) } /** - * @param mixed $resource * @param string|null $type */ public function supports($resource, $type = null): bool @@ -25,7 +24,6 @@ public function supports($resource, $type = null): bool } /** - * @param mixed $resource * @param string|null $type */ public function load($resource, $type = null): RouteCollection diff --git a/src/Templating/Helper/UploaderHelper.php b/src/Templating/Helper/UploaderHelper.php index 7392f5be..d6f0a0b0 100644 --- a/src/Templating/Helper/UploaderHelper.php +++ b/src/Templating/Helper/UploaderHelper.php @@ -9,10 +9,6 @@ class UploaderHelper extends Helper { - /** - * @param RouterInterface $router - * @param array $maxsize - */ public function __construct(protected RouterInterface $router, protected array $maxsize) { } @@ -39,12 +35,9 @@ public function cancel(string $key): string public function uploadKey(): string { - return (string) ini_get('session.upload_progress.name'); + return (string) \ini_get('session.upload_progress.name'); } - /** - * @return mixed - */ public function maxSize(string $key) { if (!\array_key_exists($key, $this->maxsize)) { diff --git a/src/Twig/Extension/UploaderExtension.php b/src/Twig/Extension/UploaderExtension.php index e87fedbd..8eda3eb0 100644 --- a/src/Twig/Extension/UploaderExtension.php +++ b/src/Twig/Extension/UploaderExtension.php @@ -10,9 +10,6 @@ class UploaderExtension extends AbstractExtension { - /** - * @param UploaderHelper $helper - */ public function __construct(protected UploaderHelper $helper) { } @@ -53,9 +50,6 @@ public function uploadKey(): string return $this->helper->uploadKey(); } - /** - * @return mixed - */ public function maxSize(string $key) { return $this->helper->maxSize($key); diff --git a/src/Uploader/Chunk/ChunkManager.php b/src/Uploader/Chunk/ChunkManager.php index e91ae4dc..67f414a1 100644 --- a/src/Uploader/Chunk/ChunkManager.php +++ b/src/Uploader/Chunk/ChunkManager.php @@ -9,10 +9,6 @@ class ChunkManager implements ChunkManagerInterface { - /** - * @param array $configuration - * @param ChunkStorageInterface $storage - */ public function __construct(protected array $configuration, protected ChunkStorageInterface $storage) { } diff --git a/src/Uploader/Chunk/ChunkManagerInterface.php b/src/Uploader/Chunk/ChunkManagerInterface.php index 579d4065..b53540ac 100644 --- a/src/Uploader/Chunk/ChunkManagerInterface.php +++ b/src/Uploader/Chunk/ChunkManagerInterface.php @@ -11,26 +11,19 @@ interface ChunkManagerInterface { /** * Adds a new Chunk to a given uuid. - * - * @return mixed */ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original); /** * Assembles the given chunks and return the resulting file. * - * @param mixed $chunks - * @param bool $removeChunk remove the chunk file once its assembled - * @param bool $renameChunk rename the chunk file once its assembled - * - * @return mixed + * @param bool $removeChunk remove the chunk file once its assembled + * @param bool $renameChunk rename the chunk file once its assembled */ public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false); /** * Get chunks associated with the given uuid. - * - * @return mixed */ public function getChunks(string $uuid); diff --git a/src/Uploader/Chunk/Storage/ChunkStorageInterface.php b/src/Uploader/Chunk/Storage/ChunkStorageInterface.php index 5d4bfc3e..00af3c2b 100644 --- a/src/Uploader/Chunk/Storage/ChunkStorageInterface.php +++ b/src/Uploader/Chunk/Storage/ChunkStorageInterface.php @@ -10,22 +10,11 @@ interface ChunkStorageInterface { public function clear(int $maxAge): void; - /** - * @return mixed - */ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original); - /** - * @param mixed $chunks - * - * @return mixed - */ public function assembleChunks($chunks, bool $removeChunk, bool $renameChunk); public function cleanup(string $path): void; - /** - * @return mixed - */ public function getChunks(string $uuid); } diff --git a/src/Uploader/Chunk/Storage/FilesystemStorage.php b/src/Uploader/Chunk/Storage/FilesystemStorage.php index e9a9ca25..4262bf34 100644 --- a/src/Uploader/Chunk/Storage/FilesystemStorage.php +++ b/src/Uploader/Chunk/Storage/FilesystemStorage.php @@ -12,9 +12,6 @@ class FilesystemStorage implements ChunkStorageInterface { - /** - * @param string $directory - */ public function __construct(protected string $directory) { } diff --git a/src/Uploader/Chunk/Storage/FlysystemStorage.php b/src/Uploader/Chunk/Storage/FlysystemStorage.php index 9f8f3a09..57b6e7a9 100644 --- a/src/Uploader/Chunk/Storage/FlysystemStorage.php +++ b/src/Uploader/Chunk/Storage/FlysystemStorage.php @@ -18,12 +18,6 @@ class FlysystemStorage implements ChunkStorageInterface */ protected $unhandledChunk; - /** - * @param Filesystem $filesystem - * @param int $bufferSize - * @param string $streamWrapperPrefix - * @param string $prefix - */ public function __construct(protected Filesystem $filesystem, public int $bufferSize, protected string $streamWrapperPrefix, protected string $prefix) { } @@ -150,7 +144,7 @@ public function getChunks(string $uuid): array $uuid = basename($uuid); return $this->filesystem->listContents($this->prefix . '/' . $uuid) - ->filter(function (StorageAttributes $attributes) { return $attributes->isFile(); }) + ->filter(fn (StorageAttributes $attributes) => $attributes->isFile()) ->sortByPath() ->map(function (StorageAttributes $attributes) { return [ diff --git a/src/Uploader/Chunk/Storage/GaufretteStorage.php b/src/Uploader/Chunk/Storage/GaufretteStorage.php index 9392b94c..e622cd21 100644 --- a/src/Uploader/Chunk/Storage/GaufretteStorage.php +++ b/src/Uploader/Chunk/Storage/GaufretteStorage.php @@ -20,10 +20,6 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface */ protected $unhandledChunk; - /** - * @param string|null $streamWrapperPrefix - * @param string $prefix - */ public function __construct(FilesystemInterface $filesystem, int $bufferSize, protected ?string $streamWrapperPrefix, protected string $prefix) { $base = interface_exists(FilesystemInterface::class) @@ -31,7 +27,7 @@ public function __construct(FilesystemInterface $filesystem, int $bufferSize, pr : Filesystem::class; if (!$filesystem instanceof $base) { - throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, \get_class($filesystem))); + throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, $filesystem::class)); } if ($filesystem instanceof Filesystem && !($filesystem->getAdapter() instanceof StreamFactory)) { diff --git a/src/Uploader/ErrorHandler/BlueimpErrorHandler.php b/src/Uploader/ErrorHandler/BlueimpErrorHandler.php index 01b3f11c..3fd3f407 100644 --- a/src/Uploader/ErrorHandler/BlueimpErrorHandler.php +++ b/src/Uploader/ErrorHandler/BlueimpErrorHandler.php @@ -4,20 +4,16 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler; -use Exception; use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; use Symfony\Contracts\Translation\TranslatorInterface; class BlueimpErrorHandler implements ErrorHandlerInterface { - /** - * @param TranslatorInterface $translator - */ public function __construct(private TranslatorInterface $translator) { } - public function addException(AbstractResponse $response, Exception $exception): void + public function addException(AbstractResponse $response, \Exception $exception): void { $message = $this->translator->trans($exception->getMessage(), [], 'OneupUploaderBundle'); $response->addToOffset(['error' => $message], ['files']); diff --git a/src/Uploader/ErrorHandler/DropzoneErrorHandler.php b/src/Uploader/ErrorHandler/DropzoneErrorHandler.php index f1d578dc..3430f1f1 100755 --- a/src/Uploader/ErrorHandler/DropzoneErrorHandler.php +++ b/src/Uploader/ErrorHandler/DropzoneErrorHandler.php @@ -4,12 +4,11 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler; -use Exception; use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; class DropzoneErrorHandler implements ErrorHandlerInterface { - public function addException(AbstractResponse $response, Exception $exception): void + public function addException(AbstractResponse $response, \Exception $exception): void { $errors[] = $exception; $message = $exception->getMessage(); diff --git a/src/Uploader/ErrorHandler/ErrorHandlerInterface.php b/src/Uploader/ErrorHandler/ErrorHandlerInterface.php index a1b3571a..28875e4d 100644 --- a/src/Uploader/ErrorHandler/ErrorHandlerInterface.php +++ b/src/Uploader/ErrorHandler/ErrorHandlerInterface.php @@ -4,10 +4,9 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler; -use Exception; use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; interface ErrorHandlerInterface { - public function addException(AbstractResponse $response, Exception $exception): void; + public function addException(AbstractResponse $response, \Exception $exception): void; } diff --git a/src/Uploader/ErrorHandler/NoopErrorHandler.php b/src/Uploader/ErrorHandler/NoopErrorHandler.php index 71826d3b..57dea366 100644 --- a/src/Uploader/ErrorHandler/NoopErrorHandler.php +++ b/src/Uploader/ErrorHandler/NoopErrorHandler.php @@ -4,12 +4,11 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler; -use Exception; use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; class NoopErrorHandler implements ErrorHandlerInterface { - public function addException(AbstractResponse $response, Exception $exception): void + public function addException(AbstractResponse $response, \Exception $exception): void { // noop } diff --git a/src/Uploader/ErrorHandler/PluploadErrorHandler.php b/src/Uploader/ErrorHandler/PluploadErrorHandler.php index 6d4c0d7a..1ad33e79 100644 --- a/src/Uploader/ErrorHandler/PluploadErrorHandler.php +++ b/src/Uploader/ErrorHandler/PluploadErrorHandler.php @@ -4,12 +4,11 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler; -use Exception; use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; class PluploadErrorHandler implements ErrorHandlerInterface { - public function addException(AbstractResponse $response, Exception $exception): void + public function addException(AbstractResponse $response, \Exception $exception): void { /* Plupload only needs an error message so it can be handled client side */ $message = $exception->getMessage(); diff --git a/src/Uploader/File/FileInterface.php b/src/Uploader/File/FileInterface.php index cea4878d..a303552f 100644 --- a/src/Uploader/File/FileInterface.php +++ b/src/Uploader/File/FileInterface.php @@ -55,8 +55,5 @@ public function getBasename(); */ public function getExtension(): string; - /** - * @return mixed - */ public function getFileSystem(); } diff --git a/src/Uploader/File/FlysystemFile.php b/src/Uploader/File/FlysystemFile.php index e26622c9..6e51a1c4 100644 --- a/src/Uploader/File/FlysystemFile.php +++ b/src/Uploader/File/FlysystemFile.php @@ -9,10 +9,6 @@ class FlysystemFile implements FileInterface { - /** - * @param string $pathname - * @param FilesystemOperator $filesystem - */ public function __construct(private string $pathname, private FilesystemOperator $filesystem) { } diff --git a/src/Uploader/File/GaufretteFile.php b/src/Uploader/File/GaufretteFile.php index 656ce938..b8eda299 100644 --- a/src/Uploader/File/GaufretteFile.php +++ b/src/Uploader/File/GaufretteFile.php @@ -16,9 +16,6 @@ class GaufretteFile extends File implements FileInterface */ protected $mimeType; - /** - * @param string|null $streamWrapperPrefix - */ public function __construct(File $file, FilesystemInterface $filesystem, protected ?string $streamWrapperPrefix = null) { parent::__construct($file->getKey(), $filesystem); diff --git a/src/Uploader/Response/AbstractResponse.php b/src/Uploader/Response/AbstractResponse.php index 2cf2ed91..e7fe0801 100644 --- a/src/Uploader/Response/AbstractResponse.php +++ b/src/Uploader/Response/AbstractResponse.php @@ -6,41 +6,26 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface { - /** - * @param array $data - */ public function __construct(protected array $data = []) { } - /** - * @param mixed $offset - * @param mixed $value - */ public function offsetSet($offset, $value): void { null === $offset ? $this->data[] = $value : $this->data[$offset] = $value; } - /** - * @param mixed $offset - */ public function offsetExists($offset): bool { return isset($this->data[$offset]); } - /** - * @param mixed $offset - */ public function offsetUnset($offset): void { unset($this->data[$offset]); } /** - * @param mixed $offset - * * @return mixed|null */ #[\ReturnTypeWillChange] @@ -53,8 +38,6 @@ public function offsetGet($offset) * The \ArrayAccess interface does not support multi-dimensional array syntax such as $array["foo"][] = bar * This function will take a path of arrays and add a new element to it, creating the path if needed. * - * @param mixed $value - * * @throws \InvalidArgumentException if the path contains non-array items */ public function addToOffset($value, array $offsets): void diff --git a/src/Uploader/Response/FineUploaderResponse.php b/src/Uploader/Response/FineUploaderResponse.php index bb9c9fe2..b37b3101 100644 --- a/src/Uploader/Response/FineUploaderResponse.php +++ b/src/Uploader/Response/FineUploaderResponse.php @@ -6,10 +6,6 @@ class FineUploaderResponse extends AbstractResponse { - /** - * @param bool $success - * @param string|null $error - */ public function __construct(protected bool $success = true, protected ?string $error = null) { parent::__construct(); diff --git a/src/Uploader/Response/MooUploadResponse.php b/src/Uploader/Response/MooUploadResponse.php index af8f66a9..1f5b7387 100644 --- a/src/Uploader/Response/MooUploadResponse.php +++ b/src/Uploader/Response/MooUploadResponse.php @@ -45,9 +45,6 @@ public function assemble(): array return $data; } - /** - * @param mixed $id - */ public function setId($id): self { $this->id = $id; @@ -55,9 +52,6 @@ public function setId($id): self return $this; } - /** - * @return mixed - */ public function getId() { return $this->id; @@ -75,9 +69,6 @@ public function getName(): ?string return $this->name; } - /** - * @param mixed $size - */ public function setSize($size): self { $this->size = (int) $size; diff --git a/src/Uploader/Storage/FilesystemOrphanageStorage.php b/src/Uploader/Storage/FilesystemOrphanageStorage.php index 0decbc51..83cfaa1a 100644 --- a/src/Uploader/Storage/FilesystemOrphanageStorage.php +++ b/src/Uploader/Storage/FilesystemOrphanageStorage.php @@ -20,12 +20,6 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageS */ protected $session; - /** - * @param StorageInterface $storage - * @param ChunkStorage $chunkStorage - * @param array $config - * @param string $type - */ public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected ChunkStorage $chunkStorage, protected array $config, protected string $type) { parent::__construct($config['directory']); @@ -61,7 +55,8 @@ public function uploadFiles(array $files = null): array foreach ($files as $file) { $return[] = $this->storage->upload( new FilesystemFile(new File($file->getPathname())), - ltrim(str_replace($this->getFindPath(), '', (string) $file), '/')); + ltrim(str_replace($this->getFindPath(), '', (string) $file), '/') + ); } return $return; @@ -77,10 +72,10 @@ public function getFiles(): Finder try { $finder->in($this->getFindPath())->files(); } catch (\InvalidArgumentException $e) { - //catch non-existing directory exception. - //This can happen if getFiles is called and no file has yet been uploaded + // catch non-existing directory exception. + // This can happen if getFiles is called and no file has yet been uploaded - //push empty array into the finder so we can emulate no files found + // push empty array into the finder so we can emulate no files found $finder->append([]); } diff --git a/src/Uploader/Storage/FilesystemStorage.php b/src/Uploader/Storage/FilesystemStorage.php index 40f6fee6..a67f7a20 100644 --- a/src/Uploader/Storage/FilesystemStorage.php +++ b/src/Uploader/Storage/FilesystemStorage.php @@ -10,9 +10,6 @@ class FilesystemStorage implements StorageInterface { - /** - * @param string $directory - */ public function __construct(protected string $directory) { } diff --git a/src/Uploader/Storage/FlysystemOrphanageStorage.php b/src/Uploader/Storage/FlysystemOrphanageStorage.php index 6134249d..9f51f63d 100644 --- a/src/Uploader/Storage/FlysystemOrphanageStorage.php +++ b/src/Uploader/Storage/FlysystemOrphanageStorage.php @@ -21,12 +21,6 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto */ protected $session; - /** - * @param StorageInterface $storage - * @param ChunkStorage $chunkStorage - * @param array $config - * @param string $type - */ public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected ChunkStorage $chunkStorage, protected array $config, protected string $type) { /* diff --git a/src/Uploader/Storage/FlysystemStorage.php b/src/Uploader/Storage/FlysystemStorage.php index ff4806d0..4636e260 100644 --- a/src/Uploader/Storage/FlysystemStorage.php +++ b/src/Uploader/Storage/FlysystemStorage.php @@ -14,11 +14,6 @@ class FlysystemStorage implements StorageInterface { - /** - * @param FilesystemOperator $filesystem - * @param int $bufferSize - * @param string|null $streamWrapperPrefix - */ public function __construct(private FilesystemOperator $filesystem, protected int $bufferSize, protected ?string $streamWrapperPrefix = null) { } diff --git a/src/Uploader/Storage/GaufretteOrphanageStorage.php b/src/Uploader/Storage/GaufretteOrphanageStorage.php index d5b0e145..bac1a926 100644 --- a/src/Uploader/Storage/GaufretteOrphanageStorage.php +++ b/src/Uploader/Storage/GaufretteOrphanageStorage.php @@ -19,12 +19,6 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto */ protected $session; - /** - * @param StorageInterface $storage - * @param GaufretteChunkStorage $chunkStorage - * @param array $config - * @param string $type - */ public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected GaufretteChunkStorage $chunkStorage, protected array $config, protected string $type) { /* diff --git a/src/Uploader/Storage/GaufretteStorage.php b/src/Uploader/Storage/GaufretteStorage.php index 91af3fb6..ea2cd830 100644 --- a/src/Uploader/Storage/GaufretteStorage.php +++ b/src/Uploader/Storage/GaufretteStorage.php @@ -14,9 +14,6 @@ class GaufretteStorage extends StreamManager implements StorageInterface { - /** - * @param string|null $streamWrapperPrefix - */ public function __construct(FilesystemInterface $filesystem, int $bufferSize, protected ?string $streamWrapperPrefix = null) { $base = interface_exists(FilesystemInterface::class) @@ -24,7 +21,7 @@ public function __construct(FilesystemInterface $filesystem, int $bufferSize, pr : Filesystem::class; if (!$filesystem instanceof $base) { - throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, \get_class($filesystem))); + throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, $filesystem::class)); } $this->filesystem = $filesystem; diff --git a/tests/Controller/AbstractUploadTest.php b/tests/Controller/AbstractUploadTest.php index aef114ab..1dda249d 100644 --- a/tests/Controller/AbstractUploadTest.php +++ b/tests/Controller/AbstractUploadTest.php @@ -87,8 +87,5 @@ public function testEvents(): void abstract protected function getRequestParameters(): array; - /** - * @return mixed - */ abstract protected function getRequestFile(); } diff --git a/tests/Controller/AbstractValidationTest.php b/tests/Controller/AbstractValidationTest.php index 8b9803a7..81586a40 100644 --- a/tests/Controller/AbstractValidationTest.php +++ b/tests/Controller/AbstractValidationTest.php @@ -18,7 +18,7 @@ public function testAgainstMaxSize(): void $client->request('POST', $endpoint, $this->getRequestParameters(), [$this->getOversizedFile()], $this->requestHeaders); $response = $client->getResponse(); - //$this->assertTrue($response->isNotSuccessful()); + // $this->assertTrue($response->isNotSuccessful()); $this->assertSame($response->headers->get('Content-Type'), 'application/json'); $this->assertCount(0, $this->getUploadedFiles()); } @@ -113,29 +113,17 @@ public function testAgainstIncorrectMimeType(): void $client->request('POST', $endpoint, $this->getRequestParameters(), [$this->getFileWithIncorrectMimeType()], $this->requestHeaders); $response = $client->getResponse(); - //$this->assertTrue($response->isNotSuccessful()); + // $this->assertTrue($response->isNotSuccessful()); $this->assertSame($response->headers->get('Content-Type'), 'application/json'); $this->assertCount(0, $this->getUploadedFiles()); } - /** - * @return mixed - */ abstract protected function getFileWithCorrectMimeType(); - /** - * @return mixed - */ abstract protected function getFileWithCorrectMimeTypeAndIncorrectExtension(); - /** - * @return mixed - */ abstract protected function getFileWithIncorrectMimeType(); - /** - * @return mixed - */ abstract protected function getOversizedFile(); abstract protected function getRequestParameters(): array; diff --git a/tests/Controller/BlueimpValidationTest.php b/tests/Controller/BlueimpValidationTest.php index eb68247e..8f09d343 100644 --- a/tests/Controller/BlueimpValidationTest.php +++ b/tests/Controller/BlueimpValidationTest.php @@ -21,7 +21,7 @@ public function testAgainstMaxSize(): void $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getOversizedFile(), $this->requestHeaders); $response = $client->getResponse(); - //$this->assertTrue($response->isNotSuccessful()); + // $this->assertTrue($response->isNotSuccessful()); $this->assertSame($response->headers->get('Content-Type'), 'application/json'); $this->assertCount(0, $this->getUploadedFiles()); $this->assertFalse(strpos((string) $response->getContent(), 'error.maxsize'), 'Failed to translate error id into lang'); @@ -78,7 +78,7 @@ public function testAgainstIncorrectMimeType(): void $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithIncorrectMimeType(), $this->requestHeaders); $response = $client->getResponse(); - //$this->assertTrue($response->isNotSuccessful()); + // $this->assertTrue($response->isNotSuccessful()); $this->assertSame($response->headers->get('Content-Type'), 'application/json'); $this->assertCount(0, $this->getUploadedFiles()); } diff --git a/tests/Controller/FileBagExtractorTest.php b/tests/Controller/FileBagExtractorTest.php index 6b3d9d75..285159ca 100644 --- a/tests/Controller/FileBagExtractorTest.php +++ b/tests/Controller/FileBagExtractorTest.php @@ -83,9 +83,6 @@ public function testWithMultipleFiles(): void $this->assertCount(3, $result); } - /** - * @return mixed - */ protected function invoke(FileBag $bag) { return $this->method->invoke($this->mock, $bag); diff --git a/tests/DependencyInjection/OneupUploaderExtensionTest.php b/tests/DependencyInjection/OneupUploaderExtensionTest.php index 2b8a0b0a..86fc33fc 100644 --- a/tests/DependencyInjection/OneupUploaderExtensionTest.php +++ b/tests/DependencyInjection/OneupUploaderExtensionTest.php @@ -76,8 +76,8 @@ public function testGetMaxUploadSize(): void $getValueInBytes->setAccessible(true); $store = [ - $getValueInBytes->invoke($mock, ini_get('upload_max_filesize')), - $getValueInBytes->invoke($mock, ini_get('post_max_size')), + $getValueInBytes->invoke($mock, \ini_get('upload_max_filesize')), + $getValueInBytes->invoke($mock, \ini_get('post_max_size')), ]; $min = min($store); diff --git a/tests/Uploader/File/FilesystemFileTest.php b/tests/Uploader/File/FilesystemFileTest.php index d73ac35d..a8a369cd 100644 --- a/tests/Uploader/File/FilesystemFileTest.php +++ b/tests/Uploader/File/FilesystemFileTest.php @@ -20,7 +20,7 @@ protected function setUp(): void $this->basename = 'test_file.txt'; $this->pathname = $this->path . '/' . $this->basename; $this->extension = 'txt'; - $this->size = 9; //something = 9 bytes + $this->size = 9; // something = 9 bytes $this->mimeType = 'text/plain'; file_put_contents($this->pathname, 'something'); diff --git a/tests/Uploader/File/GaufretteFileTest.php b/tests/Uploader/File/GaufretteFileTest.php index 45bd080f..1febc13e 100644 --- a/tests/Uploader/File/GaufretteFileTest.php +++ b/tests/Uploader/File/GaufretteFileTest.php @@ -31,7 +31,7 @@ protected function setUp(): void $this->basename = 'test_file.txt'; $this->pathname = $this->path . '/' . $this->basename; $this->extension = 'txt'; - $this->size = 9; //something = 9 bytes + $this->size = 9; // something = 9 bytes $this->mimeType = 'text/plain'; file_put_contents(sys_get_temp_dir() . '/' . $this->pathname, 'something'); diff --git a/tests/Uploader/Naming/UrlSafeNamerTest.php b/tests/Uploader/Naming/UrlSafeNamerTest.php index 275ddd00..ae435387 100644 --- a/tests/Uploader/Naming/UrlSafeNamerTest.php +++ b/tests/Uploader/Naming/UrlSafeNamerTest.php @@ -22,7 +22,7 @@ protected function setUp(): void $this->basename = 'test_file.txt'; $this->pathname = $this->path . '/' . $this->basename; $this->extension = 'txt'; - $this->size = 9; //something = 9 bytes + $this->size = 9; // something = 9 bytes $this->mimeType = 'text/plain'; file_put_contents($this->pathname, 'something'); diff --git a/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php b/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php index 764d9433..3dc7b020 100644 --- a/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php +++ b/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php @@ -81,7 +81,7 @@ protected function setUp(): void fwrite($pointer, str_repeat('A', 1024), 1024); fclose($pointer); - //file key needs to be relative to the root of the flysystem filesystem + // file key needs to be relative to the root of the flysystem filesystem // It seems that tempnam on OS X prepends 'private' to chunkDirectory, so strip that off as well $fileKey = str_replace([$this->realDirectory, '/private'], '', $file); diff --git a/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php b/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php index 46cc9d19..3a6c06e3 100644 --- a/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php +++ b/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php @@ -42,9 +42,9 @@ class GaufretteAmazonS3StorageTest extends TestCase protected function setUp(): void { if ( - false === getenv('AWS_ACCESS_KEY_ID') || - false === getenv('AWS_SECRET_ACCESS_KEY') || - false === getenv('AWS_BUCKET') + false === getenv('AWS_ACCESS_KEY_ID') + || false === getenv('AWS_SECRET_ACCESS_KEY') + || false === getenv('AWS_BUCKET') ) { $this->markTestSkipped('Missing AWS_* ENV variables.'); } diff --git a/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php b/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php index a1fde8e6..e1235211 100644 --- a/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php +++ b/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php @@ -81,7 +81,7 @@ protected function setUp(): void fwrite($pointer, str_repeat('A', 1024), 1024); fclose($pointer); - //gaufrette needs the key relative to it's root + // gaufrette needs the key relative to it's root $fileKey = str_replace($this->realDirectory, '', $file); $this->payloads[] = new GaufretteFile(new File($fileKey, $filesystem), $filesystem); @@ -134,6 +134,6 @@ public function testUploadAndFetching(): void public function checkIfTempnameMatchesAfterCreation(): bool { - return 0 === strpos((string) @tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory); + return str_starts_with((string) @tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f10afb32..b12496a5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,12 +4,12 @@ if (!($loader = @include __DIR__ . '/../vendor/autoload.php')) { echo <<<'EOT' -You need to install the project dependencies using Composer: -$ wget http://getcomposer.org/composer.phar -OR -$ curl -s https://getcomposer.org/installer | php -$ php composer.phar install --dev -$ phpunit -EOT; + You need to install the project dependencies using Composer: + $ wget https://getcomposer.org/composer.phar + OR + $ curl -s https://getcomposer.org/installer | php + $ php composer.phar install --dev + $ phpunit + EOT; exit(1); } From aab411ebc5c9a545ee62f8132578495b9feae860 Mon Sep 17 00:00:00 2001 From: Johan Kasselman Date: Fri, 4 Aug 2023 10:40:22 +0200 Subject: [PATCH 05/17] Updated php_stan and config file --- composer.json | 2 +- phpstan.neon | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index dc0257de..827d5528 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "friendsofphp/php-cs-fixer": "3.22.*", "knplabs/gaufrette": "^0.9", "oneup/flysystem-bundle": "^4.1", - "phpstan/phpstan": "^0.12.10", + "phpstan/phpstan": "^1.8", "phpunit/phpunit": "^9.5", "sensio/framework-extra-bundle": "^5.0 || ^6.0", "m2mtech/flysystem-stream-wrapper": "^1.0", diff --git a/phpstan.neon b/phpstan.neon index b9453756..58ba2b85 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,15 +1,15 @@ parameters: - bootstrapFiles: - - %rootDir%/../../../vendor/autoload.php - - excludes_analyse: + level: 9 + paths: + - src + - tests + excludePaths: - src/DependencyInjection/Configuration.php - tests/App/cache - tests/App/logs - tests/App/var - var - vendor - checkGenericClassInNonGenericObjectType: false checkMissingIterableValueType: false reportUnmatchedIgnoredErrors: false @@ -18,4 +18,4 @@ parameters: - '#Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required\.#' - message: '#Parameter \#1 \$parameters of class Symfony\\Component\\HttpFoundation\\FileBag constructor expects array, array given\.#' - path: '%currentWorkingDirectory%/tests/Controller/FileBagExtractorTest.php' + path: '%currentWorkingDirectory%/tests/Controller/FileBagExtractorTest.php' \ No newline at end of file From 3676cb500bdfa37731509cbc53c94c1257c551ba Mon Sep 17 00:00:00 2001 From: Johan Kasselman Date: Fri, 4 Aug 2023 10:45:32 +0200 Subject: [PATCH 06/17] Updated php unit-brdge to v6.0.* --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 827d5528..0996aa8d 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "sensio/framework-extra-bundle": "^5.0 || ^6.0", "m2mtech/flysystem-stream-wrapper": "^1.0", "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", - "symfony/phpunit-bridge": "^5.4", + "symfony/phpunit-bridge": "6.0.*", "symfony/security-bundle": "^4.4 || ^5.4 || ^6.0", "symfony/var-dumper": "^4.4 || ^5.4 || ^6.0", "twistor/flysystem-stream-wrapper": "^1.0" From 8651acb48e4c91a8a1c9f38e319458274490cfe5 Mon Sep 17 00:00:00 2001 From: Johan Kasselman Date: Fri, 4 Aug 2023 10:50:52 +0200 Subject: [PATCH 07/17] Add tyope hint var comment/Annotation to the $helper class --- tests/Templating/TemplateHelperTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Templating/TemplateHelperTest.php b/tests/Templating/TemplateHelperTest.php index a0abf716..51a3ec89 100644 --- a/tests/Templating/TemplateHelperTest.php +++ b/tests/Templating/TemplateHelperTest.php @@ -4,6 +4,7 @@ namespace Oneup\UploaderBundle\Tests\Templating; +use Oneup\UploaderBundle\Templating\Helper\UploaderHelper; use Psr\Container\ContainerInterface; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -20,6 +21,7 @@ public function testName(): void /** @var ContainerInterface $container */ $container = $client->getContainer(); + /** @var UploaderHelper $helper */ $helper = $container->get('oneup_uploader.templating.uploader_helper'); // this is for code coverage From becf98d681598586e394a634838008f322ac10f4 Mon Sep 17 00:00:00 2001 From: Johan Kasselman Date: Fri, 4 Aug 2023 11:30:54 +0200 Subject: [PATCH 08/17] Fixe some more phpstan issues with regards to type hints and retur types --- phpstan.neon | 8 ++++ src/Controller/AbstractController.php | 23 ++++++----- src/Controller/BlueimpController.php | 4 +- src/Uploader/Chunk/ChunkManager.php | 10 +++-- .../Chunk/Storage/FlysystemStorage.php | 4 +- tests/Controller/AbstractValidationTest.php | 9 +++-- tests/Controller/BlueimpTest.php | 2 + tests/Controller/BlueimpValidationTest.php | 40 +++++++++---------- tests/Controller/DropzoneValidationTest.php | 8 ++-- .../Controller/FancyUploadValidationTest.php | 8 ++-- .../Controller/FineUploaderValidationTest.php | 8 ++-- tests/Controller/PluploadValidationTest.php | 8 ++-- tests/Controller/UploadifyValidationTest.php | 8 ++-- 13 files changed, 81 insertions(+), 59 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 58ba2b85..f5d64129 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -15,6 +15,14 @@ parameters: reportUnmatchedIgnoredErrors: false ignoreErrors: + - '#Cannot cast mixed to int\.#' + - '#Cannot call method addListener\(\) on mixed\.#' + - '#Cannot call method getSize\(\) on mixed\.#' + - '#Cannot call method maxSize\(\) on mixed\.#' + - '#Cannot call method getPathname\(\) on mixed\.#' + - '#Cannot call method getPath\(\) on mixed\.#' + - '#Cannot call method getRealPath\(\) on mixed\.#' + - '#Cannot call method getBasename\(\) on mixed\.#' - '#Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required\.#' - message: '#Parameter \#1 \$parameters of class Symfony\\Component\\HttpFoundation\\FileBag constructor expects array, array given\.#' diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index be85c1a0..76ba0424 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -15,6 +15,7 @@ use Oneup\UploaderBundle\Uploader\Response\ResponseInterface; use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\FileBag; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -38,10 +39,11 @@ public function progress(): JsonResponse $prefix = (string) \ini_get('session.upload_progress.prefix'); $name = (string) \ini_get('session.upload_progress.name'); - + /** @var string $value */ + $value = $request->get($name); // assemble session key // ref: http://php.net/manual/en/session.upload-progress.php - $key = sprintf('%s.%s', $prefix, $request->get($name)); + $key = sprintf('%s.%s', $prefix, $value); $value = $session->get($key); return new JsonResponse($value); @@ -55,9 +57,11 @@ public function cancel(): JsonResponse $prefix = (string) \ini_get('session.upload_progress.prefix'); $name = (string) \ini_get('session.upload_progress.name'); + /** @var string $value */ + $value = $request->get($name); + $key = sprintf('%s.%s', $prefix, $value); - $key = sprintf('%s.%s', $prefix, $request->get($name)); - + /** @var array $progress */ $progress = $session->get($key); $progress['cancel_upload'] = false; @@ -97,9 +101,9 @@ protected function getFiles(FileBag $bag): array * * Note: The return value differs when * - * @param mixed $file The file to upload + * @param File $file The file to upload */ - protected function handleUpload($file, ResponseInterface $response, Request $request): void + protected function handleUpload(File $file, ResponseInterface $response, Request $request): void { // wrap the file if it is not done yet which can only happen // if it wasn't a chunked upload, in which case it is definitely @@ -118,6 +122,7 @@ protected function handleUpload($file, ResponseInterface $response, Request $req $name = $namer->name($file); // perform the real upload + /** @var File $uploaded */ $uploaded = $this->storage->upload($file, $name); $this->dispatchPostEvents($uploaded, $response, $request); @@ -142,9 +147,9 @@ protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInter * This function is a helper function which dispatches post upload * and post persist events. * - * @param mixed $uploaded the uploaded file + * @param File $uploaded the uploaded file */ - protected function dispatchPostEvents($uploaded, ResponseInterface $response, Request $request): void + protected function dispatchPostEvents(File $uploaded, ResponseInterface $response, Request $request): void { // dispatch post upload event (both the specific and the general) $postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config); @@ -172,7 +177,7 @@ protected function validate(FileInterface $file, Request $request, ResponseInter * On top of that, if the client does not support the application/json type, * then the content type of the response will be set to text/plain instead. */ - protected function createSupportedJsonResponse($data, int $statusCode = 200): JsonResponse + protected function createSupportedJsonResponse(mixed $data, int $statusCode = 200): JsonResponse { $request = $this->getRequest(); $response = new JsonResponse($data, $statusCode); diff --git a/src/Controller/BlueimpController.php b/src/Controller/BlueimpController.php index 5c53ae0c..0cc5241d 100644 --- a/src/Controller/BlueimpController.php +++ b/src/Controller/BlueimpController.php @@ -41,9 +41,11 @@ public function progress(): JsonResponse $prefix = (string) \ini_get('session.upload_progress.prefix'); $name = (string) \ini_get('session.upload_progress.name'); + /** @var string $value */ + $value = $request->get($name); // ref: https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-Session-Upload-Progress - $key = sprintf('%s.%s', $prefix, $request->get($name)); + $key = sprintf('%s.%s', $prefix, $value); $value = $session->get($key); $progress = [ diff --git a/src/Uploader/Chunk/ChunkManager.php b/src/Uploader/Chunk/ChunkManager.php index 67f414a1..8da0b885 100644 --- a/src/Uploader/Chunk/ChunkManager.php +++ b/src/Uploader/Chunk/ChunkManager.php @@ -9,6 +9,10 @@ class ChunkManager implements ChunkManagerInterface { + /** + * @param array $configuration + * @param ChunkStorageInterface $storage + */ public function __construct(protected array $configuration, protected ChunkStorageInterface $storage) { } @@ -18,12 +22,12 @@ public function clear(): void $this->storage->clear($this->configuration['maxage']); } - public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original) + public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): mixed { return $this->storage->addChunk($uuid, $index, $chunk, $original); } - public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false) + public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false): mixed { return $this->storage->assembleChunks($chunks, $removeChunk, $renameChunk); } @@ -33,7 +37,7 @@ public function cleanup(string $path): void $this->storage->cleanup($path); } - public function getChunks(string $uuid) + public function getChunks(string $uuid): mixed { return $this->storage->getChunks($uuid); } diff --git a/src/Uploader/Chunk/Storage/FlysystemStorage.php b/src/Uploader/Chunk/Storage/FlysystemStorage.php index 57b6e7a9..8ef85ebd 100644 --- a/src/Uploader/Chunk/Storage/FlysystemStorage.php +++ b/src/Uploader/Chunk/Storage/FlysystemStorage.php @@ -14,9 +14,9 @@ class FlysystemStorage implements ChunkStorageInterface { /** - * @var array|null + * @var array */ - protected $unhandledChunk; + protected array $unhandledChunk = []; public function __construct(protected Filesystem $filesystem, public int $bufferSize, protected string $streamWrapperPrefix, protected string $prefix) { diff --git a/tests/Controller/AbstractValidationTest.php b/tests/Controller/AbstractValidationTest.php index 81586a40..16c2f60c 100644 --- a/tests/Controller/AbstractValidationTest.php +++ b/tests/Controller/AbstractValidationTest.php @@ -6,6 +6,7 @@ use Oneup\UploaderBundle\Event\ValidationEvent; use Psr\Container\ContainerInterface; +use Symfony\Component\HttpFoundation\File\UploadedFile; abstract class AbstractValidationTest extends AbstractControllerTest { @@ -118,13 +119,13 @@ public function testAgainstIncorrectMimeType(): void $this->assertCount(0, $this->getUploadedFiles()); } - abstract protected function getFileWithCorrectMimeType(); + abstract protected function getFileWithCorrectMimeType(): UploadedFile; - abstract protected function getFileWithCorrectMimeTypeAndIncorrectExtension(); + abstract protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile; - abstract protected function getFileWithIncorrectMimeType(); + abstract protected function getFileWithIncorrectMimeType(): UploadedFile; - abstract protected function getOversizedFile(); + abstract protected function getOversizedFile(): UploadedFile; abstract protected function getRequestParameters(): array; } diff --git a/tests/Controller/BlueimpTest.php b/tests/Controller/BlueimpTest.php index 9d0f5b15..73c58e4c 100644 --- a/tests/Controller/BlueimpTest.php +++ b/tests/Controller/BlueimpTest.php @@ -7,6 +7,7 @@ use Oneup\UploaderBundle\Event\PostUploadEvent; use Oneup\UploaderBundle\Event\PreUploadEvent; use Psr\Container\ContainerInterface; +use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -53,6 +54,7 @@ public function testEvents(): void $container = $client->getContainer(); $endpoint = $this->helper->endpoint($this->getConfigKey()); + /** @var EventDispatcher $dispatcher */ $dispatcher = $container->get('event_dispatcher'); // event data diff --git a/tests/Controller/BlueimpValidationTest.php b/tests/Controller/BlueimpValidationTest.php index 8f09d343..0722c0a4 100644 --- a/tests/Controller/BlueimpValidationTest.php +++ b/tests/Controller/BlueimpValidationTest.php @@ -17,8 +17,8 @@ public function testAgainstMaxSize(): void /** @var KernelBrowser $client */ $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getOversizedFile(), $this->requestHeaders); + $file = ['files' => [$this->getOversizedFile()]]; + $client->request('POST', $endpoint, $this->getRequestParameters(), $file, $this->requestHeaders); $response = $client->getResponse(); // $this->assertTrue($response->isNotSuccessful()); @@ -43,8 +43,8 @@ public function testEvents(): void $dispatcher->addListener(ValidationEvent::NAME, static function () use (&$validationCount): void { ++$validationCount; }); - - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectMimeType(), $this->requestHeaders); + $file = ['files' => [$this->getFileWithCorrectMimeType()]]; + $client->request('POST', $endpoint, $this->getRequestParameters(), $file, $this->requestHeaders); $this->assertSame(1, $validationCount); } @@ -54,8 +54,8 @@ public function testAgainstCorrectMimeType(): void // assemble a request $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectMimeType(), $this->requestHeaders); + $file = ['files' => [$this->getFileWithCorrectMimeType()]]; + $client->request('POST', $endpoint, $this->getRequestParameters(), $file, $this->requestHeaders); $response = $client->getResponse(); $this->assertTrue($response->isSuccessful()); @@ -74,8 +74,8 @@ public function testAgainstIncorrectMimeType(): void // assemble a request $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithIncorrectMimeType(), $this->requestHeaders); + $file = [$this->getFileWithIncorrectMimeType()]; + $client->request('POST', $endpoint, $this->getRequestParameters(), $file, $this->requestHeaders); $response = $client->getResponse(); // $this->assertTrue($response->isNotSuccessful()); @@ -93,39 +93,39 @@ protected function getRequestParameters(): array return []; } - protected function getOversizedFile(): array + protected function getOversizedFile(): UploadedFile { - return ['files' => [new UploadedFile( + return new UploadedFile( $this->createTempFile(512), 'cat.ok', 'text/plain' - )]]; + ); } - protected function getFileWithCorrectMimeType(): array + protected function getFileWithCorrectMimeType(): UploadedFile { - return ['files' => [new UploadedFile( + return new UploadedFile( $this->createTempFile(128), 'cat.txt', 'text/plain' - )]]; + ); } - protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): array + protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile { - return ['files' => [new UploadedFile( + return new UploadedFile( $this->createTempFile(128), 'cat.txxt', 'text/plain' - )]]; + ); } - protected function getFileWithIncorrectMimeType(): array + protected function getFileWithIncorrectMimeType(): UploadedFile { - return [new UploadedFile( + return new UploadedFile( $this->createTempFile(128), 'cat.ok', 'image/gif' - )]; + ); } } diff --git a/tests/Controller/DropzoneValidationTest.php b/tests/Controller/DropzoneValidationTest.php index 3d0b2f9c..0d6f0bf4 100644 --- a/tests/Controller/DropzoneValidationTest.php +++ b/tests/Controller/DropzoneValidationTest.php @@ -18,7 +18,7 @@ protected function getRequestParameters(): array return []; } - protected function getOversizedFile() + protected function getOversizedFile(): UploadedFile { return new UploadedFile( $this->createTempFile(512), @@ -27,7 +27,7 @@ protected function getOversizedFile() ); } - protected function getFileWithCorrectMimeType() + protected function getFileWithCorrectMimeType(): UploadedFile { return new UploadedFile( $this->createTempFile(128), @@ -36,7 +36,7 @@ protected function getFileWithCorrectMimeType() ); } - protected function getFileWithCorrectMimeTypeAndIncorrectExtension() + protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile { return new UploadedFile( $this->createTempFile(128), @@ -45,7 +45,7 @@ protected function getFileWithCorrectMimeTypeAndIncorrectExtension() ); } - protected function getFileWithIncorrectMimeType() + protected function getFileWithIncorrectMimeType(): UploadedFile { return new UploadedFile( $this->createTempFile(128), diff --git a/tests/Controller/FancyUploadValidationTest.php b/tests/Controller/FancyUploadValidationTest.php index 218aa77a..89afc185 100644 --- a/tests/Controller/FancyUploadValidationTest.php +++ b/tests/Controller/FancyUploadValidationTest.php @@ -18,7 +18,7 @@ protected function getRequestParameters(): array return []; } - protected function getOversizedFile() + protected function getOversizedFile(): UploadedFile { return new UploadedFile( $this->createTempFile(512), @@ -27,7 +27,7 @@ protected function getOversizedFile() ); } - protected function getFileWithCorrectMimeType() + protected function getFileWithCorrectMimeType(): UploadedFile { return new UploadedFile( $this->createTempFile(128), @@ -36,7 +36,7 @@ protected function getFileWithCorrectMimeType() ); } - protected function getFileWithCorrectMimeTypeAndIncorrectExtension() + protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile { return new UploadedFile( $this->createTempFile(128), @@ -45,7 +45,7 @@ protected function getFileWithCorrectMimeTypeAndIncorrectExtension() ); } - protected function getFileWithIncorrectMimeType() + protected function getFileWithIncorrectMimeType(): UploadedFile { return new UploadedFile( $this->createTempFile(128), diff --git a/tests/Controller/FineUploaderValidationTest.php b/tests/Controller/FineUploaderValidationTest.php index e3b17d42..842b83bd 100644 --- a/tests/Controller/FineUploaderValidationTest.php +++ b/tests/Controller/FineUploaderValidationTest.php @@ -18,7 +18,7 @@ protected function getRequestParameters(): array return []; } - protected function getOversizedFile() + protected function getOversizedFile(): UploadedFile { return new UploadedFile( $this->createTempFile(512), @@ -27,7 +27,7 @@ protected function getOversizedFile() ); } - protected function getFileWithCorrectMimeType() + protected function getFileWithCorrectMimeType(): UploadedFile { return new UploadedFile( $this->createTempFile(128), @@ -36,7 +36,7 @@ protected function getFileWithCorrectMimeType() ); } - protected function getFileWithCorrectMimeTypeAndIncorrectExtension() + protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile { return new UploadedFile( $this->createTempFile(128), @@ -45,7 +45,7 @@ protected function getFileWithCorrectMimeTypeAndIncorrectExtension() ); } - protected function getFileWithIncorrectMimeType() + protected function getFileWithIncorrectMimeType(): UploadedFile { return new UploadedFile( $this->createTempFile(128), diff --git a/tests/Controller/PluploadValidationTest.php b/tests/Controller/PluploadValidationTest.php index 95968590..0e8745a6 100644 --- a/tests/Controller/PluploadValidationTest.php +++ b/tests/Controller/PluploadValidationTest.php @@ -18,7 +18,7 @@ protected function getRequestParameters(): array return []; } - protected function getOversizedFile() + protected function getOversizedFile(): UploadedFile { return new UploadedFile( $this->createTempFile(512), @@ -27,7 +27,7 @@ protected function getOversizedFile() ); } - protected function getFileWithCorrectMimeType() + protected function getFileWithCorrectMimeType(): UploadedFile { return new UploadedFile( $this->createTempFile(128), @@ -36,7 +36,7 @@ protected function getFileWithCorrectMimeType() ); } - protected function getFileWithCorrectMimeTypeAndIncorrectExtension() + protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile { return new UploadedFile( $this->createTempFile(128), @@ -45,7 +45,7 @@ protected function getFileWithCorrectMimeTypeAndIncorrectExtension() ); } - protected function getFileWithIncorrectMimeType() + protected function getFileWithIncorrectMimeType(): UploadedFile { return new UploadedFile( $this->createTempFile(128), diff --git a/tests/Controller/UploadifyValidationTest.php b/tests/Controller/UploadifyValidationTest.php index 29f5a2d5..e1587cbb 100644 --- a/tests/Controller/UploadifyValidationTest.php +++ b/tests/Controller/UploadifyValidationTest.php @@ -18,7 +18,7 @@ protected function getRequestParameters(): array return []; } - protected function getOversizedFile() + protected function getOversizedFile(): UploadedFile { return new UploadedFile( $this->createTempFile(512), @@ -27,7 +27,7 @@ protected function getOversizedFile() ); } - protected function getFileWithCorrectMimeType() + protected function getFileWithCorrectMimeType(): UploadedFile { return new UploadedFile( $this->createTempFile(128), @@ -36,7 +36,7 @@ protected function getFileWithCorrectMimeType() ); } - protected function getFileWithCorrectMimeTypeAndIncorrectExtension() + protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile { return new UploadedFile( $this->createTempFile(128), @@ -45,7 +45,7 @@ protected function getFileWithCorrectMimeTypeAndIncorrectExtension() ); } - protected function getFileWithIncorrectMimeType() + protected function getFileWithIncorrectMimeType(): UploadedFile { return new UploadedFile( $this->createTempFile(128), From 6cf9f3aefe066370073331a7214ef2c018747e53 Mon Sep 17 00:00:00 2001 From: Johan Kasselman Date: Fri, 4 Aug 2023 11:32:57 +0200 Subject: [PATCH 09/17] Some mroe php cs fixer changes --- src/Uploader/Chunk/ChunkManager.php | 4 ---- src/Uploader/Chunk/Storage/FlysystemStorage.php | 3 --- 2 files changed, 7 deletions(-) diff --git a/src/Uploader/Chunk/ChunkManager.php b/src/Uploader/Chunk/ChunkManager.php index 8da0b885..b2c4b6ad 100644 --- a/src/Uploader/Chunk/ChunkManager.php +++ b/src/Uploader/Chunk/ChunkManager.php @@ -9,10 +9,6 @@ class ChunkManager implements ChunkManagerInterface { - /** - * @param array $configuration - * @param ChunkStorageInterface $storage - */ public function __construct(protected array $configuration, protected ChunkStorageInterface $storage) { } diff --git a/src/Uploader/Chunk/Storage/FlysystemStorage.php b/src/Uploader/Chunk/Storage/FlysystemStorage.php index 8ef85ebd..b30793f1 100644 --- a/src/Uploader/Chunk/Storage/FlysystemStorage.php +++ b/src/Uploader/Chunk/Storage/FlysystemStorage.php @@ -13,9 +13,6 @@ class FlysystemStorage implements ChunkStorageInterface { - /** - * @var array - */ protected array $unhandledChunk = []; public function __construct(protected Filesystem $filesystem, public int $bufferSize, protected string $streamWrapperPrefix, protected string $prefix) From 51ce4b4af06c396e8319429c55b8d76d0578a086 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Thu, 23 Nov 2023 13:45:28 +0100 Subject: [PATCH 10/17] Removed unused sensio/framework-extra-bundle + updated symfony/phpunit-bridge version constraint --- composer.json | 3 +-- tests/App/Kernel.php | 2 -- tests/App/config/config.yml | 2 -- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 0996aa8d..b5e52a14 100644 --- a/composer.json +++ b/composer.json @@ -53,10 +53,9 @@ "oneup/flysystem-bundle": "^4.1", "phpstan/phpstan": "^1.8", "phpunit/phpunit": "^9.5", - "sensio/framework-extra-bundle": "^5.0 || ^6.0", "m2mtech/flysystem-stream-wrapper": "^1.0", "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", - "symfony/phpunit-bridge": "6.0.*", + "symfony/phpunit-bridge": "^6.0", "symfony/security-bundle": "^4.4 || ^5.4 || ^6.0", "symfony/var-dumper": "^4.4 || ^5.4 || ^6.0", "twistor/flysystem-stream-wrapper": "^1.0" diff --git a/tests/App/Kernel.php b/tests/App/Kernel.php index 1a15234d..fec971fe 100644 --- a/tests/App/Kernel.php +++ b/tests/App/Kernel.php @@ -3,7 +3,6 @@ declare(strict_types=1); use Oneup\UploaderBundle\OneupUploaderBundle; -use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Component\Config\Loader\LoaderInterface; @@ -16,7 +15,6 @@ public function registerBundles(): iterable $bundles = [ new FrameworkBundle(), new SecurityBundle(), - new SensioFrameworkExtraBundle(), // bundle to test new OneupUploaderBundle(), diff --git a/tests/App/config/config.yml b/tests/App/config/config.yml index 3eda25a1..7203fccd 100644 --- a/tests/App/config/config.yml +++ b/tests/App/config/config.yml @@ -1,6 +1,4 @@ framework: - annotations: - enabled: true translator: { fallback: en } secret: secret router: From f8f2f31342a1263b6b94fe577361d70eff2b0735 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Thu, 23 Nov 2023 14:03:55 +0100 Subject: [PATCH 11/17] Allow Symfony 7 --- composer.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index b5e52a14..dc458479 100644 --- a/composer.json +++ b/composer.json @@ -33,15 +33,15 @@ ], "require": { "php": "^8.0", - "symfony/asset": "^4.4 || ^5.4 || ^6.0", + "symfony/asset": "^4.4 || ^5.4 || ^6.0 || ^7.0", "symfony/event-dispatcher-contracts": "^1.0 || ^2.0 || ^3.0", - "symfony/finder": "^4.4 || ^5.4 || ^6.0", - "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0", - "symfony/mime": "^4.4 || ^5.4 || ^6.0", - "symfony/templating": "^4.4 || ^5.4 || ^6.0", - "symfony/translation": "^4.4 || ^5.4 || ^6.0", + "symfony/finder": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/mime": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/templating": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/translation": "^4.4 || ^5.4 || ^6.0 || ^7.0", "symfony/translation-contracts": "^1.0 || ^2.0 || ^3.0", - "symfony/yaml": "^4.4 || ^5.4 || ^6.0", + "symfony/yaml": "^4.4 || ^5.4 || ^6.0 || ^7.0", "twig/twig": "^2.4 || ^3.0" }, "require-dev": { @@ -54,10 +54,10 @@ "phpstan/phpstan": "^1.8", "phpunit/phpunit": "^9.5", "m2mtech/flysystem-stream-wrapper": "^1.0", - "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", - "symfony/phpunit-bridge": "^6.0", - "symfony/security-bundle": "^4.4 || ^5.4 || ^6.0", - "symfony/var-dumper": "^4.4 || ^5.4 || ^6.0", + "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/phpunit-bridge": "^6.0 || ^7.0", + "symfony/security-bundle": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/var-dumper": "^4.4 || ^5.4 || ^6.0 || ^7.0", "twistor/flysystem-stream-wrapper": "^1.0" }, "suggest": { From de49885ded8e658feeddc95592950b1a9b4cdce8 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Thu, 23 Nov 2023 14:09:23 +0100 Subject: [PATCH 12/17] Updated CI to test SF 6.2 - 7.0 --- .github/workflows/ci.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1a58fcf..1477f463 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,8 +25,10 @@ jobs: - name: Install the dependencies run: composer install --no-interaction + - name: Check the coding style run: vendor/bin/php-cs-fixer fix --diff --dry-run + - name: Analyze the code run: vendor/bin/phpstan analyze @@ -36,12 +38,21 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0, 8.1] - symfony: [5.4, 6.0, 6.1] + php: [8.0, 8.1, 8.2] + symfony: [5.4, 6.0, 6.1, 6.2, 6.3, 6.4, 7.0] exclude: - # Symfony 6.1 does not support php <8.1 - php: 8.0 symfony: 6.1 + - php: 8.0 + symfony: 6.2 + - php: 8.0 + symfony: 6.3 + - php: 8.0 + symfony: 6.4 + - php: 8.0 + symfony: 7.0 + - php: 8.1 + symfony: 7.0 steps: - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -57,6 +68,7 @@ jobs: run: | composer require symfony/framework-bundle:^${{ matrix.symfony }} symfony/http-foundation:^${{ matrix.symfony }} composer install --no-interaction --no-suggest + - name: Run the unit tests run: vendor/bin/phpunit --colors=always @@ -76,5 +88,6 @@ jobs: - name: Install the dependencies run: composer update --prefer-lowest --prefer-stable --no-interaction + - name: Run the unit tests - run: vendor/bin/phpunit --colors=always \ No newline at end of file + run: vendor/bin/phpunit --colors=always From ab844e1c07ea45846374b8d73fca6f95ed53041c Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Tue, 28 Nov 2023 21:29:06 +0100 Subject: [PATCH 13/17] Fixes phpstan errors --- phpstan.neon | 17 ++++++++++++++++- src/Controller/AbstractChunkedController.php | 7 ++++++- src/Controller/BlueimpController.php | 1 + src/Controller/DropzoneController.php | 7 ++++--- src/Controller/MooUploadController.php | 4 +++- .../OneupUploaderExtension.php | 18 ++++++++++++++---- src/Routing/RouteLoader.php | 2 ++ src/Templating/Helper/UploaderHelper.php | 3 +++ src/Twig/Extension/UploaderExtension.php | 3 +++ src/Uploader/Chunk/ChunkManager.php | 5 +++++ src/Uploader/Chunk/ChunkManagerInterface.php | 8 +++++++- .../Chunk/Storage/ChunkStorageInterface.php | 10 ++++++++++ src/Uploader/File/FileInterface.php | 5 +++-- src/Uploader/File/FilesystemFile.php | 3 +++ src/Uploader/Response/AbstractResponse.php | 2 ++ src/Uploader/Response/MooUploadResponse.php | 11 ++++++++++- src/Uploader/Storage/FlysystemStorage.php | 4 +++- tests/Controller/AbstractUploadTest.php | 2 +- tests/Controller/FileBagExtractorTest.php | 2 +- .../Chunk/Storage/FlysystemStorageTest.php | 1 + 20 files changed, 98 insertions(+), 17 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index f5d64129..db97df9c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -24,6 +24,21 @@ parameters: - '#Cannot call method getRealPath\(\) on mixed\.#' - '#Cannot call method getBasename\(\) on mixed\.#' - '#Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required\.#' + - + message: '#Cannot use array destructuring on array\|false\.#' + path: '%currentWorkingDirectory%/src/Controller/BlueimpController.php' + - + message: '#Binary operation "/" between string and int results in an error\.#' + path: '%currentWorkingDirectory%/src/Controller/BlueimpController.php' + - + message: '#Dead catch - Gaufrette\\Exception\\FileNotFound is never thrown in the try block\.#' + path: '%currentWorkingDirectory%/src/Uploader/Chunk/Storage/GaufretteStorage.php' + - + message: '#Parameter \#1 \$finfo of function finfo_file|finfo_close expects finfo, resource given\.#' + path: '%currentWorkingDirectory%/src/Uploader/File/GaufretteFile.php' + - + message: '#Parameter \#2 ...\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.#' + path: '%currentWorkingDirectory%/src/Controller/PluploadController.php' - message: '#Parameter \#1 \$parameters of class Symfony\\Component\\HttpFoundation\\FileBag constructor expects array, array given\.#' - path: '%currentWorkingDirectory%/tests/Controller/FileBagExtractorTest.php' \ No newline at end of file + path: '%currentWorkingDirectory%/tests/Controller/FileBagExtractorTest.php' diff --git a/src/Controller/AbstractChunkedController.php b/src/Controller/AbstractChunkedController.php index 20234f67..959d72a1 100644 --- a/src/Controller/AbstractChunkedController.php +++ b/src/Controller/AbstractChunkedController.php @@ -7,6 +7,7 @@ use Oneup\UploaderBundle\Event\PostChunkUploadEvent; use Oneup\UploaderBundle\Uploader\Chunk\ChunkManagerInterface; use Oneup\UploaderBundle\Uploader\Response\ResponseInterface; +use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\Request; @@ -70,7 +71,11 @@ protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $re // with reassembling the parts if ($last) { $path = $assembled->getPath(); - $this->handleUpload($assembled, $response, $request); + if ($assembled instanceof File) { + $this->handleUpload($assembled, $response, $request); + } else { + // @todo $assembled is of type mixed, so would error without check + } $chunkManager->cleanup($path); } diff --git a/src/Controller/BlueimpController.php b/src/Controller/BlueimpController.php index 0cc5241d..d2cf2d97 100644 --- a/src/Controller/BlueimpController.php +++ b/src/Controller/BlueimpController.php @@ -46,6 +46,7 @@ public function progress(): JsonResponse // ref: https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-Session-Upload-Progress $key = sprintf('%s.%s', $prefix, $value); + /** @var array $value */ $value = $session->get($key); $progress = [ diff --git a/src/Controller/DropzoneController.php b/src/Controller/DropzoneController.php index da6a15ed..ccc5fd62 100644 --- a/src/Controller/DropzoneController.php +++ b/src/Controller/DropzoneController.php @@ -53,10 +53,11 @@ protected function parseChunkedRequest(Request $request): array $uuid = $request->get('dzuuid'); /** - * @var UploadedFile + * @var UploadedFile $file */ - $file = $request->files->get('file')->getClientOriginalName(); - $orig = $file; + $file = $request->files->get('file'); + $fileName = $file->getClientOriginalName(); + $orig = $fileName; return [$last, $uuid, $index, $orig]; } diff --git a/src/Controller/MooUploadController.php b/src/Controller/MooUploadController.php index 59abc918..176729db 100644 --- a/src/Controller/MooUploadController.php +++ b/src/Controller/MooUploadController.php @@ -74,7 +74,9 @@ protected function parseChunkedRequest(Request $request): array try { // loop through every file that has been uploaded before - foreach ($chunkManager->getChunks((string) $uuid) as $file) { + /** @var iterable $chunks */ + $chunks = $chunkManager->getChunks((string) $uuid); + foreach ($chunks as $file) { $size += $file->getSize(); } } catch (\InvalidArgumentException $e) { diff --git a/src/DependencyInjection/OneupUploaderExtension.php b/src/DependencyInjection/OneupUploaderExtension.php index bcff9c74..31245445 100644 --- a/src/DependencyInjection/OneupUploaderExtension.php +++ b/src/DependencyInjection/OneupUploaderExtension.php @@ -108,12 +108,12 @@ protected function createController(string $key, array $config): string } else { $customFrontend = $config['custom_frontend']; - $controllerName = sprintf('oneup_uploader.controller.%s', $customFrontend['name']); - $controllerType = $customFrontend['class']; - - if (empty($controllerName) || empty($controllerType)) { + if (empty($customFrontend['name']) || empty($customFrontend['class'])) { throw new ServiceNotFoundException('Empty controller class or name. If you really want to use a custom frontend implementation, be sure to provide a class and a name.'); } + + $controllerName = sprintf('oneup_uploader.controller.%s', $customFrontend['name']); + $controllerType = $customFrontend['class']; } $errorHandler = $this->createErrorHandler($config); @@ -285,6 +285,9 @@ protected function registerFilesystem(string $type, string $key, string $class, ->addArgument($prefix); } + /** + * @param mixed $input + */ protected function getMaxUploadSize($input): int { $input = $this->getValueInBytes($input); @@ -298,9 +301,16 @@ protected function getMaxUploadSize($input): int return min(min($input, $maxPost), $maxFile); } + /** + * @param mixed $input + */ protected function getValueInBytes($input): int { // see: http://www.php.net/manual/en/function.ini-get.php + if (!is_scalar($input)) { + return -1; + } + $input = trim((string) $input); $last = strtolower($input[\strlen($input) - 1]); $numericInput = (float) substr($input, 0, -1); diff --git a/src/Routing/RouteLoader.php b/src/Routing/RouteLoader.php index 8a61adcd..4708b5d3 100644 --- a/src/Routing/RouteLoader.php +++ b/src/Routing/RouteLoader.php @@ -16,6 +16,7 @@ public function __construct(protected array $controllers) } /** + * @param mixed $resource * @param string|null $type */ public function supports($resource, $type = null): bool @@ -24,6 +25,7 @@ public function supports($resource, $type = null): bool } /** + * @param mixed $resource * @param string|null $type */ public function load($resource, $type = null): RouteCollection diff --git a/src/Templating/Helper/UploaderHelper.php b/src/Templating/Helper/UploaderHelper.php index d6f0a0b0..0bedf4a8 100644 --- a/src/Templating/Helper/UploaderHelper.php +++ b/src/Templating/Helper/UploaderHelper.php @@ -38,6 +38,9 @@ public function uploadKey(): string return (string) \ini_get('session.upload_progress.name'); } + /** + * @return int + */ public function maxSize(string $key) { if (!\array_key_exists($key, $this->maxsize)) { diff --git a/src/Twig/Extension/UploaderExtension.php b/src/Twig/Extension/UploaderExtension.php index 8eda3eb0..53243210 100644 --- a/src/Twig/Extension/UploaderExtension.php +++ b/src/Twig/Extension/UploaderExtension.php @@ -50,6 +50,9 @@ public function uploadKey(): string return $this->helper->uploadKey(); } + /** + * @return int + */ public function maxSize(string $key) { return $this->helper->maxSize($key); diff --git a/src/Uploader/Chunk/ChunkManager.php b/src/Uploader/Chunk/ChunkManager.php index b2c4b6ad..340cbbf8 100644 --- a/src/Uploader/Chunk/ChunkManager.php +++ b/src/Uploader/Chunk/ChunkManager.php @@ -23,6 +23,11 @@ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $ return $this->storage->addChunk($uuid, $index, $chunk, $original); } + /** + * @param mixed $chunks + * @param bool $removeChunk + * @param bool $renameChunk + */ public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false): mixed { return $this->storage->assembleChunks($chunks, $removeChunk, $renameChunk); diff --git a/src/Uploader/Chunk/ChunkManagerInterface.php b/src/Uploader/Chunk/ChunkManagerInterface.php index b53540ac..fe3205c7 100644 --- a/src/Uploader/Chunk/ChunkManagerInterface.php +++ b/src/Uploader/Chunk/ChunkManagerInterface.php @@ -4,26 +4,32 @@ namespace Oneup\UploaderBundle\Uploader\Chunk; -use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\UploadedFile; interface ChunkManagerInterface { /** * Adds a new Chunk to a given uuid. + * + * @return mixed */ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original); /** * Assembles the given chunks and return the resulting file. * + * @param mixed $chunks * @param bool $removeChunk remove the chunk file once its assembled * @param bool $renameChunk rename the chunk file once its assembled + * + * @return mixed */ public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false); /** * Get chunks associated with the given uuid. + * + * @return mixed */ public function getChunks(string $uuid); diff --git a/src/Uploader/Chunk/Storage/ChunkStorageInterface.php b/src/Uploader/Chunk/Storage/ChunkStorageInterface.php index 00af3c2b..e1b419f8 100644 --- a/src/Uploader/Chunk/Storage/ChunkStorageInterface.php +++ b/src/Uploader/Chunk/Storage/ChunkStorageInterface.php @@ -10,11 +10,21 @@ interface ChunkStorageInterface { public function clear(int $maxAge): void; + /** + * @return mixed + */ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original); + /** + * @param mixed $chunks + * @return mixed + */ public function assembleChunks($chunks, bool $removeChunk, bool $renameChunk); public function cleanup(string $path): void; + /** + * @return mixed + */ public function getChunks(string $uuid); } diff --git a/src/Uploader/File/FileInterface.php b/src/Uploader/File/FileInterface.php index a303552f..a58ea109 100644 --- a/src/Uploader/File/FileInterface.php +++ b/src/Uploader/File/FileInterface.php @@ -4,8 +4,6 @@ namespace Oneup\UploaderBundle\Uploader\File; -use Symfony\Component\HttpFoundation\File\File; - /** * Every function in this interface should be considered unsafe. * They are only meant to abstract away some basic file functionality. @@ -55,5 +53,8 @@ public function getBasename(); */ public function getExtension(): string; + /** + * @return mixed + */ public function getFileSystem(); } diff --git a/src/Uploader/File/FilesystemFile.php b/src/Uploader/File/FilesystemFile.php index 5e353566..b0094f7f 100644 --- a/src/Uploader/File/FilesystemFile.php +++ b/src/Uploader/File/FilesystemFile.php @@ -23,6 +23,9 @@ public function getExtension(): string return $this->getClientOriginalExtension(); } + /** + * @return null + */ public function getFileSystem() { return null; diff --git a/src/Uploader/Response/AbstractResponse.php b/src/Uploader/Response/AbstractResponse.php index e7fe0801..2e82eba1 100644 --- a/src/Uploader/Response/AbstractResponse.php +++ b/src/Uploader/Response/AbstractResponse.php @@ -38,6 +38,8 @@ public function offsetGet($offset) * The \ArrayAccess interface does not support multi-dimensional array syntax such as $array["foo"][] = bar * This function will take a path of arrays and add a new element to it, creating the path if needed. * + * @param array $value + * * @throws \InvalidArgumentException if the path contains non-array items */ public function addToOffset($value, array $offsets): void diff --git a/src/Uploader/Response/MooUploadResponse.php b/src/Uploader/Response/MooUploadResponse.php index 1f5b7387..a1af863b 100644 --- a/src/Uploader/Response/MooUploadResponse.php +++ b/src/Uploader/Response/MooUploadResponse.php @@ -7,7 +7,7 @@ class MooUploadResponse extends AbstractResponse { /** - * @var int|string + * @var int|string|null */ protected $id; @@ -45,6 +45,9 @@ public function assemble(): array return $data; } + /** + * @param int|string|null $id + */ public function setId($id): self { $this->id = $id; @@ -52,6 +55,9 @@ public function setId($id): self return $this; } + /** + * @return int|string|null + */ public function getId() { return $this->id; @@ -69,6 +75,9 @@ public function getName(): ?string return $this->name; } + /** + * @param mixed $size + */ public function setSize($size): self { $this->size = (int) $size; diff --git a/src/Uploader/Storage/FlysystemStorage.php b/src/Uploader/Storage/FlysystemStorage.php index 4636e260..c6895875 100644 --- a/src/Uploader/Storage/FlysystemStorage.php +++ b/src/Uploader/Storage/FlysystemStorage.php @@ -55,8 +55,10 @@ public function upload($file, string $name, string $path = null) } if ($file instanceof FileInterface) { + /** @var FilesystemOperator $filesystem */ + $filesystem = $file->getFilesystem(); $manager = new MountManager([ - 'chunks' => $file->getFilesystem(), + 'chunks' => $filesystem, 'dest' => $this->filesystem, ]); diff --git a/tests/Controller/AbstractUploadTest.php b/tests/Controller/AbstractUploadTest.php index 1dda249d..b8494500 100644 --- a/tests/Controller/AbstractUploadTest.php +++ b/tests/Controller/AbstractUploadTest.php @@ -87,5 +87,5 @@ public function testEvents(): void abstract protected function getRequestParameters(): array; - abstract protected function getRequestFile(); + abstract protected function getRequestFile(): mixed; } diff --git a/tests/Controller/FileBagExtractorTest.php b/tests/Controller/FileBagExtractorTest.php index 285159ca..660a9ffb 100644 --- a/tests/Controller/FileBagExtractorTest.php +++ b/tests/Controller/FileBagExtractorTest.php @@ -83,7 +83,7 @@ public function testWithMultipleFiles(): void $this->assertCount(3, $result); } - protected function invoke(FileBag $bag) + protected function invoke(FileBag $bag): mixed { return $this->method->invoke($this->mock, $bag); } diff --git a/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php b/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php index a3ba11cd..e9b7c453 100644 --- a/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php +++ b/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php @@ -74,6 +74,7 @@ public function testGetChunks(): void $system->dumpFile($dir . '/chunk3', 'test'); $timeTo = time(); + /** @var array $files */ $files = $this->storage->getChunks($uuid); $this->assertCount(3, $files); $file = $files[0]; From b30a9c353bcb889d66e566b8bdd8421c2810d790 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Wed, 29 Nov 2023 09:40:52 +0100 Subject: [PATCH 14/17] Refactored phpstan fixes --- src/Controller/AbstractChunkedController.php | 3 +- .../OneupUploaderExtension.php | 12 ++---- src/Routing/RouteLoader.php | 12 +----- src/Templating/Helper/UploaderHelper.php | 5 +-- src/Twig/Extension/UploaderExtension.php | 5 +-- src/Uploader/Chunk/ChunkManager.php | 7 +--- src/Uploader/Chunk/ChunkManagerInterface.php | 13 ++----- .../Chunk/Storage/ChunkStorageInterface.php | 16 ++------ .../Chunk/Storage/FlysystemStorage.php | 4 +- .../Chunk/Storage/GaufretteStorage.php | 4 +- src/Uploader/File/FileInterface.php | 7 +--- src/Uploader/File/FilesystemFile.php | 5 +-- src/Uploader/File/FlysystemFile.php | 4 +- src/Uploader/File/GaufretteFile.php | 4 +- src/Uploader/Response/AbstractResponse.php | 6 +-- src/Uploader/Response/MooUploadResponse.php | 38 ++++--------------- 16 files changed, 37 insertions(+), 108 deletions(-) diff --git a/src/Controller/AbstractChunkedController.php b/src/Controller/AbstractChunkedController.php index 959d72a1..c1699154 100644 --- a/src/Controller/AbstractChunkedController.php +++ b/src/Controller/AbstractChunkedController.php @@ -73,9 +73,8 @@ protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $re $path = $assembled->getPath(); if ($assembled instanceof File) { $this->handleUpload($assembled, $response, $request); - } else { - // @todo $assembled is of type mixed, so would error without check } + // @todo $assembled is of type mixed, so would error without check $chunkManager->cleanup($path); } diff --git a/src/DependencyInjection/OneupUploaderExtension.php b/src/DependencyInjection/OneupUploaderExtension.php index 31245445..af237477 100644 --- a/src/DependencyInjection/OneupUploaderExtension.php +++ b/src/DependencyInjection/OneupUploaderExtension.php @@ -285,10 +285,7 @@ protected function registerFilesystem(string $type, string $key, string $class, ->addArgument($prefix); } - /** - * @param mixed $input - */ - protected function getMaxUploadSize($input): int + protected function getMaxUploadSize(mixed $input): int { $input = $this->getValueInBytes($input); $maxPost = $this->getValueInBytes(\ini_get('upload_max_filesize')); @@ -301,13 +298,10 @@ protected function getMaxUploadSize($input): int return min(min($input, $maxPost), $maxFile); } - /** - * @param mixed $input - */ - protected function getValueInBytes($input): int + protected function getValueInBytes(mixed $input): int { // see: http://www.php.net/manual/en/function.ini-get.php - if (!is_scalar($input)) { + if (!\is_scalar($input)) { return -1; } diff --git a/src/Routing/RouteLoader.php b/src/Routing/RouteLoader.php index 4708b5d3..39279c08 100644 --- a/src/Routing/RouteLoader.php +++ b/src/Routing/RouteLoader.php @@ -15,20 +15,12 @@ public function __construct(protected array $controllers) parent::__construct(); } - /** - * @param mixed $resource - * @param string|null $type - */ - public function supports($resource, $type = null): bool + public function supports(mixed $resource, string $type = null): bool { return 'uploader' === $type; } - /** - * @param mixed $resource - * @param string|null $type - */ - public function load($resource, $type = null): RouteCollection + public function load(mixed $resource, string $type = null): RouteCollection { $routes = new RouteCollection(); $separator = '::'; diff --git a/src/Templating/Helper/UploaderHelper.php b/src/Templating/Helper/UploaderHelper.php index 0bedf4a8..70e89ae9 100644 --- a/src/Templating/Helper/UploaderHelper.php +++ b/src/Templating/Helper/UploaderHelper.php @@ -38,10 +38,7 @@ public function uploadKey(): string return (string) \ini_get('session.upload_progress.name'); } - /** - * @return int - */ - public function maxSize(string $key) + public function maxSize(string $key): int { if (!\array_key_exists($key, $this->maxsize)) { throw new \InvalidArgumentException('No such mapping found to get maxsize for.'); diff --git a/src/Twig/Extension/UploaderExtension.php b/src/Twig/Extension/UploaderExtension.php index 53243210..ec62cc10 100644 --- a/src/Twig/Extension/UploaderExtension.php +++ b/src/Twig/Extension/UploaderExtension.php @@ -50,10 +50,7 @@ public function uploadKey(): string return $this->helper->uploadKey(); } - /** - * @return int - */ - public function maxSize(string $key) + public function maxSize(string $key): int { return $this->helper->maxSize($key); } diff --git a/src/Uploader/Chunk/ChunkManager.php b/src/Uploader/Chunk/ChunkManager.php index 340cbbf8..989f8a08 100644 --- a/src/Uploader/Chunk/ChunkManager.php +++ b/src/Uploader/Chunk/ChunkManager.php @@ -23,12 +23,7 @@ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $ return $this->storage->addChunk($uuid, $index, $chunk, $original); } - /** - * @param mixed $chunks - * @param bool $removeChunk - * @param bool $renameChunk - */ - public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false): mixed + public function assembleChunks(mixed $chunks, bool $removeChunk = true, bool $renameChunk = false): mixed { return $this->storage->assembleChunks($chunks, $removeChunk, $renameChunk); } diff --git a/src/Uploader/Chunk/ChunkManagerInterface.php b/src/Uploader/Chunk/ChunkManagerInterface.php index fe3205c7..f4aac047 100644 --- a/src/Uploader/Chunk/ChunkManagerInterface.php +++ b/src/Uploader/Chunk/ChunkManagerInterface.php @@ -10,28 +10,21 @@ interface ChunkManagerInterface { /** * Adds a new Chunk to a given uuid. - * - * @return mixed */ - public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original); + public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): mixed; /** * Assembles the given chunks and return the resulting file. * - * @param mixed $chunks * @param bool $removeChunk remove the chunk file once its assembled * @param bool $renameChunk rename the chunk file once its assembled - * - * @return mixed */ - public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false); + public function assembleChunks(mixed $chunks, bool $removeChunk = true, bool $renameChunk = false): mixed; /** * Get chunks associated with the given uuid. - * - * @return mixed */ - public function getChunks(string $uuid); + public function getChunks(string $uuid): mixed; /** * Clean a given path. diff --git a/src/Uploader/Chunk/Storage/ChunkStorageInterface.php b/src/Uploader/Chunk/Storage/ChunkStorageInterface.php index e1b419f8..11f82250 100644 --- a/src/Uploader/Chunk/Storage/ChunkStorageInterface.php +++ b/src/Uploader/Chunk/Storage/ChunkStorageInterface.php @@ -10,21 +10,11 @@ interface ChunkStorageInterface { public function clear(int $maxAge): void; - /** - * @return mixed - */ - public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original); + public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): mixed; - /** - * @param mixed $chunks - * @return mixed - */ - public function assembleChunks($chunks, bool $removeChunk, bool $renameChunk); + public function assembleChunks(mixed $chunks, bool $removeChunk, bool $renameChunk): mixed; public function cleanup(string $path): void; - /** - * @return mixed - */ - public function getChunks(string $uuid); + public function getChunks(string $uuid): mixed; } diff --git a/src/Uploader/Chunk/Storage/FlysystemStorage.php b/src/Uploader/Chunk/Storage/FlysystemStorage.php index b30793f1..f28bd0c0 100644 --- a/src/Uploader/Chunk/Storage/FlysystemStorage.php +++ b/src/Uploader/Chunk/Storage/FlysystemStorage.php @@ -19,7 +19,7 @@ public function __construct(protected Filesystem $filesystem, public int $buffer { } - public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): void + public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): mixed { // Prevent path traversal attacks $uuid = basename($uuid); @@ -30,6 +30,8 @@ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $ 'chunk' => $chunk, 'original' => $original, ]; + + return null; } /** diff --git a/src/Uploader/Chunk/Storage/GaufretteStorage.php b/src/Uploader/Chunk/Storage/GaufretteStorage.php index e622cd21..345f0288 100644 --- a/src/Uploader/Chunk/Storage/GaufretteStorage.php +++ b/src/Uploader/Chunk/Storage/GaufretteStorage.php @@ -93,7 +93,7 @@ public function clear(int $maxAge, string $prefix = null): void * for gaufrette based chunk storage therefore assembleChunks will * be called in the same request. */ - public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): void + public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): mixed { // Prevent path traversal attacks $uuid = basename($uuid); @@ -104,6 +104,8 @@ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $ 'chunk' => $chunk, 'original' => $original, ]; + + return null; } /** diff --git a/src/Uploader/File/FileInterface.php b/src/Uploader/File/FileInterface.php index a58ea109..d69b13e9 100644 --- a/src/Uploader/File/FileInterface.php +++ b/src/Uploader/File/FileInterface.php @@ -37,7 +37,7 @@ public function getPath(); /** * Returns the guessed mime type of the file. * - * @return string + * @return string|null */ public function getMimeType(); @@ -53,8 +53,5 @@ public function getBasename(); */ public function getExtension(): string; - /** - * @return mixed - */ - public function getFileSystem(); + public function getFileSystem(): mixed; } diff --git a/src/Uploader/File/FilesystemFile.php b/src/Uploader/File/FilesystemFile.php index b0094f7f..e63f00c5 100644 --- a/src/Uploader/File/FilesystemFile.php +++ b/src/Uploader/File/FilesystemFile.php @@ -23,10 +23,7 @@ public function getExtension(): string return $this->getClientOriginalExtension(); } - /** - * @return null - */ - public function getFileSystem() + public function getFileSystem(): mixed { return null; } diff --git a/src/Uploader/File/FlysystemFile.php b/src/Uploader/File/FlysystemFile.php index 6e51a1c4..a0bd1668 100644 --- a/src/Uploader/File/FlysystemFile.php +++ b/src/Uploader/File/FlysystemFile.php @@ -16,7 +16,7 @@ public function __construct(private string $pathname, private FilesystemOperator /** * @throws FilesystemException */ - public function getSize(): int + public function getSize() { return $this->filesystem->fileSize($this->pathname); } @@ -34,7 +34,7 @@ public function getPath(): string /** * @throws FilesystemException */ - public function getMimeType(): string + public function getMimeType() { return $this->filesystem->mimeType($this->pathname); } diff --git a/src/Uploader/File/GaufretteFile.php b/src/Uploader/File/GaufretteFile.php index b8eda299..f7e24db6 100644 --- a/src/Uploader/File/GaufretteFile.php +++ b/src/Uploader/File/GaufretteFile.php @@ -31,7 +31,7 @@ public function __construct(File $file, FilesystemInterface $filesystem, protect * and will have heavy performance footprint. * !! ------- !! */ - public function getSize(): int + public function getSize() { // This can only work on streamable files, so basically local files, // still only perform it once even on local files to avoid bothering the filesystem.php g @@ -67,7 +67,7 @@ public function getBasename(): string return pathinfo($this->getKey(), \PATHINFO_BASENAME); } - public function getMimeType(): string + public function getMimeType() { // This can only work on streamable files, so basically local files, // still only perform it once even on local files to avoid bothering the filesystem. diff --git a/src/Uploader/Response/AbstractResponse.php b/src/Uploader/Response/AbstractResponse.php index 2e82eba1..38e66289 100644 --- a/src/Uploader/Response/AbstractResponse.php +++ b/src/Uploader/Response/AbstractResponse.php @@ -35,14 +35,12 @@ public function offsetGet($offset) } /** - * The \ArrayAccess interface does not support multi-dimensional array syntax such as $array["foo"][] = bar + * The \ArrayAccess interface does not support multidimensional array syntax such as $array["foo"][] = bar * This function will take a path of arrays and add a new element to it, creating the path if needed. * - * @param array $value - * * @throws \InvalidArgumentException if the path contains non-array items */ - public function addToOffset($value, array $offsets): void + public function addToOffset(array $value, array $offsets): void { $element = &$this->data; foreach ($offsets as $offset) { diff --git a/src/Uploader/Response/MooUploadResponse.php b/src/Uploader/Response/MooUploadResponse.php index a1af863b..3a5cad90 100644 --- a/src/Uploader/Response/MooUploadResponse.php +++ b/src/Uploader/Response/MooUploadResponse.php @@ -6,25 +6,10 @@ class MooUploadResponse extends AbstractResponse { - /** - * @var int|string|null - */ - protected $id; - - /** - * @var string|null - */ - protected $name; - - /** - * @var int - */ - protected $size; - - /** - * @var string - */ - protected $uploadedName; + protected int|string|null $id; + protected ?string $name; + protected int $size; + protected string $uploadedName; public function __construct(protected bool $finish = true, protected int $error = 0) { @@ -45,20 +30,14 @@ public function assemble(): array return $data; } - /** - * @param int|string|null $id - */ - public function setId($id): self + public function setId(int|string|null $id): self { $this->id = $id; return $this; } - /** - * @return int|string|null - */ - public function getId() + public function getId(): int|string|null { return $this->id; } @@ -75,10 +54,7 @@ public function getName(): ?string return $this->name; } - /** - * @param mixed $size - */ - public function setSize($size): self + public function setSize(mixed $size): self { $this->size = (int) $size; From d714043913fa0eff3ca79fe501fdea5e00adee52 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Wed, 29 Nov 2023 10:45:48 +0100 Subject: [PATCH 15/17] Fix CI for prefer lowest run --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index dc458479..1c1083eb 100644 --- a/composer.json +++ b/composer.json @@ -48,14 +48,14 @@ "amazonwebservices/aws-sdk-for-php": "1.5.*", "doctrine/common": "^2.12 || ^3.0", "doctrine/doctrine-bundle": "^2.4", - "friendsofphp/php-cs-fixer": "3.22.*", + "friendsofphp/php-cs-fixer": "^3.40", "knplabs/gaufrette": "^0.9", + "m2mtech/flysystem-stream-wrapper": "^1.0", "oneup/flysystem-bundle": "^4.1", "phpstan/phpstan": "^1.8", "phpunit/phpunit": "^9.5", - "m2mtech/flysystem-stream-wrapper": "^1.0", "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0 || ^7.0", - "symfony/phpunit-bridge": "^6.0 || ^7.0", + "symfony/phpunit-bridge": "^6.0.17 || ^7.0", "symfony/security-bundle": "^4.4 || ^5.4 || ^6.0 || ^7.0", "symfony/var-dumper": "^4.4 || ^5.4 || ^6.0 || ^7.0", "twistor/flysystem-stream-wrapper": "^1.0" From 80c4eb59a60c208a65a1c79100932a1d58cd991a Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Mon, 15 Jan 2024 15:30:03 +0100 Subject: [PATCH 16/17] Drop support for symfony/* ^4.4 --- composer.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 1c1083eb..89249510 100644 --- a/composer.json +++ b/composer.json @@ -33,15 +33,15 @@ ], "require": { "php": "^8.0", - "symfony/asset": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/asset": "^5.4 || ^6.0 || ^7.0", "symfony/event-dispatcher-contracts": "^1.0 || ^2.0 || ^3.0", - "symfony/finder": "^4.4 || ^5.4 || ^6.0 || ^7.0", - "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0 || ^7.0", - "symfony/mime": "^4.4 || ^5.4 || ^6.0 || ^7.0", - "symfony/templating": "^4.4 || ^5.4 || ^6.0 || ^7.0", - "symfony/translation": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/finder": "^5.4 || ^6.0 || ^7.0", + "symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0", + "symfony/mime": "^5.4 || ^6.0 || ^7.0", + "symfony/templating": "^5.4 || ^6.0 || ^7.0", + "symfony/translation": "^5.4 || ^6.0 || ^7.0", "symfony/translation-contracts": "^1.0 || ^2.0 || ^3.0", - "symfony/yaml": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/yaml": "^5.4 || ^6.0 || ^7.0", "twig/twig": "^2.4 || ^3.0" }, "require-dev": { @@ -54,10 +54,10 @@ "oneup/flysystem-bundle": "^4.1", "phpstan/phpstan": "^1.8", "phpunit/phpunit": "^9.5", - "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/browser-kit": "^5.4 || ^6.0 || ^7.0", "symfony/phpunit-bridge": "^6.0.17 || ^7.0", - "symfony/security-bundle": "^4.4 || ^5.4 || ^6.0 || ^7.0", - "symfony/var-dumper": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/security-bundle": "^5.4 || ^6.0 || ^7.0", + "symfony/var-dumper": "^5.4 || ^6.0 || ^7.0", "twistor/flysystem-stream-wrapper": "^1.0" }, "suggest": { From befecb10b17d44bcd142cccd636bc4e0ebd61b8e Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Mon, 15 Jan 2024 15:38:20 +0100 Subject: [PATCH 17/17] Fix CI for Yaml incompatibility --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1477f463..c78c8b71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: - name: Install the dependencies run: | - composer require symfony/framework-bundle:^${{ matrix.symfony }} symfony/http-foundation:^${{ matrix.symfony }} + composer require symfony/framework-bundle:^${{ matrix.symfony }} symfony/http-foundation:^${{ matrix.symfony }} symfony/yaml:^${{ matrix.symfony }} composer install --no-interaction --no-suggest - name: Run the unit tests