diff --git a/composer.json b/composer.json index b0ecb74..e3260e4 100644 --- a/composer.json +++ b/composer.json @@ -1,47 +1,55 @@ { - "name": "pion/laravel-chunk-upload", - "description": "Service for chunked upload with several js providers", - "license": "MIT", - "authors": [ - { - "name": "Martin Kluska", - "email": "martin@kluska.cz" - } - ], - "scripts": { - "lint:fix": "./vendor/bin/php-cs-fixer fix --config=.php_cs --using-cache false", - "lint:check": "./vendor/bin/phplint", - "lint": "composer run-script lint:fix && composer run-script lint:check", - "test": "./vendor/bin/phpunit" - }, - "require": { - "illuminate/http": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0", - "illuminate/console": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0", - "illuminate/support": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0", - "illuminate/filesystem": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0" - }, - "require-dev": { - "phpunit/phpunit": "5.7 | 6.0 | 7.0 | 7.5 | 8.4 | ^8.5 | ^9.3 | ^10.0", - "mockery/mockery": "^1.1.0 | ^1.3.0", - "friendsofphp/php-cs-fixer": "^2.16.0", - "overtrue/phplint": "^1.1 | ^2.0" - }, - "autoload": { - "psr-4": { - "Pion\\Laravel\\ChunkUpload\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests/" - } - }, - "extra":{ - "laravel":{ - "providers":[ - "Pion\\Laravel\\ChunkUpload\\Providers\\ChunkUploadServiceProvider" - ] - } - }, - "minimum-stability": "stable" + "name": "pion/laravel-chunk-upload", + "description": "Service for chunked upload with several js providers", + "license": "MIT", + "authors": [ + { + "name": "Martin Kluska", + "email": "martin@kluska.cz" + } + ], + "scripts": { + "check": "composer lint && composer test && composer lint:stan", + "lint:check": "./vendor/bin/ecs", + "lint:fix": "./vendor/bin/ecs --fix", + "lint:stan": "./vendor/bin/phpstan", + "lint:upgrade:check": "vendor/bin/rector process --dry-run", + "lint:upgrade": "vendor/bin/rector process", + "lint": "composer lint:upgrade && composer lint:fix && composer lint:stan", + "test": "./vendor/bin/phpunit", + "test:coverage": "./vendor/bin/phpunit --coverage-text" + }, + "require": { + "laravel/framework": "5.2 - 5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0", + "mockery/mockery": "^1.1.0 | ^1.3.0", + "nunomaduro/larastan": "2.5.1", + "phpstan/phpstan": "1.10.6", + "phpstan/phpstan-deprecation-rules": "^1.0.0", + "phpstan/phpstan-mockery": "^1.1.0", + "phpstan/phpstan-phpunit": "^1.1.1", + "rector/rector": "0.15.21", + "symplify/easy-coding-standard": "11.1.20", + "orchestra/testbench": "^8.0" + }, + "autoload": { + "psr-4": { + "Pion\\Laravel\\ChunkUpload\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, + "extra": { + "laravel": { + "providers": [ + "Pion\\Laravel\\ChunkUpload\\Providers\\ChunkUploadServiceProvider" + ] + } + }, + "minimum-stability": "stable" } diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..7a79f1c --- /dev/null +++ b/ecs.php @@ -0,0 +1,24 @@ +import(SetList::PSR_12); + $containerConfigurator->import(SetList::SYMPLIFY); + $containerConfigurator->import(SetList::COMMON); + $containerConfigurator->import(SetList::CLEAN_CODE); + + $containerConfigurator->parallel(); + $containerConfigurator->paths( + [__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/ecs.php', __DIR__ . '/rector.php'] + ); + $containerConfigurator->skip([ + YodaStyleFixer::class, + DeclareStrictTypesFixer::class, + ]); +}; diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..c97688b --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,20 @@ +includes: + - vendor/nunomaduro/larastan/extension.neon + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon + - vendor/phpstan/phpstan-deprecation-rules/rules.neon + - vendor/phpstan/phpstan-mockery/extension.neon + +parameters: + + parallel: + processTimeout: 600.0 + + paths: + - src + - tests + + level: 8 + + # it is impossible to map toArray() + #checkMissingIterableValueType: false diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..b0a9dac --- /dev/null +++ b/rector.php @@ -0,0 +1,27 @@ +paths([__DIR__ . '/src', __DIR__ . '/tests']); + $config->phpVersion(PhpVersion::PHP_74); + + // Define what rule sets will be applied + $config->import(LevelSetList::UP_TO_PHP_74); + $config->import(SetList::CODE_QUALITY); + $config->import(SetList::CODING_STYLE); + $config->importNames(); + $config->skip([ + VarConstantCommentRector::class, + ]); +}; diff --git a/src/Config/AbstractConfig.php b/src/Config/AbstractConfig.php index bb89fd1..4956e4f 100644 --- a/src/Config/AbstractConfig.php +++ b/src/Config/AbstractConfig.php @@ -47,7 +47,7 @@ abstract public function clearTimestampString(); /** * Returns the schedule config array. * - * @return array + * @return array{enable: bool, cron: string} */ abstract public function scheduleConfig(); diff --git a/src/Config/FileConfig.php b/src/Config/FileConfig.php index 02a0043..a692cb3 100644 --- a/src/Config/FileConfig.php +++ b/src/Config/FileConfig.php @@ -61,7 +61,7 @@ public function clearTimestampString() /** * Returns the shedule config array. * - * @return array + * @return array{enable: bool, cron: string} */ public function scheduleConfig() { diff --git a/src/Handler/ChunksInRequestUploadHandler.php b/src/Handler/ChunksInRequestUploadHandler.php index 2882ab5..f938531 100644 --- a/src/Handler/ChunksInRequestUploadHandler.php +++ b/src/Handler/ChunksInRequestUploadHandler.php @@ -125,7 +125,7 @@ public function isFirstChunk() /** * Checks if the chunk is last. * - * @return int + * @return bool */ public function isLastChunk() { diff --git a/src/Handler/ContentRangeUploadHandler.php b/src/Handler/ContentRangeUploadHandler.php index d2b2e3a..ee06f9b 100644 --- a/src/Handler/ContentRangeUploadHandler.php +++ b/src/Handler/ContentRangeUploadHandler.php @@ -36,21 +36,21 @@ class ContentRangeUploadHandler extends AbstractHandler /** * Current chunk start bytes. * - * @var int + * @var float */ protected $bytesStart = 0; /** * Current chunk bytes end. * - * @var int + * @var float */ protected $bytesEnd = 0; /** * The files total bytes. * - * @var int + * @var float */ protected $bytesTotal = 0; @@ -153,7 +153,7 @@ public function isFirstChunk() /** * Returns the chunks count. * - * @return int + * @return bool */ public function isLastChunk() { @@ -172,7 +172,7 @@ public function isChunkedUpload() } /** - * @return int returns the starting bytes for current request + * @return float returns the starting bytes for current request */ public function getBytesStart() { @@ -180,7 +180,7 @@ public function getBytesStart() } /** - * @return int returns the ending bytes for current request + * @return float returns the ending bytes for current request */ public function getBytesEnd() { @@ -188,7 +188,7 @@ public function getBytesEnd() } /** - * @return int returns the total bytes for the file + * @return float returns the total bytes for the file */ public function getBytesTotal() { diff --git a/src/Handler/HandlerFactory.php b/src/Handler/HandlerFactory.php index 832cbd6..7f56b70 100644 --- a/src/Handler/HandlerFactory.php +++ b/src/Handler/HandlerFactory.php @@ -37,7 +37,7 @@ class HandlerFactory */ public static function classFromRequest(Request $request, $fallbackClass = null) { - /** @var AbstractHandler $handlerClass */ + /** @var AbstractHandler|string $handlerClass */ foreach (static::$handlers as $handlerClass) { if ($handlerClass::canBeUsedForRequest($request)) { return $handlerClass; diff --git a/src/Handler/SingleUploadHandler.php b/src/Handler/SingleUploadHandler.php index 50e789b..8c91781 100644 --- a/src/Handler/SingleUploadHandler.php +++ b/src/Handler/SingleUploadHandler.php @@ -2,7 +2,6 @@ namespace Pion\Laravel\ChunkUpload\Handler; -use Pion\Laravel\ChunkUpload\Config\AbstractConfig; use Pion\Laravel\ChunkUpload\Save\SingleSave; use Pion\Laravel\ChunkUpload\Storage\ChunkStorage; @@ -16,8 +15,7 @@ class SingleUploadHandler extends AbstractHandler /** * Returns the chunks ave instance for saving. * - * @param ChunkStorage $chunkStorage the chunk storage - * @param AbstractConfig $config the config manager + * @param ChunkStorage $chunkStorage the chunk storage * * @return SingleSave */ @@ -33,7 +31,7 @@ public function startSaving($chunkStorage) */ public function getChunkFileName() { - return null; // never used + return ''; // never used } /** diff --git a/src/Receiver/FileReceiver.php b/src/Receiver/FileReceiver.php index d8367d0..b7f7ab3 100644 --- a/src/Receiver/FileReceiver.php +++ b/src/Receiver/FileReceiver.php @@ -25,7 +25,7 @@ class FileReceiver protected $file; /** - * The handler that detects what upload proccess is beeing used. + * The handler that detects what upload process is being used. * * @var AbstractHandler */ @@ -93,10 +93,10 @@ public function isUploaded() */ public function receive() { - if (false === is_object($this->handler)) { + if (false == is_object($this->handler)) { return false; } - return $this->handler->startSaving($this->chunkStorage, $this->config); + return $this->handler->startSaving($this->chunkStorage); } } diff --git a/src/Save/AbstractSave.php b/src/Save/AbstractSave.php index 2bc900d..2422587 100644 --- a/src/Save/AbstractSave.php +++ b/src/Save/AbstractSave.php @@ -105,8 +105,8 @@ public function getUploadedFile() /** * Passes all the function into the file. * - * @param $name string - * @param $arguments array + * @param string $name + * @param array $arguments * * @return mixed * diff --git a/src/Save/ChunkSave.php b/src/Save/ChunkSave.php index 298d6b1..79c9923 100644 --- a/src/Save/ChunkSave.php +++ b/src/Save/ChunkSave.php @@ -2,6 +2,7 @@ namespace Pion\Laravel\ChunkUpload\Save; +use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract; use Illuminate\Http\UploadedFile; use Pion\Laravel\ChunkUpload\Config\AbstractConfig; use Pion\Laravel\ChunkUpload\Exceptions\ChunkSaveException; @@ -155,7 +156,7 @@ protected function handleChunk() $file = $this->getChunkFilePath(); $this->handleChunkFile($file) - ->tryToBuildFullFileFromChunks(); + ->tryToBuildFullFileFromChunks(); } /** @@ -248,7 +249,7 @@ public function chunkStorage() /** * Returns the disk adapter for the chunk. * - * @return \Illuminate\Filesystem\FilesystemAdapter + * @return FilesystemContract */ public function chunkDisk() { diff --git a/src/Save/ParallelSave.php b/src/Save/ParallelSave.php index eacbf42..8f17170 100644 --- a/src/Save/ParallelSave.php +++ b/src/Save/ParallelSave.php @@ -3,6 +3,7 @@ namespace Pion\Laravel\ChunkUpload\Save; use Illuminate\Http\UploadedFile; +use Illuminate\Support\Collection; use Illuminate\Support\Str; use Pion\Laravel\ChunkUpload\ChunkFile; use Pion\Laravel\ChunkUpload\Config\AbstractConfig; @@ -35,10 +36,10 @@ class ParallelSave extends ChunkSave /** * ParallelSave constructor. * - * @param UploadedFile $file the uploaded file (chunk file) - * @param AbstractHandler|HandleParallelUploadTrait $handler the handler that detected the correct save method - * @param ChunkStorage $chunkStorage the chunk storage - * @param AbstractConfig $config the config manager + * @param UploadedFile $file the uploaded file (chunk file) + * @param AbstractHandler $handler the handler that detected the correct save method + * @param ChunkStorage $chunkStorage the chunk storage + * @param AbstractConfig $config the config manager * * @throws ChunkSaveException */ @@ -87,7 +88,7 @@ protected function handleChunkFile($file) /** * Searches for all chunk files. * - * @return \Illuminate\Support\Collection + * @return Collection */ protected function getSavedChunksFiles() { diff --git a/src/Storage/ChunkStorage.php b/src/Storage/ChunkStorage.php index 882a837..bc534e0 100644 --- a/src/Storage/ChunkStorage.php +++ b/src/Storage/ChunkStorage.php @@ -187,7 +187,7 @@ public function config() } /** - * @return FilesystemAdapter + * @return FilesystemContract */ public function disk() { @@ -197,7 +197,7 @@ public function disk() /** * Returns the driver. * - * @return FilesystemOperator|FilesystemInterface + * @return FilesystemInterface */ public function driver() {