diff --git a/src/Collection.php b/src/Collection.php index b2b9e18a2..ad49637f9 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -23,6 +23,7 @@ class Collection implements CollectionInterface, IteratorAggregate, Countable */ public function __construct(protected array $items = []) { + // } /** @@ -181,11 +182,13 @@ public function get(int|string $query, $default = null): mixed */ public function map(callable $callback): self { - $items = array_map(function ($item) use ($callback) { - return $callback($item); - }, $this->items); - return new self($items); + return new self( + array_map( + fn($item) => $callback($item), + $this->items, + ) + ); } /** @@ -196,11 +199,12 @@ public function map(callable $callback): self */ public function filter(callable $callback): self { - $items = array_filter($this->items, function ($item) use ($callback) { - return $callback($item); - }); - - return new self($items); + return new self( + array_filter( + $this->items, + fn($item) => $callback($item), + ) + ); } /** diff --git a/src/Colors/AbstractColor.php b/src/Colors/AbstractColor.php index ef9d7be72..bcb7e2694 100644 --- a/src/Colors/AbstractColor.php +++ b/src/Colors/AbstractColor.php @@ -36,9 +36,10 @@ public function channels(): array */ public function channel(string $classname): ColorChannelInterface { - $channels = array_filter($this->channels(), function (ColorChannelInterface $channel) use ($classname) { - return $channel::class == $classname; - }); + $channels = array_filter( + $this->channels(), + fn(ColorChannelInterface $channel) => $channel::class == $classname, + ); if (count($channels) == 0) { throw new ColorException('Color channel ' . $classname . ' could not be found.'); @@ -54,9 +55,10 @@ public function channel(string $classname): ColorChannelInterface */ public function normalize(): array { - return array_map(function (ColorChannelInterface $channel) { - return $channel->normalize(); - }, $this->channels()); + return array_map( + fn(ColorChannelInterface $channel) => $channel->normalize(), + $this->channels(), + ); } /** @@ -66,9 +68,10 @@ public function normalize(): array */ public function toArray(): array { - return array_map(function (ColorChannelInterface $channel) { - return $channel->value(); - }, $this->channels()); + return array_map( + fn(ColorChannelInterface $channel) => $channel->value(), + $this->channels() + ); } /** diff --git a/src/Colors/Cmyk/Colorspace.php b/src/Colors/Cmyk/Colorspace.php index 66b9b496e..fc5445bb6 100644 --- a/src/Colors/Cmyk/Colorspace.php +++ b/src/Colors/Cmyk/Colorspace.php @@ -34,11 +34,11 @@ class Colorspace implements ColorspaceInterface */ public function colorFromNormalized(array $normalized): ColorInterface { - $values = array_map(function ($classname, $value_normalized) { - return (new $classname(normalized: $value_normalized))->value(); - }, self::$channels, $normalized); - - return new Color(...$values); + return new Color(...array_map( + fn($classname, $value_normalized) => (new $classname(normalized: $value_normalized))->value(), + self::$channels, + $normalized, + )); } /** diff --git a/src/Colors/Hsl/Colorspace.php b/src/Colors/Hsl/Colorspace.php index 2192bc11d..84914736d 100644 --- a/src/Colors/Hsl/Colorspace.php +++ b/src/Colors/Hsl/Colorspace.php @@ -9,6 +9,7 @@ use Intervention\Image\Colors\Hsv\Color as HsvColor; use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace; use Intervention\Image\Exceptions\ColorException; +use Intervention\Image\Interfaces\ColorChannelInterface; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; @@ -32,11 +33,11 @@ class Colorspace implements ColorspaceInterface */ public function colorFromNormalized(array $normalized): ColorInterface { - $values = array_map(function ($classname, $value_normalized) { - return (new $classname(normalized: $value_normalized))->value(); - }, self::$channels, $normalized); - - return new Color(...$values); + return new Color(...array_map( + fn($classname, $value_normalized) => (new $classname(normalized: $value_normalized))->value(), + self::$channels, + $normalized + )); } /** @@ -66,9 +67,10 @@ protected function importRgbColor(ColorInterface $color): ColorInterface } // normalized values of rgb channels - $values = array_map(function ($channel) { - return $channel->normalize(); - }, $color->channels()); + $values = array_map( + fn(ColorChannelInterface $channel) => $channel->normalize(), + $color->channels(), + ); // take only RGB $values = array_slice($values, 0, 3); @@ -116,9 +118,10 @@ protected function importHsvColor(ColorInterface $color): ColorInterface } // normalized values of hsv channels - list($h, $s, $v) = array_map(function ($channel) { - return $channel->normalize(); - }, $color->channels()); + list($h, $s, $v) = array_map( + fn(ColorChannelInterface $channel) => $channel->normalize(), + $color->channels(), + ); // calculate Luminance $luminance = (2 - $s) * $v / 2; diff --git a/src/Colors/Hsv/Colorspace.php b/src/Colors/Hsv/Colorspace.php index d02110523..88c8f2215 100644 --- a/src/Colors/Hsv/Colorspace.php +++ b/src/Colors/Hsv/Colorspace.php @@ -9,6 +9,7 @@ use Intervention\Image\Colors\Hsl\Color as HslColor; use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace; use Intervention\Image\Exceptions\ColorException; +use Intervention\Image\Interfaces\ColorChannelInterface; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; @@ -32,11 +33,11 @@ class Colorspace implements ColorspaceInterface */ public function colorFromNormalized(array $normalized): ColorInterface { - $values = array_map(function ($classname, $value_normalized) { - return (new $classname(normalized: $value_normalized))->value(); - }, self::$channels, $normalized); - - return new Color(...$values); + return new Color(...array_map( + fn($classname, $value_normalized) => (new $classname(normalized: $value_normalized))->value(), + self::$channels, + $normalized + )); } /** @@ -66,9 +67,7 @@ protected function importRgbColor(ColorInterface $color): ColorInterface } // normalized values of rgb channels - $values = array_map(function ($channel) { - return $channel->normalize(); - }, $color->channels()); + $values = array_map(fn(ColorChannelInterface $channel) => $channel->normalize(), $color->channels()); // take only RGB $values = array_slice($values, 0, 3); @@ -116,9 +115,7 @@ protected function importHslColor(ColorInterface $color): ColorInterface } // normalized values of hsl channels - list($h, $s, $l) = array_map(function ($channel) { - return $channel->normalize(); - }, $color->channels()); + list($h, $s, $l) = array_map(fn(ColorChannelInterface $channel) => $channel->normalize(), $color->channels()); $v = $l + $s * min($l, 1 - $l); $s = ($v == 0) ? 0 : 2 * (1 - $l / $v); diff --git a/src/Colors/Rgb/Colorspace.php b/src/Colors/Rgb/Colorspace.php index 35deb7564..bf1ff2d9f 100644 --- a/src/Colors/Rgb/Colorspace.php +++ b/src/Colors/Rgb/Colorspace.php @@ -8,6 +8,7 @@ use Intervention\Image\Colors\Hsl\Color as HslColor; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Exceptions\ColorException; +use Intervention\Image\Interfaces\ColorChannelInterface; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; @@ -32,11 +33,11 @@ class Colorspace implements ColorspaceInterface */ public function colorFromNormalized(array $normalized): ColorInterface { - $values = array_map(function ($classname, $value_normalized) { - return (new $classname(normalized: $value_normalized))->value(); - }, self::$channels, $normalized); - - return new Color(...$values); + return new Color(...array_map( + fn($classname, $value_normalized) => (new $classname(normalized: $value_normalized))->value(), + self::$channels, + $normalized, + )); } /** @@ -98,9 +99,7 @@ protected function importHsvColor(ColorInterface $color): ColorInterface }; // add to each value - $values = array_map(function ($value) use ($color, $chroma) { - return $value + $color->value()->normalize() - $chroma; - }, $values); + $values = array_map(fn($value) => $value + $color->value()->normalize() - $chroma, $values); array_push($values, 1); // append alpha channel value @@ -119,9 +118,10 @@ protected function importHslColor(ColorInterface $color): ColorInterface } // normalized values of hsl channels - list($h, $s, $l) = array_map(function ($channel) { - return $channel->normalize(); - }, $color->channels()); + list($h, $s, $l) = array_map( + fn(ColorChannelInterface $channel) => $channel->normalize(), + $color->channels() + ); $c = (1 - abs(2 * $l - 1)) * $s; $x = $c * (1 - abs(fmod($h * 6, 2) - 1)); @@ -136,9 +136,7 @@ protected function importHslColor(ColorInterface $color): ColorInterface default => [$c, 0, $x], }; - $values = array_map(function ($value) use ($m) { - return $value + $m; - }, $values); + $values = array_map(fn($value) => $value + $m, $values); array_push($values, 1); // append alpha channel value diff --git a/src/Format.php b/src/Format.php index b3040d1d5..87a646842 100644 --- a/src/Format.php +++ b/src/Format.php @@ -86,9 +86,10 @@ public static function tryCreate(string|self|MediaType|FileExtension $identifier */ public function mediaTypes(): array { - return array_filter(MediaType::cases(), function ($mediaType) { - return $mediaType->format() === $this; - }); + return array_filter( + MediaType::cases(), + fn(MediaType $mediaType) => $mediaType->format() === $this + ); } /** @@ -110,9 +111,10 @@ public function mediaType(): MediaType */ public function fileExtensions(): array { - return array_filter(FileExtension::cases(), function ($fileExtension) { - return $fileExtension->format() === $this; - }); + return array_filter( + FileExtension::cases(), + fn(FileExtension $fileExtension) => $fileExtension->format() === $this + ); } /** @@ -153,7 +155,7 @@ public function encoder(mixed ...$options): EncoderInterface $reflectionClass = new ReflectionClass($classname); if ($constructor = $reflectionClass->getConstructor()) { $parameters = array_map( - fn ($parameter) => $parameter->getName(), + fn($parameter) => $parameter->getName(), $constructor->getParameters(), ); } @@ -161,7 +163,7 @@ public function encoder(mixed ...$options): EncoderInterface // filter out unavailable options of target encoder $options = array_filter( $options, - fn ($key) => in_array($key, $parameters), + fn($key) => in_array($key, $parameters), ARRAY_FILTER_USE_KEY, );