Skip to content

Commit

Permalink
Modernize code
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 5, 2025
1 parent 1a74b89 commit d4f2b50
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function get(int|string $query, $default = null): mixed
return $this->items[$query];
}

if (is_string($query) && strpos($query, '.') === false) {
if (is_string($query) && !str_contains($query, '.')) {
return array_key_exists($query, $this->items) ? $this->items[$query] : $default;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Colors/AbstractColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
use ReflectionClass;
use Stringable;

abstract class AbstractColor implements ColorInterface
abstract class AbstractColor implements ColorInterface, Stringable
{
/**
* Color channels
Expand Down
3 changes: 2 additions & 1 deletion src/Colors/AbstractColorChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\ColorChannelInterface;
use Stringable;

abstract class AbstractColorChannel implements ColorChannelInterface
abstract class AbstractColorChannel implements ColorChannelInterface, Stringable
{
protected int $value;

Expand Down
4 changes: 2 additions & 2 deletions src/Colors/Hsl/Colorspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function importRgbColor(ColorInterface $color): ColorInterface
};

// calculate hue
list($r, $g, $b) = $values;
[$r, $g, $b] = $values;
$hue = match (true) {
($delta == 0) => 0,
($max == $r) => 60 * fmod((($g - $b) / $delta), 6),
Expand Down Expand Up @@ -118,7 +118,7 @@ protected function importHsvColor(ColorInterface $color): ColorInterface
}

// normalized values of hsv channels
list($h, $s, $v) = array_map(
[$h, $s, $v] = array_map(
fn(ColorChannelInterface $channel): float => $channel->normalize(),
$color->channels(),
);
Expand Down
4 changes: 2 additions & 2 deletions src/Colors/Hsv/Colorspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function importRgbColor(ColorInterface $color): ColorInterface
$s = 100 * ($chroma / $max);

// calculate hue
list($r, $g, $b) = $values;
[$r, $g, $b] = $values;
$h = match (true) {
($r == $min) => 3 - (($g - $b) / $chroma),
($b == $min) => 1 - (($r - $g) / $chroma),
Expand All @@ -115,7 +115,7 @@ protected function importHslColor(ColorInterface $color): ColorInterface
}

// normalized values of hsl channels
list($h, $s, $l) = array_map(
[$h, $s, $l] = array_map(
fn(ColorChannelInterface $channel): float => $channel->normalize(),
$color->channels()
);
Expand Down
2 changes: 1 addition & 1 deletion src/Colors/Rgb/Colorspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected function importHslColor(ColorInterface $color): ColorInterface
}

// normalized values of hsl channels
list($h, $s, $l) = array_map(
[$h, $s, $l] = array_map(
fn(ColorChannelInterface $channel): float => $channel->normalize(),
$color->channels()
);
Expand Down
13 changes: 3 additions & 10 deletions src/Drivers/AbstractDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,18 @@ protected function parseDataUri(mixed $input): object
$pattern = "/^data:(?P<mediatype>\w+\/[-+.\w]+)?" .
"(?P<parameters>(;[-\w]+=[-\w]+)*)(?P<base64>;base64)?,(?P<data>.*)/";

$result = preg_match($pattern, $input, $matches);
$result = preg_match($pattern, (string) $input, $matches);

return new class ($matches, $result)
{
/**
* @var array<mixed>
*/
private array $matches;
private int|false $result;

/**
* @param array<mixed> $matches
* @param int|false $result
* @return void
*/
public function __construct(array $matches, int|false $result)
public function __construct(private array $matches, private int|false $result)
{
$this->matches = $matches;
$this->result = $result;
//
}

public function isValid(): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Gd/Decoders/Base64ImageDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public function decode(mixed $input): ImageInterface|ColorInterface
throw new DecoderException('Unable to decode input');
}

return parent::decode(base64_decode($input));
return parent::decode(base64_decode((string) $input));
}
}
2 changes: 1 addition & 1 deletion src/Drivers/Gd/Modifiers/DrawBezierModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function apply(ImageInterface $image): ImageInterface
throw new GeometryException('You must specify either 3 or 4 points to create a bezier curve');
}

list($polygon, $polygon_border_segments) = $this->calculateBezierPoints();
[$polygon, $polygon_border_segments] = $this->calculateBezierPoints();

if ($this->drawable->hasBackgroundColor() || $this->drawable->hasBorder()) {
imagealphablending($frame->native(), true);
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Imagick/Decoders/Base64ImageDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public function decode(mixed $input): ImageInterface|ColorInterface
throw new DecoderException('Unable to decode input');
}

return parent::decode(base64_decode($input));
return parent::decode(base64_decode((string) $input));
}
}
3 changes: 2 additions & 1 deletion src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\FileInterface;
use Intervention\Image\Traits\CanBuildFilePointer;
use Stringable;

class File implements FileInterface
class File implements FileInterface, Stringable
{
use CanBuildFilePointer;

Expand Down
3 changes: 2 additions & 1 deletion src/Resolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Intervention\Image;

use Intervention\Image\Interfaces\ResolutionInterface;
use Stringable;

class Resolution implements ResolutionInterface
class Resolution implements ResolutionInterface, Stringable
{
public const PER_INCH = 1;
public const PER_CM = 2;
Expand Down
3 changes: 2 additions & 1 deletion src/Typography/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\PointInterface;
use IteratorAggregate;
use Stringable;
use Traversable;

/**
* @implements IteratorAggregate<string>
*/
class Line implements IteratorAggregate, Countable
class Line implements IteratorAggregate, Countable, Stringable
{
/**
* Segments (usually individual words including punctuation marks) of the line
Expand Down

0 comments on commit d4f2b50

Please sign in to comment.