Skip to content

Commit

Permalink
Concise code
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Feb 12, 2024
1 parent 874a11f commit 7cff858
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 69 deletions.
8 changes: 3 additions & 5 deletions src/Manipulators/BaseManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ public function setParams(array $params)
*/
public function getParam(string $name): mixed
{
if (array_key_exists($name, $this->params)) {
return $this->params[$name];
}

return null;
return array_key_exists($name, $this->params)
? $this->params[$name]
: null;
}

/**
Expand Down
80 changes: 16 additions & 64 deletions src/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ public function getSource(): FilesystemOperator
*/
public function getSourcePathPrefix(): ?string
{
if (isset($this->config['source_path_prefix'])) {
return $this->config['source_path_prefix'];
}

return null;
return $this->config['source_path_prefix'] ?? null;
}

/**
Expand Down Expand Up @@ -133,23 +129,15 @@ public function getCache(): FilesystemOperator
*/
public function getCachePathPrefix(): ?string
{
if (isset($this->config['cache_path_prefix'])) {
return $this->config['cache_path_prefix'];
}

return null;
return $this->config['cache_path_prefix'] ?? null;
}

/**
* Get temporary EXIF data directory.
*/
public function getTempDir(): ?string
{
if (isset($this->config['temp_dir'])) {
return $this->config['temp_dir'];
}

return null;
return $this->config['temp_dir'] ?? null;
}

/**
Expand All @@ -169,11 +157,7 @@ public function getCachePathCallable(): ?\Closure
*/
public function getGroupCacheInFolders(): bool
{
if (isset($this->config['group_cache_in_folders'])) {
return $this->config['group_cache_in_folders'];
}

return true;
return $this->config['group_cache_in_folders'] ?? true;
}

/**
Expand All @@ -183,11 +167,7 @@ public function getGroupCacheInFolders(): bool
*/
public function getCacheWithFileExtensions(): bool
{
if (isset($this->config['cache_with_file_extensions'])) {
return $this->config['cache_with_file_extensions'];
}

return false;
return $this->config['cache_with_file_extensions'] ?? false;
}

/**
Expand Down Expand Up @@ -217,11 +197,7 @@ public function getWatermarks(): ?FilesystemOperator
*/
public function getWatermarksPathPrefix(): ?string
{
if (isset($this->config['watermarks_path_prefix'])) {
return $this->config['watermarks_path_prefix'];
}

return null;
return $this->config['watermarks_path_prefix'] ?? null;
}

/**
Expand Down Expand Up @@ -250,15 +226,11 @@ public function getImageManager(): ImageManager
$driver = $this->config['driver'];
}

if ('gd' === $driver) {
$manager = ImageManager::gd();
} elseif ('imagick' === $driver) {
$manager = ImageManager::imagick();
} else {
$manager = ImageManager::withDriver($driver);
}

return $manager;
return match ($driver) {
'gd' => ImageManager::gd(),
'imagick' => ImageManager::imagick(),
default => ImageManager::withDriver($driver),
};
}

/**
Expand Down Expand Up @@ -294,11 +266,7 @@ public function getManipulators(): array
*/
public function getMaxImageSize(): ?int
{
if (isset($this->config['max_image_size'])) {
return $this->config['max_image_size'];
}

return null;
return $this->config['max_image_size'] ?? null;
}

/**
Expand All @@ -308,11 +276,7 @@ public function getMaxImageSize(): ?int
*/
public function getDefaults(): array
{
if (isset($this->config['defaults'])) {
return $this->config['defaults'];
}

return [];
return $this->config['defaults'] ?? [];
}

/**
Expand All @@ -322,11 +286,7 @@ public function getDefaults(): array
*/
public function getPresets(): array
{
if (isset($this->config['presets'])) {
return $this->config['presets'];
}

return [];
return $this->config['presets'] ?? [];
}

/**
Expand All @@ -336,11 +296,7 @@ public function getPresets(): array
*/
public function getBaseUrl(): ?string
{
if (isset($this->config['base_url'])) {
return $this->config['base_url'];
}

return null;
return $this->config['base_url'] ?? null;
}

/**
Expand All @@ -350,11 +306,7 @@ public function getBaseUrl(): ?string
*/
public function getResponseFactory(): ?ResponseFactoryInterface
{
if (isset($this->config['response'])) {
return $this->config['response'];
}

return null;
return $this->config['response'] ?? null;
}

/**
Expand Down

0 comments on commit 7cff858

Please sign in to comment.