diff --git a/composer.json b/composer.json index dc29299..b1cd203 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,9 @@ } ], "scripts": { - "analyze": "./vendor/bin/phpcs", - "analyze-fix": "./vendor/bin/phpcbf" + "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" }, "require": { "illuminate/http": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", @@ -22,7 +23,8 @@ "laravel/laravel": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", "phpunit/phpunit": "5.7 || 6.0 || 7.0", "mockery/mockery": "^0.9.9", - "squizlabs/php_codesniffer": "^3.2" + "friendsofphp/php-cs-fixer": "^2.12", + "overtrue/phplint": "^1.1" }, "autoload": { "psr-4": { diff --git a/config/chunk-upload.php b/config/chunk-upload.php index 01aa6cc..c962eea 100644 --- a/config/chunk-upload.php +++ b/config/chunk-upload.php @@ -1,33 +1,33 @@ [ - /** + 'storage' => [ + /* * Returns the folder name of the chunks. The location is in storage/app/{folder_name} */ - "chunks" => "chunks", - "disk" => "local" + 'chunks' => 'chunks', + 'disk' => 'local', ], - "clear" => [ - /** + 'clear' => [ + /* * How old chunks we should delete */ - "timestamp" => "-3 HOURS", - "schedule" => [ - "enabled" => true, - "cron" => "25 * * * *" // run every hour on the 25th minute - ] + 'timestamp' => '-3 HOURS', + 'schedule' => [ + 'enabled' => true, + 'cron' => '25 * * * *', // run every hour on the 25th minute + ], ], - "chunk" => [ + 'chunk' => [ // setup for the chunk naming setup to ensure same name upload at same time - "name" => [ - "use" => [ - "session" => true, // should the chunk name use the session id? The uploader must send cookie!, - "browser" => false // instead of session we can use the ip and browser? - ] - ] - ] + 'name' => [ + 'use' => [ + 'session' => true, // should the chunk name use the session id? The uploader must send cookie!, + 'browser' => false, // instead of session we can use the ip and browser? + ], + ], + ], ]; diff --git a/src/ChunkFile.php b/src/ChunkFile.php index f5630d5..1225136 100644 --- a/src/ChunkFile.php +++ b/src/ChunkFile.php @@ -1,12 +1,11 @@ getPath(), date("Y-m-d H:i:s", $this->getModifiedTime())); + return sprintf('ChunkFile %s uploaded at %s', $this->getPath(), date('Y-m-d H:i:s', $this->getModifiedTime())); } } diff --git a/src/Commands/ClearChunksCommand.php b/src/Commands/ClearChunksCommand.php index dedc206..5956297 100644 --- a/src/Commands/ClearChunksCommand.php +++ b/src/Commands/ClearChunksCommand.php @@ -1,4 +1,5 @@ oldChunkFiles(); - + if ($oldFiles->isEmpty()) { - $this->warn("Chunks: no old files"); + $this->warn('Chunks: no old files'); + return; } - - $this->info(sprintf("Found %d chunk files", $oldFiles->count()), $verbouse); + + $this->info(sprintf('Found %d chunk files', $oldFiles->count()), $verbouse); $deleted = 0; /** @var ChunkFile $file */ foreach ($oldFiles as $file) { // debug the file info - $this->comment("> ".$file, $verbouse); + $this->comment('> '.$file, $verbouse); // delete the file if ($file->delete()) { - $deleted++; + ++$deleted; } else { - $this->error("> chunk not deleted: ".$file); + $this->error('> chunk not deleted: '.$file); } } - $this->info("Chunks: cleared ".$deleted." ".Str::plural("file", $deleted)); + $this->info('Chunks: cleared '.$deleted.' '.Str::plural('file', $deleted)); } } diff --git a/src/Config/AbstractConfig.php b/src/Config/AbstractConfig.php index 7207812..5acffa9 100644 --- a/src/Config/AbstractConfig.php +++ b/src/Config/AbstractConfig.php @@ -1,10 +1,11 @@ */ abstract public function scheduleConfig(); @@ -43,15 +47,14 @@ abstract public function scheduleConfig(); /** * Should the chunk name add a session? * - * @return boolean + * @return bool */ abstract public function chunkUseSessionForName(); - /** * Should the chunk name add a ip address? * - * @return boolean + * @return bool */ abstract public function chunkUseBrowserInfoForName(); } diff --git a/src/Config/FileConfig.php b/src/Config/FileConfig.php index d1f02b7..9041c9f 100644 --- a/src/Config/FileConfig.php +++ b/src/Config/FileConfig.php @@ -1,33 +1,31 @@ get("storage.disk"); + return $this->get('storage.disk'); } - /** - * The storage path for the chunks + * The storage path for the chunks. * * @return string the full path to the storage * @@ -35,11 +33,11 @@ public function chunksDiskName() */ public function chunksStorageDirectory() { - return $this->get("storage.chunks"); + return $this->get('storage.chunks'); } /** - * Returns the time stamp string for clear command + * Returns the time stamp string for clear command. * * @return string * @@ -47,50 +45,51 @@ public function chunksStorageDirectory() */ public function clearTimestampString() { - return $this->get("clear.timestamp"); + return $this->get('clear.timestamp'); } /** - * Returns the shedule config array + * Returns the shedule config array. + * * @return array */ public function scheduleConfig() { - return $this->get("clear.schedule"); + return $this->get('clear.schedule'); } /** * Should the chunk name add a session? * - * @return boolean + * @return bool */ public function chunkUseSessionForName() { - return $this->get("chunk.name.use.session", true); + return $this->get('chunk.name.use.session', true); } /** * Should the chunk name add a ip address? * - * @return boolean + * @return bool */ public function chunkUseBrowserInfoForName() { - return $this->get("chunk.name.use.browser", false); + return $this->get('chunk.name.use.browser', false); } /** - * Returns a chunks config value - * - * @param string $key the config name is prepended to the key value + * Returns a chunks config value. * + * @param string $key the config name is prepended to the key value * @param mixed|null $default * * @return mixed + * * @see \Config::get() */ public function get($key, $default = null) { - return config(self::FILE_NAME.".".$key, $default); + return config(self::FILE_NAME.'.'.$key, $default); } } diff --git a/src/Exceptions/ChunkInvalidValueException.php b/src/Exceptions/ChunkInvalidValueException.php index b62bb50..0e6bf16 100644 --- a/src/Exceptions/ChunkInvalidValueException.php +++ b/src/Exceptions/ChunkInvalidValueException.php @@ -5,9 +5,7 @@ use Exception; /** - * Class ChunkInvalidValueException - * - * @package Pion\Laravel\ChunkUpload\Exception + * Class ChunkInvalidValueException. */ class ChunkInvalidValueException extends \Exception { diff --git a/src/Exceptions/ChunkSaveException.php b/src/Exceptions/ChunkSaveException.php index e71f737..be8f581 100644 --- a/src/Exceptions/ChunkSaveException.php +++ b/src/Exceptions/ChunkSaveException.php @@ -1,7 +1,7 @@ getDrivers(); // Check if the driver is valid and started - allow using session - if (isset($drivers[$driver]) && $drivers[$driver]->isStarted() === true) { + if (isset($drivers[$driver]) && true === $drivers[$driver]->isStarted()) { return true; } + return false; } /** * Builds the chunk file name per session and the original name. You can * provide custom additional name at the end of the generated file name. All chunk - * files has .part extension + * files has .part extension. * - * @param string|null $additionalName Make the name more unique (example: use id from request) + * @param string|null $additionalName Make the name more unique (example: use id from request) * @param string|null $currentChunkIndex Add the chunk index for parallel upload * * @return string @@ -92,13 +92,13 @@ public function createChunkFileName($additionalName = null, $currentChunkIndex = { // prepare basic name structure $array = [ - $this->file->getClientOriginalName() + $this->file->getClientOriginalName(), ]; // ensure that the chunk name is for unique for the client session $useSession = $this->config->chunkUseSessionForName(); $useBrowser = $this->config->chunkUseBrowserInfoForName(); - if ($useSession && static::canUseSession() === false) { + if ($useSession && false === static::canUseSession()) { $useBrowser = true; $useSession = false; } @@ -110,7 +110,7 @@ public function createChunkFileName($additionalName = null, $currentChunkIndex = // can work without any additional setup if ($useBrowser) { - $array[] = md5($this->request->ip().$this->request->header("User-Agent", "no-browser")); + $array[] = md5($this->request->ip().$this->request->header('User-Agent', 'no-browser')); } // Add additional name for more unique chunk name @@ -120,11 +120,11 @@ public function createChunkFileName($additionalName = null, $currentChunkIndex = // Build the final name - parts separated by dot $namesSeparatedByDot = [ - implode('-', $array) + implode('-', $array), ]; // Add the chunk index for parallel upload - if ($currentChunkIndex !== null) { + if (null !== $currentChunkIndex) { $namesSeparatedByDot[] = $currentChunkIndex; } @@ -136,44 +136,44 @@ public function createChunkFileName($additionalName = null, $currentChunkIndex = } /** - * Creates save instance and starts saving the uploaded file + * Creates save instance and starts saving the uploaded file. * - * @param ChunkStorage $chunkStorage the chunk storage + * @param ChunkStorage $chunkStorage the chunk storage * * @return AbstractSave */ abstract public function startSaving($chunkStorage); /** - * Returns the chunk file name for a storing the tmp file + * Returns the chunk file name for a storing the tmp file. * * @return string */ abstract public function getChunkFileName(); /** - * Checks if the request has first chunk + * Checks if the request has first chunk. * * @return bool */ abstract public function isFirstChunk(); /** - * Checks if the current request has the last chunk + * Checks if the current request has the last chunk. * * @return bool */ abstract public function isLastChunk(); /** - * Checks if the current request is chunked upload + * Checks if the current request is chunked upload. * * @return bool */ abstract public function isChunkedUpload(); /** - * Returns the percentage of the upload file + * Returns the percentage of the upload file. * * @return int */ diff --git a/src/Handler/ChunksInRequestSimpleUploadHandler.php b/src/Handler/ChunksInRequestSimpleUploadHandler.php index 6f26cca..50017cd 100644 --- a/src/Handler/ChunksInRequestSimpleUploadHandler.php +++ b/src/Handler/ChunksInRequestSimpleUploadHandler.php @@ -1,25 +1,26 @@ currentChunk == 1; + return 1 == $this->currentChunk; } /** - * Checks if the chunk is last + * Checks if the chunk is last. * * @return int */ @@ -130,7 +134,7 @@ public function isLastChunk() } /** - * Returns the current chunk index + * Returns the current chunk index. * * @return bool */ @@ -140,7 +144,7 @@ public function isChunkedUpload() } /** - * Returns the chunk file name. Uses the original client name and the total bytes + * Returns the chunk file name. Uses the original client name and the total bytes. * * @return string returns the original name with the part extension * @@ -168,7 +172,8 @@ public function getCurrentChunk() } /** - * Returns the percentage of the uploaded file + * Returns the percentage of the uploaded file. + * * @return int */ public function getPercentageDone() diff --git a/src/Handler/ContentRangeUploadHandler.php b/src/Handler/ContentRangeUploadHandler.php index 0136b58..45c33fb 100644 --- a/src/Handler/ContentRangeUploadHandler.php +++ b/src/Handler/ContentRangeUploadHandler.php @@ -1,4 +1,5 @@ bytesStart == 0; + return 0 == $this->bytesStart; } /** - * Returns the chunks count + * Returns the chunks count. * * @return int */ @@ -156,7 +162,7 @@ public function isLastChunk() } /** - * Returns the current chunk index + * Returns the current chunk index. * * @return bool */ @@ -190,7 +196,7 @@ public function getBytesTotal() } /** - * Returns the chunk file name. Uses the original client name and the total bytes + * Returns the chunk file name. Uses the original client name and the total bytes. * * @return string returns the original name with the part extension * @@ -207,7 +213,7 @@ public function getChunkFileName() public function getPercentageDone() { // Check that we have received total bytes - if ($this->getBytesTotal() == 0) { + if (0 == $this->getBytesTotal()) { return 0; } diff --git a/src/Handler/DropZoneUploadHandler.php b/src/Handler/DropZoneUploadHandler.php index feb7bf3..b0ca765 100644 --- a/src/Handler/DropZoneUploadHandler.php +++ b/src/Handler/DropZoneUploadHandler.php @@ -1,4 +1,5 @@ fileUuid = $request->get(self::CHUNK_UUID_INDEX); } - /** - * Builds the chunk file name from file uuid and current chunk + * Builds the chunk file name from file uuid and current chunk. + * * @return string */ public function getChunkFileName() @@ -47,7 +49,7 @@ public function getChunkFileName() } /** - * Returns current chunk from the request + * Returns current chunk from the request. * * @param Request $request * @@ -59,7 +61,7 @@ protected function getCurrentChunkFromRequest(Request $request) } /** - * Returns current chunk from the request + * Returns current chunk from the request. * * @param Request $request * @@ -70,9 +72,8 @@ protected function getTotalChunksFromRequest(Request $request) return intval($request->get(self::CHUNK_TOTAL_INDEX, 1)); } - /** - * Checks if the current abstract handler can be used via HandlerFactory + * Checks if the current abstract handler can be used via HandlerFactory. * * @param Request $request * diff --git a/src/Handler/HandlerFactory.php b/src/Handler/HandlerFactory.php index 7904cdd..26384ac 100644 --- a/src/Handler/HandlerFactory.php +++ b/src/Handler/HandlerFactory.php @@ -1,4 +1,5 @@ has(self::CHUNK_NUMBER_INDEX) && $request->has(self::TOTAL_CHUNKS_INDEX) && $request->has(self::CHUNK_UUID_INDEX); } - -} \ No newline at end of file +} diff --git a/src/Handler/SingleUploadHandler.php b/src/Handler/SingleUploadHandler.php index f888760..50e789b 100644 --- a/src/Handler/SingleUploadHandler.php +++ b/src/Handler/SingleUploadHandler.php @@ -1,4 +1,5 @@ config ); } -} \ No newline at end of file +} diff --git a/src/Providers/ChunkUploadServiceProvider.php b/src/Providers/ChunkUploadServiceProvider.php index f5783a3..9d985fc 100644 --- a/src/Providers/ChunkUploadServiceProvider.php +++ b/src/Providers/ChunkUploadServiceProvider.php @@ -1,8 +1,8 @@ scheduleConfig(); // Run only if schedule is enabled - if (Arr::get($scheduleConfig, "enabled", false) === true) { + if (true === Arr::get($scheduleConfig, 'enabled', false)) { // Wait until the app is fully booted $this->app->booted(function () use ($scheduleConfig) { - // Get the scheduler instance /** @var Schedule $schedule */ $schedule = $this->app->make(Schedule::class); // Register the clear chunks with custom schedule - $schedule->command('uploads:clear')->cron(Arr::get($scheduleConfig, "cron", "* * * * *")); + $schedule->command('uploads:clear')->cron(Arr::get($scheduleConfig, 'cron', '* * * * *')); }); } } - /** * Register the package requirements. * @@ -50,7 +47,7 @@ public function register() { // Register the commands $this->commands([ - ClearChunksCommand::class + ClearChunksCommand::class, ]); // Register the config @@ -70,8 +67,7 @@ public function register() return new ChunkStorage(Storage::disk($config->chunksDiskName()), $config); }); - - /** + /* * Bind a FileReceiver for dependency and use only the first object */ $this->app->bind(FileReceiver::class, function ($app) { @@ -87,7 +83,7 @@ public function register() } /** - * Publishes and mergers the config. Uses the FileConfig + * Publishes and mergers the config. Uses the FileConfig. * * @see FileConfig * @see ServiceProvider::publishes @@ -97,7 +93,7 @@ protected function registerConfig() { // Config options $configIndex = FileConfig::FILE_NAME; - $configFileName = FileConfig::FILE_NAME.".php"; + $configFileName = FileConfig::FILE_NAME.'.php'; $configPath = __DIR__.'/../../config/'.$configFileName; // Publish the config diff --git a/src/Receiver/FileReceiver.php b/src/Receiver/FileReceiver.php index c269bb5..11317e4 100644 --- a/src/Receiver/FileReceiver.php +++ b/src/Receiver/FileReceiver.php @@ -1,4 +1,5 @@ file) && $this->file->getError() !== UPLOAD_ERR_NO_FILE; + return is_object($this->file) && UPLOAD_ERR_NO_FILE !== $this->file->getError(); } /** @@ -91,7 +93,7 @@ public function isUploaded() */ public function receive() { - if (is_object($this->handler) === false) { + if (false === is_object($this->handler)) { return false; } diff --git a/src/Save/AbstractSave.php b/src/Save/AbstractSave.php index 7bff1da..e9fdd66 100644 --- a/src/Save/AbstractSave.php +++ b/src/Save/AbstractSave.php @@ -1,4 +1,5 @@ handleChunk(); } - /** - * Checks if the file upload is finished (last chunk) + * Checks if the file upload is finished (last chunk). * * @return bool */ @@ -76,7 +77,7 @@ public function isFinished() } /** - * Returns the chunk file path in the current disk instance + * Returns the chunk file path in the current disk instance. * * @param bool $absolutePath * @@ -88,7 +89,8 @@ public function getChunkFilePath($absolutePath = false) } /** - * Returns the full file path + * Returns the full file path. + * * @return string */ public function getChunkFullFilePath() @@ -97,9 +99,9 @@ public function getChunkFullFilePath() } /** - * Returns the folder for the cunks in the storage path on current disk instance + * Returns the folder for the cunks in the storage path on current disk instance. * - * @param boolean $absolutePath + * @param bool $absolutePath * * @return string */ @@ -113,12 +115,12 @@ public function getChunkDirectory($absolutePath = false) $paths[] = $this->chunkStorage()->directory(); - return implode("", $paths); + return implode('', $paths); } /** * Returns the uploaded file if the chunk if is not completed, otherwise passes the - * final chunk file + * final chunk file. * * @return null|UploadedFile */ @@ -131,7 +133,6 @@ public function getFile() return parent::getFile(); } - /** * @deprecated * @since v1.1.8 @@ -142,7 +143,7 @@ protected function handleChunkMerge() } /** - * Appends the new uploaded data to the final file + * Appends the new uploaded data to the final file. * * @throws ChunkSaveException */ @@ -157,7 +158,8 @@ protected function handleChunk() } /** - * Checks if the current chunk is last + * Checks if the current chunk is last. + * * @return $this */ protected function tryToBuildFullFileFromChunks() @@ -166,15 +168,17 @@ protected function tryToBuildFullFileFromChunks() if ($this->isLastChunk) { $this->buildFullFileFromChunks(); } + return $this; } /** - * Appends the current uploaded file to chunk file + * Appends the current uploaded file to chunk file. * * @param string $file Relative path to chunk * * @return $this + * * @throws ChunkSaveException */ protected function handleChunkFile($file) @@ -193,7 +197,7 @@ protected function handleChunkFile($file) } /** - * Builds the final file + * Builds the final file. */ protected function buildFullFileFromChunks() { @@ -205,7 +209,7 @@ protected function buildFullFileFromChunks() } /** - * Creates the UploadedFile object for given chunk file + * Creates the UploadedFile object for given chunk file. * * @param string $finalPath * @@ -226,7 +230,7 @@ protected function createFullChunkFile($finalPath) } /** - * Returns the current chunk storage + * Returns the current chunk storage. * * @return ChunkStorage */ @@ -236,7 +240,7 @@ public function chunkStorage() } /** - * Returns the disk adapter for the chunk + * Returns the disk adapter for the chunk. * * @return \Illuminate\Filesystem\FilesystemAdapter */ @@ -246,7 +250,7 @@ public function chunkDisk() } /** - * Crates the chunks folder if doesn't exists. Uses recursive create + * Crates the chunks folder if doesn't exists. Uses recursive create. */ protected function createChunksFolderIfNeeded() { diff --git a/src/Save/ParallelSave.php b/src/Save/ParallelSave.php index 913d0d0..debd2e2 100644 --- a/src/Save/ParallelSave.php +++ b/src/Save/ParallelSave.php @@ -13,17 +13,16 @@ use Pion\Laravel\ChunkUpload\Storage\ChunkStorage; /** - * Class ParallelSave + * Class ParallelSave. * * @method HandleParallelUploadTrait|AbstractHandler handler() - * - * @package Pion\Laravel\ChunkUpload\Save */ class ParallelSave extends ChunkSave { protected $totalChunks; /** - * Stored on construct - the file is moved and isValid will return false + * Stored on construct - the file is moved and isValid will return false. + * * @var bool */ protected $isFileValid; @@ -43,8 +42,7 @@ public function __construct( AbstractHandler $handler, ChunkStorage $chunkStorage, AbstractConfig $config - ) - { + ) { // Get current file validation - the file instance is changed $this->isFileValid = $file->isValid(); @@ -57,9 +55,8 @@ public function isValid() return $this->isFileValid; } - /** - * Moves the uploaded chunk file to separate chunk file for merging + * Moves the uploaded chunk file to separate chunk file for merging. * * @param string $file Relative path to chunk * @@ -69,6 +66,7 @@ protected function handleChunkFile($file) { // Move the uploaded file to chunk folder $this->file->move($this->getChunkDirectory(true), $this->chunkFileName); + return $this; } @@ -78,17 +76,18 @@ protected function tryToBuildFullFileFromChunks() } /** - * Searches for all chunk files + * Searches for all chunk files. * * @return \Illuminate\Support\Collection */ protected function getSavedChunksFiles() { $chunkFileName = preg_replace( - "/\.[\d]+\.".ChunkStorage::CHUNK_EXTENSION."$/", '', $this->handler()->getChunkFileName() + "/\.[\d]+\.".ChunkStorage::CHUNK_EXTENSION.'$/', '', $this->handler()->getChunkFileName() ); + return $this->chunkStorage->files(function ($file) use ($chunkFileName) { - return str_contains($file, $chunkFileName) === false; + return false === str_contains($file, $chunkFileName); }); } @@ -100,7 +99,7 @@ protected function buildFullFileFromChunks() { $chunkFiles = $this->getSavedChunksFiles()->all(); - if (count($chunkFiles) === 0) { + if (0 === count($chunkFiles)) { throw new MissingChunkFilesException(); } diff --git a/src/Save/SingleSave.php b/src/Save/SingleSave.php index 6c8061c..41a308d 100644 --- a/src/Save/SingleSave.php +++ b/src/Save/SingleSave.php @@ -1,7 +1,7 @@ disk = $disk; - $driver = $this->driver(); // try to get the adapter - if (!method_exists($driver, "getAdapter")) { - throw new RuntimeException("FileSystem driver must have an adapter implemented"); + if (!method_exists($driver, 'getAdapter')) { + throw new RuntimeException('FileSystem driver must have an adapter implemented'); } // get the disk adapter @@ -77,7 +77,7 @@ public function __construct(FilesystemAdapter $disk, $config) } /** - * The current path for chunks directory + * The current path for chunks directory. * * @return string * @@ -89,20 +89,21 @@ public function getDiskPathPrefix() return $this->diskAdapter->getPathPrefix(); } - throw new RuntimeException("The full path is not supported on current disk - local adapter supported only"); + throw new RuntimeException('The full path is not supported on current disk - local adapter supported only'); } /** - * The current chunks directory + * The current chunks directory. + * * @return string */ public function directory() { - return $this->config->chunksStorageDirectory()."/"; + return $this->config->chunksStorageDirectory().'/'; } /** - * Returns an array of files in the chunks directory + * Returns an array of files in the chunks directory. * * @param \Closure|null $rejectClosure * @@ -118,19 +119,20 @@ public function files($rejectClosure = null) return $filesCollection->reject(function ($file) use ($rejectClosure) { // ensure the file ends with allowed extension - $shouldReject = !preg_match("/.".self::CHUNK_EXTENSION."$/", $file); + $shouldReject = !preg_match('/.'.self::CHUNK_EXTENSION.'$/', $file); if ($shouldReject) { return true; } if (is_callable($rejectClosure)) { return $rejectClosure($file); } + return false; }); } /** - * Returns the old chunk files + * Returns the old chunk files. * * @return Collection collection of a ChunkFile objects */ @@ -157,6 +159,7 @@ public function oldChunkFiles() $collection->push(new ChunkFile($file, $modified, $this)); } }); + return $collection; } @@ -177,7 +180,7 @@ public function disk() } /** - * Returns the driver + * Returns the driver. * * @return FilesystemInterface */ @@ -185,4 +188,4 @@ public function driver() { return $this->disk()->getDriver(); } -} \ No newline at end of file +} diff --git a/tests/Handler/ContentRangeUploadHandlerTest.php b/tests/Handler/ContentRangeUploadHandlerTest.php index 787d4a3..b93b7c0 100644 --- a/tests/Handler/ContentRangeUploadHandlerTest.php +++ b/tests/Handler/ContentRangeUploadHandlerTest.php @@ -4,7 +4,6 @@ use Illuminate\Http\Request; use Illuminate\Http\UploadedFile; -use Illuminate\Support\Facades\Storage; use PHPUnit\Framework\TestCase; use Pion\Laravel\ChunkUpload\Config\FileConfig; use Pion\Laravel\ChunkUpload\Exceptions\ContentRangeValueToLargeException; @@ -12,7 +11,6 @@ class ContentRangeUploadHandlerTest extends TestCase { - public function testInitWithoutBytesRange() { $request = Request::create('test', 'POST', [], [], [], []); @@ -39,7 +37,7 @@ public function testPercentageDoneWithoutBytesRange() public function testValidContentRangeFirstChunk() { $request = Request::create('test', 'POST', [], [], [], [ - 'HTTP_CONTENT_RANGE' => 'bytes 0-100/1200' + 'HTTP_CONTENT_RANGE' => 'bytes 0-100/1200', ]); $file = UploadedFile::fake()->create('test'); @@ -56,7 +54,7 @@ public function testValidContentRangeFirstChunk() public function testValidContentRangeNextChunk() { $request = Request::create('test', 'POST', [], [], [], [ - 'HTTP_CONTENT_RANGE' => 'bytes 100-100/1200' + 'HTTP_CONTENT_RANGE' => 'bytes 100-100/1200', ]); $file = UploadedFile::fake(); @@ -74,7 +72,7 @@ public function testValidContentRangeNextChunk() public function testIsLastChunk() { $request = Request::create('test', 'POST', [], [], [], [ - 'HTTP_CONTENT_RANGE' => 'bytes 1100-1199/1200' + 'HTTP_CONTENT_RANGE' => 'bytes 1100-1199/1200', ]); $file = UploadedFile::fake(); @@ -89,7 +87,7 @@ public function testIsLastChunk() } /** - * Checks if canBeUsedForRequest returns false when content-range is missing + * Checks if canBeUsedForRequest returns false when content-range is missing. */ public function testCanBeUsedForInvalidRequest() { @@ -98,38 +96,38 @@ public function testCanBeUsedForInvalidRequest() } /** - * Checks if canBeUsedForRequest returns false when content-range is invalid + * Checks if canBeUsedForRequest returns false when content-range is invalid. */ public function testCanBeUsedForInvalidContentRangeFormat() { $request = Request::create('test', 'POST', [], [], [], [ - 'HTTP_CONTENT_RANGE' => 'bytes ss-ss' + 'HTTP_CONTENT_RANGE' => 'bytes ss-ss', ]); $this->assertFalse(ContentRangeUploadHandler::canBeUsedForRequest($request)); } /** - * Checks if canBeUsedForRequest returns false when content-range is missing + * Checks if canBeUsedForRequest returns false when content-range is missing. */ public function testCanBeUsedForValidRange() { $request = Request::create('test', 'POST', [], [], [], [ - 'HTTP_CONTENT_RANGE' => 'bytes 100-100/1000' + 'HTTP_CONTENT_RANGE' => 'bytes 100-100/1000', ]); $this->assertTrue(ContentRangeUploadHandler::canBeUsedForRequest($request)); } /** - * Test the maximum float value + * Test the maximum float value. */ public function testMaxFloatValue() { $maxFloat = '18'; - for ($i = 0; $i < 309; $i++) { + for ($i = 0; $i < 309; ++$i) { $maxFloat .= '0'; } $request = Request::create('test', 'POST', [], [], [], [ - 'HTTP_CONTENT_RANGE' => 'bytes 100-100/' . $maxFloat + 'HTTP_CONTENT_RANGE' => 'bytes 100-100/'.$maxFloat, ]); $file = UploadedFile::fake(); @@ -142,7 +140,7 @@ public function testMaxFloatValue() public function testMaxInt() { $request = Request::create('test', 'POST', [], [], [], [ - 'HTTP_CONTENT_RANGE' => 'bytes 100-100/2147483648' + 'HTTP_CONTENT_RANGE' => 'bytes 100-100/2147483648', ]); $file = UploadedFile::fake(); diff --git a/tests/Handler/DropZoneUploadHandlerTest.php b/tests/Handler/DropZoneUploadHandlerTest.php index dd13738..61a7c74 100644 --- a/tests/Handler/DropZoneUploadHandlerTest.php +++ b/tests/Handler/DropZoneUploadHandlerTest.php @@ -11,6 +11,7 @@ class DropZoneUploadHandlerTest extends TestCase { protected $file = null; + protected function setUp() { parent::setUp(); @@ -30,7 +31,7 @@ public function testInitWithoutRequestData() } /** - * Checks if canBeUsedForRequest returns false when data is missing + * Checks if canBeUsedForRequest returns false when data is missing. */ public function testCanBeUsedForInvalidRequest() { @@ -39,25 +40,25 @@ public function testCanBeUsedForInvalidRequest() } /** - * Checks if canBeUsedForRequest returns false when content-range is missing + * Checks if canBeUsedForRequest returns false when content-range is missing. */ public function testCanBeUsedForInvalidRequestPartDaata() { $request = Request::create('test', 'POST', [ - DropZoneUploadHandler::CHUNK_UUID_INDEX => 'test' + DropZoneUploadHandler::CHUNK_UUID_INDEX => 'test', ], [], [], []); $this->assertFalse(DropZoneUploadHandler::canBeUsedForRequest($request)); } /** - * Checks if canBeUsedForRequest returns false when content-range is missing + * Checks if canBeUsedForRequest returns false when content-range is missing. */ public function testCanBeUsedOnValidRequest() { $request = Request::create('test', 'POST', [ DropZoneUploadHandler::CHUNK_UUID_INDEX => 'test', DropZoneUploadHandler::CHUNK_INDEX => '1', - DropZoneUploadHandler::CHUNK_TOTAL_INDEX => '2' + DropZoneUploadHandler::CHUNK_TOTAL_INDEX => '2', ], [], [], []); $this->assertTrue(DropZoneUploadHandler::canBeUsedForRequest($request)); } @@ -67,7 +68,7 @@ public function testValidChunkRequest() $request = Request::create('test', 'POST', [ DropZoneUploadHandler::CHUNK_UUID_INDEX => 'test', DropZoneUploadHandler::CHUNK_INDEX => '0', - DropZoneUploadHandler::CHUNK_TOTAL_INDEX => '2' + DropZoneUploadHandler::CHUNK_TOTAL_INDEX => '2', ], [], [], []); $contentRange = new DropZoneUploadHandler($request, $this->file, new FileConfig()); @@ -85,7 +86,7 @@ public function testValidChunkFinishRequest() $request = Request::create('test', 'POST', [ DropZoneUploadHandler::CHUNK_UUID_INDEX => 'test', DropZoneUploadHandler::CHUNK_INDEX => '1', - DropZoneUploadHandler::CHUNK_TOTAL_INDEX => '2' + DropZoneUploadHandler::CHUNK_TOTAL_INDEX => '2', ], [], [], []); $contentRange = new DropZoneUploadHandler($request, $this->file, new FileConfig()); diff --git a/tests/Handler/NgFileUploadHandlerTest.php b/tests/Handler/NgFileUploadHandlerTest.php index 57f647d..fc0ab92 100644 --- a/tests/Handler/NgFileUploadHandlerTest.php +++ b/tests/Handler/NgFileUploadHandlerTest.php @@ -10,7 +10,6 @@ class NgFileUploadHandlerTest extends TestCase { - /** * @throws \Exception */ @@ -34,9 +33,9 @@ public function testInitWithChunk() 'test', 'POST', [ - '_chunkNumber' => 10, - '_totalSize' => 5000, - '_chunkSize' => 500, + '_chunkNumber' => 10, + '_totalSize' => 5000, + '_chunkSize' => 500, '_currentChunkSize' => 500, ] ); @@ -71,9 +70,9 @@ public function testValidNgFileUploadFirstChunk() 'test', 'POST', [ - '_chunkNumber' => 0, - '_totalSize' => 5000, - '_chunkSize' => 500, + '_chunkNumber' => 0, + '_totalSize' => 5000, + '_chunkSize' => 500, '_currentChunkSize' => 500, ] ); @@ -98,9 +97,9 @@ public function testValidNgFileUploadNextChunk() 'test', 'POST', [ - '_chunkNumber' => 1, - '_totalSize' => 5000, - '_chunkSize' => 500, + '_chunkNumber' => 1, + '_totalSize' => 5000, + '_chunkSize' => 500, '_currentChunkSize' => 500, ] ); @@ -126,9 +125,9 @@ public function testIsLastChunk() 'test', 'POST', [ - '_chunkNumber' => 9, - '_totalSize' => 5000, - '_chunkSize' => 500, + '_chunkNumber' => 9, + '_totalSize' => 5000, + '_chunkSize' => 500, '_currentChunkSize' => 500, ] ); @@ -145,7 +144,7 @@ public function testIsLastChunk() } /** - * Checks if canBeUsedForRequest returns false when chunk is missing + * Checks if canBeUsedForRequest returns false when chunk is missing. * * @throws \Exception */ @@ -156,7 +155,7 @@ public function testCanBeUsedForInvalidRequest() } /** - * Checks if canBeUsedForRequest returns false when content-range is invalid + * Checks if canBeUsedForRequest returns false when content-range is invalid. * * @throws \Exception */ @@ -166,9 +165,9 @@ public function testCanBeUsedForInvalidContentRangeFormat() 'test', 'POST', [ - '_chunkNumber' => 'xx', - '_totalSize' => 'xx', - '_chunkSize' => 'xx', + '_chunkNumber' => 'xx', + '_totalSize' => 'xx', + '_chunkSize' => 'xx', '_currentChunkSize' => 'xx', ] ); @@ -176,7 +175,7 @@ public function testCanBeUsedForInvalidContentRangeFormat() } /** - * Checks if canBeUsedForRequest returns false when content-range is missing + * Checks if canBeUsedForRequest returns false when content-range is missing. * * @throws \Exception */ @@ -186,9 +185,9 @@ public function testCanBeUsedForValidRange() 'test', 'POST', [ - '_chunkNumber' => '0', - '_totalSize' => '10', - '_chunkSize' => '10', + '_chunkNumber' => '0', + '_totalSize' => '10', + '_chunkSize' => '10', '_currentChunkSize' => '10', ] );