Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 authored and github-actions[bot] committed Aug 9, 2022
1 parent c418905 commit d383933
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
54 changes: 31 additions & 23 deletions src/Supports/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class Avatar
{

const IMAGE_JPG = 'jpg';

const COLOR_WHITE = '#FFFFFF';
Expand All @@ -21,7 +20,7 @@ class Avatar
public $extension = self::IMAGE_JPG;

/**
* @var \Intervention\Image\Image|null $image
* @var \Intervention\Image\Image|null
*/
private $image;

Expand All @@ -43,8 +42,8 @@ public function __construct()
/**
* create a avatar image from text
*
* @param string $name
* @param string $extension
* @param string $name
* @param string $extension
* @return string|null
*
* @throws Exception
Expand All @@ -61,9 +60,10 @@ public static function fromText(string $name, string $extension = self::IMAGE_JP
/**
* create a avatar image from input
*
* @param string $key
* @param string $extension
* @param string $key
* @param string $extension
* @return string|null
*
* @throws Exception
*/
public static function fromInput(string $key, string $extension = self::IMAGE_JPG): ?string
Expand All @@ -76,9 +76,10 @@ public static function fromInput(string $key, string $extension = self::IMAGE_JP
}

/**
* @param string $location
* @param string $extension
* @param string $location
* @param string $extension
* @return string|null
*
* @throws Exception
*/
public static function fromFile(string $location, string $extension = self::IMAGE_JPG): ?string
Expand All @@ -91,7 +92,7 @@ public static function fromFile(string $location, string $extension = self::IMAG
}

/**
* @param \Intervention\Image\Image|null $image
* @param \Intervention\Image\Image|null $image
*/
public function setImage(\Intervention\Image\Image $image): void
{
Expand All @@ -106,31 +107,31 @@ public function getImage(): ?\Intervention\Image\Image
/**
* Return temp location path
*
* @param string|null $temp_path
* @param string|null $temp_path
* @return string
*/
public function getTempDirectory(string $temp_path = null): string
{
$tmpPath = $temp_path ?? config('laravolt.avatar.temp_path');

if (!is_dir($tmpPath))
if (! is_dir($tmpPath)) {
mkdir($tmpPath, '0777', true);
}

return $tmpPath;
}

/**
* @param null $extension
* @param null $extension
* @return string
*/
public function getTargetFilePath($extension = null): string
{
$filepath = rtrim($this->getTempDirectory()) . DIRECTORY_SEPARATOR . $this->filename;
$filepath = rtrim($this->getTempDirectory()).DIRECTORY_SEPARATOR.$this->filename;

return ($extension != null)
? "{$filepath}.{$extension}"
: "{$filepath}";

}

/**
Expand All @@ -142,8 +143,9 @@ public function default(): \Intervention\Image\Image
}

/**
* @param string $text
* @param string $text
* @return self
*
* @throws \Exception
*/
private function text(string $text): self
Expand All @@ -154,17 +156,19 @@ private function text(string $text): self
->setDimension($this->config['width'], $this->config['height'])
->getImageObject());
} catch (\Exception $exception) {
Log::error("Avatar from text exception : " . $exception->getMessage());
Log::error('Avatar from text exception : '.$exception->getMessage());
$this->setImage($this->default());
}

return $this;
}

/**
* Return Image Object created from file location
*
* @param string $location
* @param string $location
* @return self
*
* @throws \Exception
*/
private function file(string $location): self
Expand All @@ -173,17 +177,19 @@ private function file(string $location): self
$this->filename($location);
$this->setImage(Image::make($location));
} catch (\Exception $exception) {
Log::error("Avatar from filesystem exception : " . $exception->getMessage());
Log::error('Avatar from filesystem exception : '.$exception->getMessage());
$this->setImage($this->default());
}

return $this;
}

/**
* Return Image Object created from request class
*
* @param string $key
* @param string $key
* @return self
*
* @throws \Exception
*/
private function input(string $key): self
Expand All @@ -193,14 +199,15 @@ private function input(string $key): self
$this->filename($file->getClientOriginalName());
$this->setImage(Image::make($file));
} catch (\Exception $exception) {
Log::error("Avatar from request input exception : " . $exception->getMessage());
Log::error('Avatar from request input exception : '.$exception->getMessage());
$this->setImage($this->default());
}

return $this;
}

/**
* @param string|null $filename
* @param string|null $filename
* @return void
*/
private function filename(string $filename = null)
Expand All @@ -214,14 +221,15 @@ private function filename(string $filename = null)
}

/**
* @param string $extension
* @param string $extension
* @return bool
*/
public function save($extension = self::IMAGE_JPG): bool
{
$img = $this->getImage()
->resize($this->config['width'], $this->config['height'])
->save($this->getTargetFilePath($extension), 100, $extension);
return (bool)($img instanceof \Intervention\Image\Image);

return (bool) ($img instanceof \Intervention\Image\Image);
}
}
2 changes: 1 addition & 1 deletion src/Supports/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static function formatLogFilename(string $filename)
}

/**
* @param Model $model
* @param Model $model
* @return array
*/
public static function modelAudits(Model $model): array
Expand Down

0 comments on commit d383933

Please sign in to comment.