Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jobs:
run: |
composer install --no-progress
- name: Run PHPStan
run: |
make phpstan
- name: Run tests
run: |
make test
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
phpstan:
vendor/bin/phpstan analyse --level max src tests
vendor/bin/phpstan analyse -c phpstan.neon

test: phpstan
vendor/bin/phpunit --verbose
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"php": "^8.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5.8|^9.3.3",
"phpstan/phpstan": "^0.12"
"phpunit/phpunit": "^9.6",
"phpstan/phpstan": "^1.8"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: max
paths:
- src
- tests
4 changes: 1 addition & 3 deletions src/Options/AbstractOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ abstract public function data(): array;
*/
public function value(): string
{
$data = $this->data();

array_unshift($data, $this->name());
$data = [$this->name(), ...$this->data()];

// Remove empty options from end.
return rtrim(implode(':', $data), ':');
Expand Down
9 changes: 3 additions & 6 deletions src/Options/AutoRotate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

final class AutoRotate extends AbstractOption
{
private bool $rotate;

public function __construct(bool $rotate = true)
{
$this->rotate = $rotate;
}
public function __construct(
private bool $rotate = true,
) {}

/**
* @inheritDoc
Expand Down
8 changes: 3 additions & 5 deletions src/Options/Blur.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

final class Blur extends AbstractOption
{
private float $sigma;

public function __construct(float $sigma)
public function __construct(
private float $sigma,
)
{
if ($sigma < 0) {
throw new InvalidArgumentException(sprintf('Invalid blur: %s', $sigma));
}

$this->sigma = $sigma;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/Options/CacheBuster.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@

final class CacheBuster extends AbstractOption
{
private string $value;

public function __construct(string $value)
{
public function __construct(
private string $value,
) {
if (empty($value)) {
throw new InvalidArgumentException('Cache buster cannot be empty');
}

$this->value = $value;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Options/Crop.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class Crop extends AbstractOption
{
private Width $width;
private Height $height;
private ?Gravity $gravity = null;
private ?Gravity $gravity;

public function __construct(int $width, int $height, Gravity|string|null $gravity = null)
{
Expand Down
9 changes: 3 additions & 6 deletions src/Options/Dpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@

final class Dpr extends AbstractOption
{
private int $dpr;

public function __construct(int $dpr)
{
public function __construct(
private int $dpr,
) {
if ($dpr <= 0) {
throw new InvalidArgumentException(sprintf('Invalid dpr: %s', $dpr));
}

$this->dpr = $dpr;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/Options/EnforceThumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

final class EnforceThumbnail extends AbstractOption
{
private ?string $format;

public function __construct(?string $format = null)
{
$this->format = $format;
}
public function __construct(
private ?string $format = null,
) {}

/**
* @inheritDoc
Expand Down
9 changes: 3 additions & 6 deletions src/Options/Enlarge.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

final class Enlarge extends AbstractOption
{
private bool $enlarge;

public function __construct(bool $enlarge = true)
{
$this->enlarge = $enlarge;
}
public function __construct(
private bool $enlarge = true,
) {}

/**
* @inheritDoc
Expand Down
9 changes: 3 additions & 6 deletions src/Options/Expires.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

final class Expires extends AbstractOption
{
private int $timestamp;

public function __construct(int $timestamp)
{
$this->timestamp = $timestamp;
}
public function __construct(
private int $timestamp,
) {}

/**
* @inheritDoc
Expand Down
9 changes: 5 additions & 4 deletions src/Options/Extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

final class Extend extends AbstractOption
{
private bool $extend;
private ?Gravity $gravity = null;
private ?Gravity $gravity;

public function __construct(bool $extend = true, Gravity|string|null $gravity = null)
public function __construct(
private bool $extend = true,
Gravity|string|null $gravity = null
)
{
$this->extend = $extend;
$this->gravity = is_string($gravity) ? Gravity::fromString($gravity) : $gravity;
}

Expand Down
9 changes: 3 additions & 6 deletions src/Options/Filename.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@

final class Filename extends AbstractOption
{
private string $name;

public function __construct(string $name)
{
public function __construct(
private string $name,
) {
if (empty($name)) {
throw new InvalidArgumentException('Filename cannot be empty');
}

$this->name = $name;
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/Options/Flip.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Onliner\ImgProxy\Options;

final class Flip extends AbstractOption
{
public function __construct(
private bool $horizontal = false,
private bool $vertical = false,
) {}

public function name(): string
{
return 'fl';
}

public function data(): array
{
return [
(int) $this->horizontal,
(int) $this->vertical,
];
}
}
9 changes: 3 additions & 6 deletions src/Options/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@

final class Format extends AbstractOption
{
private string $extension;

public function __construct(string $extension)
{
public function __construct(
private string $extension,
) {
if (empty($extension)) {
throw new InvalidArgumentException('Format cannot be empty');
}

$this->extension = $extension;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/Options/FormatQuality.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
final class FormatQuality extends AbstractOption
{
/**
* @var array[]
* @var list<array{string, int}>
*/
private array $options = [];

Expand All @@ -18,9 +18,8 @@ final class FormatQuality extends AbstractOption
*/
public function __construct(array $options)
{
foreach ($options as $format => $quality) {
$data = (new Quality($quality))->data();
$this->options[] = [$format, ...$data];
foreach ($options as $format => $value) {
$this->options[] = [$format, (new Quality($value))->quality()];
}

if (empty($this->options)) {
Expand Down
11 changes: 5 additions & 6 deletions src/Options/Gravity.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
final class Gravity extends AbstractOption
{
private GravityType $type;
private ?float $x;
private ?float $y;

/**
* @param string $type
* @param float|null $x
* @param float|null $y
*/
public function __construct(string $type, ?float $x = null, ?float $y = null)
public function __construct(
string $type,
private ?float $x = null,
private ?float $y = null,
)
{
$this->type = new GravityType($type);

Expand All @@ -29,9 +31,6 @@ public function __construct(string $type, ?float $x = null, ?float $y = null)
if ($y < 0) {
throw new InvalidArgumentException(sprintf('Invalid gravity Y: %s', $y));
}

$this->x = $x;
$this->y = $y;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/Options/Height.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@

final class Height extends AbstractOption
{
private int $height;

public function __construct(int $height)
{
public function __construct(
private int $height,
) {
if ($height < 0) {
throw new InvalidArgumentException(sprintf('Invalid height: %s', $height));
}

$this->height = $height;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/Options/KeepCopyright.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

final class KeepCopyright extends AbstractOption
{
private bool $keep;

public function __construct(bool $keep = true)
{
$this->keep = $keep;
}
public function __construct(
private bool $keep = true,
) {}

/**
* @inheritDoc
Expand Down
9 changes: 3 additions & 6 deletions src/Options/MaxBytes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@

final class MaxBytes extends AbstractOption
{
private int $bytes;

public function __construct(int $bytes)
{
public function __construct(
private int $bytes,
) {
if ($bytes < 0) {
throw new InvalidArgumentException(sprintf('Invalid max bytes: %s', $bytes));
}

$this->bytes = $bytes;
}

/**
Expand Down
15 changes: 4 additions & 11 deletions src/Options/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@

final class Option extends AbstractOption
{
private string $name;
/**
* @var array<string, mixed>
*/
private array $data;

/**
* @param string $name
* @param array<string, mixed> $data
*/
public function __construct(string $name, array $data = [])
{
$this->name = $name;
$this->data = $data;
}
public function __construct(
private string $name,
private array $data = [],
) {}

/**
* @inheritDoc
Expand Down
Loading
Loading