Skip to content

Commit

Permalink
Added __set_state for options
Browse files Browse the repository at this point in the history
  • Loading branch information
akarashchuk committed Aug 2, 2024
1 parent ac14b0a commit c9a77c9
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
php: ['8.0', '8.1', '8.2']
php: ['8.0', '8.1', '8.2', '8.3']
name: PHP ${{ matrix.php }} Test on ${{ matrix.os }}
steps:
- name: Checkout
Expand Down
19 changes: 18 additions & 1 deletion src/Options/AbstractOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@

namespace Onliner\ImgProxy\Options;

abstract class AbstractOption
use ReflectionClass;
use Stringable;

abstract class AbstractOption implements Stringable
{
public static function __set_state(array $data): static

Check failure on line 12 in src/Options/AbstractOption.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 Test on ubuntu-latest

Method Onliner\ImgProxy\Options\AbstractOption::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 12 in src/Options/AbstractOption.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test on ubuntu-latest

Method Onliner\ImgProxy\Options\AbstractOption::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 12 in src/Options/AbstractOption.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Method Onliner\ImgProxy\Options\AbstractOption::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 12 in src/Options/AbstractOption.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Method Onliner\ImgProxy\Options\AbstractOption::__set_state() has parameter $data with no value type specified in iterable type array.
{
$class = new ReflectionClass(static::class);
$self = $class->newInstanceWithoutConstructor();

(function () use ($data) {
foreach ($data as $key => $value) {
$this->{$key} = $value;

Check failure on line 19 in src/Options/AbstractOption.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 Test on ubuntu-latest

Undefined variable: $this

Check failure on line 19 in src/Options/AbstractOption.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test on ubuntu-latest

Undefined variable: $this

Check failure on line 19 in src/Options/AbstractOption.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Undefined variable: $this

Check failure on line 19 in src/Options/AbstractOption.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Undefined variable: $this
}
})->bindTo($self, static::class)();

return $self;
}

/**
* @return string
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Support/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public static function fromHex(string $color): self
return new self($color);
}

public static function __set_state(array $data): static

Check failure on line 36 in src/Support/Color.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\Color::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 36 in src/Support/Color.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\Color::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 36 in src/Support/Color.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\Color::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 36 in src/Support/Color.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\Color::__set_state() has parameter $data with no value type specified in iterable type array.
{
return new static(...$data);

Check failure on line 38 in src/Support/Color.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 Test on ubuntu-latest

Unsafe usage of new static().

Check failure on line 38 in src/Support/Color.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test on ubuntu-latest

Unsafe usage of new static().

Check failure on line 38 in src/Support/Color.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Unsafe usage of new static().

Check failure on line 38 in src/Support/Color.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Unsafe usage of new static().
}

/**
* @return string
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Support/GravityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function __construct(string $type)
$this->type = $type;
}

public static function __set_state(array $data): static

Check failure on line 53 in src/Support/GravityType.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\GravityType::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 53 in src/Support/GravityType.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\GravityType::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 53 in src/Support/GravityType.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\GravityType::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 53 in src/Support/GravityType.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\GravityType::__set_state() has parameter $data with no value type specified in iterable type array.
{
return new static(...$data);

Check failure on line 55 in src/Support/GravityType.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 Test on ubuntu-latest

Unsafe usage of new static().

Check failure on line 55 in src/Support/GravityType.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test on ubuntu-latest

Unsafe usage of new static().

Check failure on line 55 in src/Support/GravityType.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Unsafe usage of new static().

Check failure on line 55 in src/Support/GravityType.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Unsafe usage of new static().
}

public function value(): string
{
return $this->type;
Expand Down
5 changes: 5 additions & 0 deletions src/Support/ImageFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public function __construct(string $extension)
}
}

public static function __set_state(array $data): static

Check failure on line 30 in src/Support/ImageFormat.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\ImageFormat::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 30 in src/Support/ImageFormat.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\ImageFormat::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 30 in src/Support/ImageFormat.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\ImageFormat::__set_state() has parameter $data with no value type specified in iterable type array.

Check failure on line 30 in src/Support/ImageFormat.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Method Onliner\ImgProxy\Support\ImageFormat::__set_state() has parameter $data with no value type specified in iterable type array.
{
return new static(...$data);

Check failure on line 32 in src/Support/ImageFormat.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 Test on ubuntu-latest

Unsafe usage of new static().

Check failure on line 32 in src/Support/ImageFormat.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test on ubuntu-latest

Unsafe usage of new static().

Check failure on line 32 in src/Support/ImageFormat.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Unsafe usage of new static().

Check failure on line 32 in src/Support/ImageFormat.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Unsafe usage of new static().
}

/**
* @param string $value
*
Expand Down
2 changes: 2 additions & 0 deletions tests/Options/BackgroundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class BackgroundTest extends TestCase
public function testCreate(string $color, string $expected): void
{
$opt = new Background($color);

$this->assertSame($expected, (string) $opt);
$this->assertEquals($opt, eval('return '.var_export($opt, true).';'));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Options/ExtendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class ExtendTest extends TestCase
public function testCreate(bool $extend, ?string $gravity, string $expected): void
{
$opt = new Extend($extend, $gravity);

$this->assertSame($expected, (string) $opt);
$this->assertEquals($opt, eval('return '.var_export($opt, true).';'));
}

public function testCreateDefault(): void
Expand Down
2 changes: 2 additions & 0 deletions tests/Options/HeightTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class HeightTest extends TestCase
public function testCreate(int $height, string $expected): void
{
$opt = new Height($height);

$this->assertSame($expected, (string) $opt);
$this->assertEquals($opt, eval('return '.var_export($opt, true).';'));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Options/WidthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class WidthTest extends TestCase
public function testCreate(int $width, string $expected): void
{
$opt = new Width($width);

$this->assertSame($expected, (string) $opt);
$this->assertEquals($opt, eval('return '.var_export($opt, true).';'));
}

/**
Expand Down

0 comments on commit c9a77c9

Please sign in to comment.