Skip to content

Commit

Permalink
Merge pull request #14 from amirHossein5/analysis-e7mvda
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
amirHossein5 authored May 9, 2022
2 parents c5c8ab1 + dd30057 commit 70cfd22
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 172 deletions.
2 changes: 1 addition & 1 deletion src/Facades/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @method static void commit()
* @method static void beginTransaction()
* @method static self quality(int $quality)
*
*
**/
class Image extends Facade
{
Expand Down
42 changes: 21 additions & 21 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Illuminate\Http\UploadedFile;
use Intervention\Image\Facades\Image as Intervention;
use Symfony\Component\Routing\Exception\InvalidParameterException;
use Intervention\Image\Image as InterventionImage;
use Symfony\Component\Routing\Exception\InvalidParameterException;

class Image
{
Expand All @@ -16,7 +16,7 @@ class Image

/**
* Image quality.
*
*
* @var int
*/
public int $quality = 90;
Expand Down Expand Up @@ -50,7 +50,7 @@ class Image

/**
* On Transactioning it shows the image is going to be replave.
*
*
* @var bool
*/
private bool $willBeReplace = false;
Expand All @@ -77,7 +77,7 @@ public function disk(string $disk): self
$this->hiddenPath = config("image.disks.{$disk}");

if (!$this->hiddenPath) {
throw new InvalidParameterException('Undefined disk ' . $disk);
throw new InvalidParameterException('Undefined disk '.$disk);
}

$this->disk = $disk;
Expand All @@ -86,7 +86,7 @@ public function disk(string $disk): self
}

/**
* Determines way of saving. $image can be UploadedFile laravel object or intervention.
* Determines way of saving. $image can be UploadedFile laravel object or intervention.
*
* @param \Illuminate\Http\UploadedFile|Intervention\Image\Image $image
*
Expand All @@ -102,7 +102,7 @@ public function raw($image): self
}

/**
* Determines way of saving. $image can be UploadedFile laravel object or intervention.
* Determines way of saving. $image can be UploadedFile laravel object or intervention.
*
* @param \Illuminate\Http\UploadedFile|Intervention\Image\Image $image
*
Expand Down Expand Up @@ -131,7 +131,7 @@ public function fake(): void
* Sets image quality.
*
* @param int $quality
*
*
* @return self
*/
public function quality(int $quality): self
Expand Down Expand Up @@ -167,14 +167,14 @@ public function save(bool $upsize = false, ?\Closure $closure = null)
// saving image
if ($this->transactioning) {
$this->transactionBag[] = [
'image' => $this->image,
'sizes' => $this->sizes,
'imagePath' => $this->imagePath,
'image' => $this->image,
'sizes' => $this->sizes,
'imagePath' => $this->imagePath,
'imageDirectory' => $this->imageDirectory,
'upsize' => $upsize,
'disk' => $this->disk,
'willBeReplace' => $this->willBeReplace,
'quality' => $this->quality,
'upsize' => $upsize,
'disk' => $this->disk,
'willBeReplace' => $this->willBeReplace,
'quality' => $this->quality,
];
} else {
if (!$this->mkdirIfNotExists($this->imageDirectory)) {
Expand Down Expand Up @@ -226,13 +226,13 @@ public function replace(bool $upsize = false, ?\Closure $closure = null)

/**
* Stores image(s).
*
*
* @param Intervention\Image\Image $image
* @param null|array $sizes
* @param array|string $imagePath
* @param bool $upsize
* @param int $quality
*
* @param null|array $sizes
* @param array|string $imagePath
* @param bool $upsize
* @param int $quality
*
* @return void
*/
private function store(InterventionImage $image, ?array $sizes, $imagePath, bool $upsize, int $quality): void
Expand Down Expand Up @@ -281,7 +281,7 @@ private function mkdirIfNotExists(string $path): bool
*/
private function disk_path(string $path): string
{
return $this->hiddenPath . DIRECTORY_SEPARATOR . $path;
return $this->hiddenPath.DIRECTORY_SEPARATOR.$path;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Pathable.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function be(string $nameWithFormat): self

$name = $nameWithFormat;
array_pop($name);

$this->imageName = trim(implode('.', $name), '.');

return $this;
Expand Down Expand Up @@ -209,7 +209,7 @@ private function setDefaultsForImagePath(): void
private function setRawDefaults(): void
{
$this->sizesDirectory = $this->random(false);
$this->imageFormat = preg_replace('/image\//', '',$this->image->mime() ?? 'image/png');
$this->imageFormat = preg_replace('/image\//', '', $this->image->mime() ?? 'image/png');
$this->imageName = $this->random();
$this->hiddenPath = config('image.disks.public');
$this->disk = 'public';
Expand Down
2 changes: 2 additions & 0 deletions src/Sizeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ public function setDefaultSizeFor(array $image, string $sizeName, ?string $pathK
if ($pathKeys != 'index') {
if (array_key_exists($sizeName, $image[$pathKeys])) {
$image['default_size'] = $sizeName;

return $image;
}
} else {
$image['default_size'] = $sizeName;

return $image;
}

Expand Down
43 changes: 21 additions & 22 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,37 @@

namespace AmirHossein5\LaravelImage;

use AmirHossein5\LaravelImage\Facades\Image;

trait Transaction
{
/**
* Whether on transaction or not.
*
*
* @var bool
*/
protected bool $transactioning = false;

/**
* Array of saved images.
*
*
* @var array
*/
protected array $transactionBag = [];

/**
* Transaction function.
*
*
* @param \Closure $closure
* @param int $attempts = 1
*
* @return void
*
* @param int $attempts = 1
*
* @throws \Throwable
*
* @return void
*/
public function transaction(\Closure $callback, int $maxAttempts = 1): void
{
if ($maxAttempts <= 0) {
throw new \LogicException('max attempts should be more than 0');
}
}

for ($currentAttempt = 1; $currentAttempt <= $maxAttempts; $currentAttempt++) {
$this->beginTransaction();
Expand All @@ -56,15 +54,15 @@ public function transaction(\Closure $callback, int $maxAttempts = 1): void
$currentAttempt,
$maxAttempts
);

continue;
}
}
}

/**
* Starts the transaction.
*
*
* @return void
*/
public function beginTransaction(): void
Expand All @@ -74,15 +72,15 @@ public function beginTransaction(): void

/**
* Commits the transaction.
*
*
* @return void
*/
public function commit(): void
{
if ($this->transactioning === false) {
return;
}

foreach ($this->transactionBag as $transactioned) {
$this->disk($transactioned['disk']);
$this->mkdirIfNotExists($transactioned['imageDirectory']);
Expand All @@ -106,7 +104,7 @@ public function commit(): void

/**
* RollBacks the transaction.
*
*
* @return void
*/
public function rollBack(): void
Expand All @@ -120,20 +118,21 @@ public function rollBack(): void
}

/**
* Handles the exception
*
* Handles the exception.
*
* @param \Throwable $e
* @param int $currentAttempts = 1
* @param int $maxAttempts = 1
*
* @return void
*
* @param int $currentAttempts = 1
* @param int $maxAttempts = 1
*
* @throws \Throwable
*
* @return void
*/
private function handleTransactionException(\Throwable $e, int $currentAttempt = 1, int $maxAttempts = 1): void
{
if ($currentAttempt >= $maxAttempts) {
$this->rollBack();

throw $e;
}
}
Expand Down
Loading

0 comments on commit 70cfd22

Please sign in to comment.