Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pionl committed Sep 10, 2018
1 parent 8421555 commit dc0811a
Show file tree
Hide file tree
Showing 31 changed files with 359 additions and 326 deletions.
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*",
Expand All @@ -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": {
Expand Down
42 changes: 21 additions & 21 deletions config/chunk-upload.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?php
return [

/**
return [
/*
* The storage config
*/
"storage" => [
/**
'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?
],
],
],
];
25 changes: 13 additions & 12 deletions src/ChunkFile.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

namespace Pion\Laravel\ChunkUpload;

use Pion\Laravel\ChunkUpload\Storage\ChunkStorage;

/**
* Class Chunk
*
* @package Pion\Laravel\ChunkUpload
* Class Chunk.
*/
class ChunkFile
{
Expand All @@ -21,18 +20,18 @@ class ChunkFile
protected $modifiedTime;

/**
* The chunk storage
* The chunk storage.
*
* @var ChunkStorage
*/
protected $storage;

/**
* Creates the chunk file
* Creates the chunk file.
*
* @param string $path
* @param int $modifiedTime
* @param ChunkStorage $storage
* @param string $path
* @param int $modifiedTime
* @param ChunkStorage $storage
*/
public function __construct($path, $modifiedTime, $storage)
{
Expand Down Expand Up @@ -63,7 +62,7 @@ public function getModifiedTime()
}

/**
* Moves the chunk file to given relative path (within the disk)
* Moves the chunk file to given relative path (within the disk).
*
* @param string $pathTo
*
Expand All @@ -75,7 +74,8 @@ public function move($pathTo)
}

/**
* Deletes the chunk file
* Deletes the chunk file.
*
* @return bool
*/
public function delete()
Expand All @@ -87,10 +87,11 @@ public function delete()
* The __toString method allows a class to decide how it will react when it is converted to a string.
*
* @return string
* @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring
*
* @see http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring
*/
public function __toString()
{
return sprintf("ChunkFile %s uploaded at %s", $this->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()));
}
}
21 changes: 11 additions & 10 deletions src/Commands/ClearChunksCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Pion\Laravel\ChunkUpload\Commands;

use Illuminate\Console\Command;
Expand All @@ -23,9 +24,8 @@ class ClearChunksCommand extends Command
*/
protected $description = 'Clears the chunks upload directory. Deletes only .part objects.';


/**
* Clears the chunks upload directory
* Clears the chunks upload directory.
*
* @param ChunkStorage $storage injected chunk storage
*/
Expand All @@ -35,28 +35,29 @@ public function handle(ChunkStorage $storage)

// try to get the old chunk files
$oldFiles = $storage->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));
}
}
19 changes: 11 additions & 8 deletions src/Config/AbstractConfig.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace Pion\Laravel\ChunkUpload\Config;

abstract class AbstractConfig
{
/**
* Returns the config from the application container
* Returns the config from the application container.
*
* @return AbstractConfig
*
Expand All @@ -16,42 +17,44 @@ public static function config()
}

/**
* Returns the disk name to use for the chunk storage
* Returns the disk name to use for the chunk storage.
*
* @return string
*/
abstract public function chunksDiskName();

/**
* The storage path for the chunks
* The storage path for the chunks.
*
* @return string the full path to the storage
*/
abstract public function chunksStorageDirectory();

/**
* Returns the time stamp string for clear command
* Returns the time stamp string for clear command.
*
* @return string
*/
abstract public function clearTimestampString();

/**
* Returns the schedule config array
* Returns the schedule config array.
*
* @return array<enable,cron>
*/
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();
}
43 changes: 21 additions & 22 deletions src/Config/FileConfig.php
Original file line number Diff line number Diff line change
@@ -1,96 +1,95 @@
<?php

namespace Pion\Laravel\ChunkUpload\Config;

/**
* Class FileConfig
* Class FileConfig.
*
* Enables loading a config settings from the Laravel Config facade.
*
* @package Pion\Laravel\ChunkUpload\Config
*/
class FileConfig extends AbstractConfig
{
/**
* The file name of the config
* The file name of the config.
*/
const FILE_NAME = "chunk-upload";
const FILE_NAME = 'chunk-upload';

/**
* Returns the disk name to use for the chunk storage
* Returns the disk name to use for the chunk storage.
*
* @return string
*/
public function chunksDiskName()
{
return $this->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
*
* @see FileConfig::get()
*/
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
*
* @see FileConfig::get()
*/
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<enable,cron>
*/
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);
}
}
4 changes: 1 addition & 3 deletions src/Exceptions/ChunkInvalidValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use Exception;

/**
* Class ChunkInvalidValueException
*
* @package Pion\Laravel\ChunkUpload\Exception
* Class ChunkInvalidValueException.
*/
class ChunkInvalidValueException extends \Exception
{
Expand Down
Loading

0 comments on commit dc0811a

Please sign in to comment.