Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New life of: Introduce static analysis + Fixes #87

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 53 additions & 45 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]"
}
],
"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": "[email protected]"
}
],
"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"
}
24 changes: 24 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $containerConfigurator): void {
$containerConfigurator->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,
]);
};
20 changes: 20 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
use Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector;
use Rector\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector;
use Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector;

return static function (RectorConfig $config): void {
$config->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,
]);
};
2 changes: 1 addition & 1 deletion src/Config/AbstractConfig.php
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ abstract public function clearTimestampString();
/**
* Returns the schedule config array.
*
* @return array<enable,cron>
* @return array{enable: bool, cron: string}
*/
abstract public function scheduleConfig();

2 changes: 1 addition & 1 deletion src/Config/FileConfig.php
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ public function clearTimestampString()
/**
* Returns the shedule config array.
*
* @return array<enable,cron>
* @return array{enable: bool, cron: string}
*/
public function scheduleConfig()
{
2 changes: 1 addition & 1 deletion src/Handler/ChunksInRequestUploadHandler.php
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ public function isFirstChunk()
/**
* Checks if the chunk is last.
*
* @return int
* @return bool
*/
public function isLastChunk()
{
14 changes: 7 additions & 7 deletions src/Handler/ContentRangeUploadHandler.php
Original file line number Diff line number Diff line change
@@ -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,23 +172,23 @@ public function isChunkedUpload()
}

/**
* @return int returns the starting bytes for current request
* @return float returns the starting bytes for current request
*/
public function getBytesStart()
{
return $this->bytesStart;
}

/**
* @return int returns the ending bytes for current request
* @return float returns the ending bytes for current request
*/
public function getBytesEnd()
{
return $this->bytesEnd;
}

/**
* @return int returns the total bytes for the file
* @return float returns the total bytes for the file
*/
public function getBytesTotal()
{
2 changes: 1 addition & 1 deletion src/Handler/HandlerFactory.php
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 2 additions & 4 deletions src/Handler/SingleUploadHandler.php
Original file line number Diff line number Diff line change
@@ -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
}

/**
6 changes: 3 additions & 3 deletions src/Receiver/FileReceiver.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 2 additions & 2 deletions src/Save/AbstractSave.php
Original file line number Diff line number Diff line change
@@ -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
*
5 changes: 3 additions & 2 deletions src/Save/ChunkSave.php
Original file line number Diff line number Diff line change
@@ -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()
{
11 changes: 6 additions & 5 deletions src/Save/ParallelSave.php
Original file line number Diff line number Diff line change
@@ -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()
{
4 changes: 2 additions & 2 deletions src/Storage/ChunkStorage.php
Original file line number Diff line number Diff line change
@@ -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()
{