repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/Attributes/Models/Simple.php
tests/Console/ModelsCommand/Attributes/Models/Simple.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Attributes\Models; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; class Simple extends Model { // With a backed property protected function name(): Attribute { return new Attribute( function (?string $name): ?string { return $name; }, function (?string $name): ?string { return $name; } ); } // Without backed properties protected function typeHintedGetAndSet(): Attribute { return new Attribute( function (): ?string { return $this->name; }, function (?string $name) { $this->name = $name; } ); } protected function divergingTypeHintedGetAndSet(): Attribute { return new Attribute( function (): int { return strlen($this->name); }, function (?string $name) { $this->name = $name; } ); } protected function typeHintedGet(): Attribute { return Attribute::get(function (): ?string { return $this->name; }); } protected function typeHintedSet(): Attribute { return Attribute::set(function (?string $name) { $this->name = $name; }); } protected function nonTypeHintedGetAndSet(): Attribute { return new Attribute( function () { return $this->name; }, function ($name) { $this->name = $name; } ); } protected function nonTypeHintedGet(): Attribute { return Attribute::get(function () { return $this->name; }); } protected function nonTypeHintedSet(): Attribute { return Attribute::set(function ($name) { $this->name = $name; }); } protected function parameterlessSet(): Attribute { return Attribute::set(function () { $this->name = null; }); } /** * ide-helper does not recognize this method being an Attribute * because the method has no actual return type; * phpdoc is ignored here deliberately due to performance reasons and also * isn't supported by Laravel itself. * * @return Attribute */ protected function notAnAttribute() { return new Attribute( function (?string $value): ?string { return $value; }, function (?string $value): ?string { return $value; } ); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/CustomDate/Test.php
tests/Console/ModelsCommand/CustomDate/Test.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; use Carbon\CarbonImmutable; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Date; class Test extends AbstractModelsCommand { protected function setUp(): void { parent::setUp(); Date::use(CarbonImmutable::class); } protected function tearDown(): void { Date::use(Carbon::class); parent::tearDown(); } public function test(): void { $command = $this->app->make(ModelsCommand::class); $tester = $this->runCommand($command, [ '--write' => true, ]); $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/CustomDate/__snapshots__/Test__test__1.php
tests/Console/ModelsCommand/CustomDate/__snapshots__/Test__test__1.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models; use Illuminate\Database\Eloquent\Model; /** * @property \Carbon\CarbonImmutable|null $created_at * @property \Carbon\CarbonImmutable|null $updated_at * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomDate newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomDate newQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomDate query() * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomDate whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomDate whereUpdatedAt($value) * @mixin \Eloquent */ class CustomDate extends Model { }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/CustomDate/Models/CustomDate.php
tests/Console/ModelsCommand/CustomDate/Models/CustomDate.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models; use Illuminate\Database\Eloquent\Model; class CustomDate extends Model { }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php
tests/Console/ModelsCommand/LaravelCustomCasts/Test.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; class Test extends AbstractModelsCommand { public function test(): void { $command = $this->app->make(ModelsCommand::class); $tester = $this->runCommand($command, [ '--write' => true, ]); $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithPrimitiveReturn.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithPrimitiveReturn.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CustomCasterWithPrimitiveReturn implements CastsAttributes { /** * @inheritDoc * @return string */ public function get($model, string $key, $value, array $attributes): array { return new CastedProperty(); } /** * @inheritDoc */ public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithPrimitiveDocblockReturn.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithPrimitiveDocblockReturn.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CustomCasterWithPrimitiveDocblockReturn implements CastsAttributes { /** * @inheritDoc * @return array|null */ public function get($model, string $key, $value, array $attributes) { return new CastedProperty(); } /** * @inheritDoc */ public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/ExtendedSelfCastingCasterWithThisDocblockReturn.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/ExtendedSelfCastingCasterWithThisDocblockReturn.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; class ExtendedSelfCastingCasterWithThisDocblockReturn extends SelfCastingCasterWithStaticDocblockReturn { }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CastableReturnsCustomCaster.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CastableReturnsCustomCaster.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\Castable; class CastableReturnsCustomCaster implements Castable { public static function castUsing(array $arguments) { return CustomCasterWithDocblockReturn::class; } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/SelfCastingCasterWithThisDocblockReturn.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/SelfCastingCasterWithThisDocblockReturn.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class SelfCastingCasterWithThisDocblockReturn implements CastsAttributes { /** * @return $this */ public function get($model, string $key, $value, array $attributes) { return new static(); } /** * @inheritDoc */ public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CastableWithoutReturnType.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CastableWithoutReturnType.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\Castable; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CastableWithoutReturnType implements Castable { public static function castUsing(array $arguments) { return new class () implements CastsAttributes { public function get($model, string $key, $value, array $attributes) { return new CastedProperty(); } public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }; } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithDocblockReturnFqn.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithDocblockReturnFqn.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CustomCasterWithDocblockReturnFqn implements CastsAttributes { /** * @inheritDoc * @return CastedProperty */ public function get($model, string $key, $value, array $attributes) { return new CastedProperty(); } /** * @inheritDoc */ public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithoutReturnType.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithoutReturnType.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CustomCasterWithoutReturnType implements CastsAttributes { public function get($model, string $key, $value, array $attributes) { return new CastedProperty(); } /** * @inheritDoc */ public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/ExtendedSelfCastingCasterWithStaticDocblockReturn.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/ExtendedSelfCastingCasterWithStaticDocblockReturn.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; class ExtendedSelfCastingCasterWithStaticDocblockReturn extends SelfCastingCasterWithStaticDocblockReturn { }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithNullablePrimitiveReturn.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithNullablePrimitiveReturn.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CustomCasterWithNullablePrimitiveReturn implements CastsAttributes { /** * @inheritDoc * @return string */ public function get($model, string $key, $value, array $attributes): ?array { return new CastedProperty(); } /** * @inheritDoc */ public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/InboundAttributeCaster.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/InboundAttributeCaster.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes; class InboundAttributeCaster implements CastsInboundAttributes { public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CastedProperty.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CastedProperty.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; class CastedProperty { }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithDocblockReturn.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithDocblockReturn.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CustomCasterWithDocblockReturn implements CastsAttributes { /** * @inheritDoc * @return CastedProperty */ public function get($model, string $key, $value, array $attributes) { return new CastedProperty(); } /** * @inheritDoc */ public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/SelfCastingCasterWithStaticDocblockReturn.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/SelfCastingCasterWithStaticDocblockReturn.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class SelfCastingCasterWithStaticDocblockReturn implements CastsAttributes { /** * @return static */ public function get($model, string $key, $value, array $attributes) { return new static(); } /** * @inheritDoc */ public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithStaticReturnType.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithStaticReturnType.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Database\Eloquent\Model; class CustomCasterWithStaticReturnType implements CastsAttributes { public function get(Model $model, string $key, mixed $value, array $attributes): static { // TODO: Implement get() method. } public function set(Model $model, string $key, mixed $value, array $attributes): array { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CastableReturnsAnonymousCaster.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CastableReturnsAnonymousCaster.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\Castable; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CastableReturnsAnonymousCaster implements Castable { public static function castUsing(array $arguments) { return new class () implements CastsAttributes { /** * @inheritDoc * @return CastedProperty */ public function get($model, string $key, $value, array $attributes) { return new CastedProperty(); } /** * @inheritDoc */ public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }; } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithReturnType.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithReturnType.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CustomCasterWithReturnType implements CastsAttributes { /** * @return array */ public function get($model, string $key, $value, array $attributes): CastedProperty { return new CastedProperty(); } /** * @inheritDoc */ public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithParam.php
tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithParam.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CustomCasterWithParam implements CastsAttributes { public function __construct(string $param) { } public function get($model, string $key, $value, array $attributes): CastedProperty { return new CastedProperty(); } public function set($model, string $key, $value, array $attributes) { // TODO: Implement set() method. } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php
tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastableReturnsAnonymousCaster; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastableReturnsCustomCaster; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastableWithoutReturnType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithDocblockReturnFqn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithNullablePrimitiveReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithoutReturnType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithParam; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithPrimitiveDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithPrimitiveReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithReturnType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithStaticReturnType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\ExtendedSelfCastingCasterWithStaticDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\ExtendedSelfCastingCasterWithThisDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\InboundAttributeCaster; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\SelfCastingCasterWithStaticDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\SelfCastingCasterWithThisDocblockReturn; use Illuminate\Database\Eloquent\Model; /** * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_return_type * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_return_docblock * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_return_docblock_fqn * @property array $casted_property_with_return_primitive * @property array $casted_property_with_return_primitive_docblock * @property array $casted_property_with_return_nullable_primitive * @property array|null $casted_property_with_return_nullable_primitive_and_nullable_column * @property $casted_property_without_return * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_param * @property SelfCastingCasterWithStaticDocblockReturn $casted_property_with_static_return_docblock * @property SelfCastingCasterWithThisDocblockReturn $casted_property_with_this_return_docblock * @property ExtendedSelfCastingCasterWithStaticDocblockReturn $extended_casted_property_with_static_return_docblock * @property ExtendedSelfCastingCasterWithThisDocblockReturn $extended_casted_property_with_this_return_docblock * @property SelfCastingCasterWithStaticDocblockReturn $casted_property_with_static_return_docblock_and_param * @property CustomCasterWithStaticReturnType $casted_property_with_static_return_type * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_castable * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_anonymous_cast * @property CastableWithoutReturnType $casted_property_without_return_type * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $cast_without_property * @property mixed $cast_inbound_attribute * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast newQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast query() * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithParam($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithReturnDocblock($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithReturnDocblockFqn($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithReturnNullablePrimitive($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithReturnNullablePrimitiveAndNullableColumn($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithReturnPrimitive($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithReturnPrimitiveDocblock($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithReturnType($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithStaticReturnDocblock($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithStaticReturnDocblockAndParam($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithThisReturnDocblock($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereCastedPropertyWithoutReturn($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereExtendedCastedPropertyWithStaticReturnDocblock($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomCast whereExtendedCastedPropertyWithThisReturnDocblock($value) * @mixin \Eloquent */ class CustomCast extends Model { protected $casts = [ 'casted_property_with_return_type' => CustomCasterWithReturnType::class, 'casted_property_with_static_return_type' => CustomCasterWithStaticReturnType::class, 'casted_property_with_return_docblock' => CustomCasterWithDocblockReturn::class, 'casted_property_with_return_docblock_fqn' => CustomCasterWithDocblockReturnFqn::class, 'casted_property_with_return_primitive' => CustomCasterWithPrimitiveReturn::class, 'casted_property_with_return_primitive_docblock' => CustomCasterWithPrimitiveDocblockReturn::class, 'casted_property_with_return_nullable_primitive' => CustomCasterWithNullablePrimitiveReturn::class, 'casted_property_with_return_nullable_primitive_and_nullable_column' => CustomCasterWithNullablePrimitiveReturn::class, 'casted_property_without_return' => CustomCasterWithoutReturnType::class, 'casted_property_with_param' => CustomCasterWithParam::class . ':param', 'casted_property_with_static_return_docblock' => SelfCastingCasterWithStaticDocblockReturn::class, 'casted_property_with_this_return_docblock' => SelfCastingCasterWithThisDocblockReturn::class, 'casted_property_with_castable' => CastableReturnsCustomCaster::class, 'casted_property_with_anonymous_cast' => CastableReturnsAnonymousCaster::class, 'casted_property_without_return_type' => CastableWithoutReturnType::class, 'extended_casted_property_with_static_return_docblock' => ExtendedSelfCastingCasterWithStaticDocblockReturn::class, 'extended_casted_property_with_this_return_docblock' => ExtendedSelfCastingCasterWithThisDocblockReturn::class, 'casted_property_with_static_return_docblock_and_param' => SelfCastingCasterWithStaticDocblockReturn::class . ':param', 'cast_without_property' => CustomCasterWithReturnType::class, 'cast_inbound_attribute' => InboundAttributeCaster::class, ]; }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/LaravelCustomCasts/Models/CustomCast.php
tests/Console/ModelsCommand/LaravelCustomCasts/Models/CustomCast.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastableReturnsAnonymousCaster; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastableReturnsCustomCaster; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastableWithoutReturnType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithDocblockReturnFqn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithNullablePrimitiveReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithoutReturnType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithParam; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithPrimitiveDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithPrimitiveReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithReturnType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithStaticReturnType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\ExtendedSelfCastingCasterWithStaticDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\ExtendedSelfCastingCasterWithThisDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\InboundAttributeCaster; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\SelfCastingCasterWithStaticDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\SelfCastingCasterWithThisDocblockReturn; use Illuminate\Database\Eloquent\Model; class CustomCast extends Model { protected $casts = [ 'casted_property_with_return_type' => CustomCasterWithReturnType::class, 'casted_property_with_static_return_type' => CustomCasterWithStaticReturnType::class, 'casted_property_with_return_docblock' => CustomCasterWithDocblockReturn::class, 'casted_property_with_return_docblock_fqn' => CustomCasterWithDocblockReturnFqn::class, 'casted_property_with_return_primitive' => CustomCasterWithPrimitiveReturn::class, 'casted_property_with_return_primitive_docblock' => CustomCasterWithPrimitiveDocblockReturn::class, 'casted_property_with_return_nullable_primitive' => CustomCasterWithNullablePrimitiveReturn::class, 'casted_property_with_return_nullable_primitive_and_nullable_column' => CustomCasterWithNullablePrimitiveReturn::class, 'casted_property_without_return' => CustomCasterWithoutReturnType::class, 'casted_property_with_param' => CustomCasterWithParam::class . ':param', 'casted_property_with_static_return_docblock' => SelfCastingCasterWithStaticDocblockReturn::class, 'casted_property_with_this_return_docblock' => SelfCastingCasterWithThisDocblockReturn::class, 'casted_property_with_castable' => CastableReturnsCustomCaster::class, 'casted_property_with_anonymous_cast' => CastableReturnsAnonymousCaster::class, 'casted_property_without_return_type' => CastableWithoutReturnType::class, 'extended_casted_property_with_static_return_docblock' => ExtendedSelfCastingCasterWithStaticDocblockReturn::class, 'extended_casted_property_with_this_return_docblock' => ExtendedSelfCastingCasterWithThisDocblockReturn::class, 'casted_property_with_static_return_docblock_and_param' => SelfCastingCasterWithStaticDocblockReturn::class . ':param', 'cast_without_property' => CustomCasterWithReturnType::class, 'cast_inbound_attribute' => InboundAttributeCaster::class, ]; }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/AdvancedCasts/Test.php
tests/Console/ModelsCommand/AdvancedCasts/Test.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; class Test extends AbstractModelsCommand { public function test(): void { $command = $this->app->make(ModelsCommand::class); $tester = $this->runCommand($command, [ '--write' => true, ]); $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/AdvancedCasts/__snapshots__/Test__test__1.php
tests/Console/ModelsCommand/AdvancedCasts/__snapshots__/Test__test__1.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Models; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Collections\AdvancedCastCollection; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Collections\AdvancedCastMap; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Enums\AdvancedCastEnum; use Illuminate\Database\Eloquent\Casts\AsArrayObject; use Illuminate\Database\Eloquent\Casts\AsCollection; use Illuminate\Database\Eloquent\Casts\AsEnumCollection; use Illuminate\Database\Eloquent\Model; /** * @property \Illuminate\Support\Carbon $cast_to_date_serialization * @property \Illuminate\Support\Carbon $cast_to_datetime_serialization * @property \Illuminate\Support\Carbon $cast_to_custom_datetime * @property \Carbon\CarbonImmutable $cast_to_immutable_date * @property \Carbon\CarbonImmutable $cast_to_immutable_custom_datetime * @property \Carbon\CarbonImmutable $cast_to_immutable_datetime * @property int $cast_to_timestamp * @property string $cast_to_encrypted * @property array<array-key, mixed> $cast_to_encrypted_array * @property \Illuminate\Support\Collection<array-key, mixed> $cast_to_encrypted_collection * @property array<array-key, mixed> $cast_to_encrypted_json * @property object $cast_to_encrypted_object * @property \Illuminate\Support\Collection $cast_to_as_collection * @property \Illuminate\Support\Collection $cast_to_as_enum_collection * @property \Illuminate\Database\Eloquent\Casts\ArrayObject<array-key, mixed> $cast_to_as_array_object * @property \Illuminate\Support\Collection<int, AdvancedCastMap> $cast_to_as_collection_of * @property AdvancedCastCollection $cast_to_as_collection_using * @property AdvancedCastCollection<int, AdvancedCastMap> $cast_to_as_collection_using_and_map * @property \Illuminate\Support\Collection<int, AdvancedCastEnum> $cast_to_as_enum_collection_of * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast newQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast query() * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToAsArrayObject($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToAsCollection($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToAsEnumCollection($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToCustomDatetime($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToDateSerialization($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToDatetimeSerialization($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToEncrypted($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToEncryptedArray($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToEncryptedCollection($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToEncryptedJson($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToEncryptedObject($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToImmutableCustomDatetime($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToImmutableDate($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToImmutableDatetime($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|AdvancedCast whereCastToTimestamp($value) * @mixin \Eloquent */ class AdvancedCast extends Model { protected function casts(): array { return [ 'cast_to_date_serialization' => 'date:Y-m-d', 'cast_to_datetime_serialization' => 'datetime:Y-m-d H:i:s', 'cast_to_custom_datetime' => 'custom_datetime:Y-m-d H:i:s', 'cast_to_immutable_date' => 'immutable_date', 'cast_to_immutable_custom_datetime' => 'immutable_custom_datetime:Y-m-d H:i:s', 'cast_to_immutable_datetime' => 'immutable_datetime', 'cast_to_timestamp' => 'timestamp', 'cast_to_encrypted' => 'encrypted', 'cast_to_encrypted_array' => 'encrypted:array', 'cast_to_encrypted_collection' => 'encrypted:collection', 'cast_to_encrypted_json' => 'encrypted:json', 'cast_to_encrypted_object' => 'encrypted:object', 'cast_to_as_collection' => AsCollection::class, 'cast_to_as_collection_of' => AsCollection::class . ':,' . AdvancedCastMap::class, // since 12.10 'cast_to_as_collection_using' => AsCollection::using(AdvancedCastCollection::class), 'cast_to_as_collection_using_and_map' => AsCollection::class . ':' . AdvancedCastCollection::class . ',' . AdvancedCastMap::class, // since 12.10 'cast_to_as_enum_collection' => AsEnumCollection::class, 'cast_to_as_enum_collection_of' => AsEnumCollection::of(AdvancedCastEnum::class), 'cast_to_as_array_object' => AsArrayObject::class, ]; } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/AdvancedCasts/Collections/AdvancedCastCollection.php
tests/Console/ModelsCommand/AdvancedCasts/Collections/AdvancedCastCollection.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Collections; use Illuminate\Support\Collection; class AdvancedCastCollection extends Collection { }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/AdvancedCasts/Collections/AdvancedCastMap.php
tests/Console/ModelsCommand/AdvancedCasts/Collections/AdvancedCastMap.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Collections; use Illuminate\Contracts\Support\Arrayable; use JsonSerializable; class AdvancedCastMap implements Arrayable, JsonSerializable { public function toArray(): array { return []; } public function jsonSerialize(): array { return $this->toArray(); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/AdvancedCasts/Enums/AdvancedCastEnum.php
tests/Console/ModelsCommand/AdvancedCasts/Enums/AdvancedCastEnum.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Enums; enum AdvancedCastEnum { case apple; case banana; case orange; }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/AdvancedCasts/Models/AdvancedCast.php
tests/Console/ModelsCommand/AdvancedCasts/Models/AdvancedCast.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Models; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Collections\AdvancedCastCollection; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Collections\AdvancedCastMap; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AdvancedCasts\Enums\AdvancedCastEnum; use Illuminate\Database\Eloquent\Casts\AsArrayObject; use Illuminate\Database\Eloquent\Casts\AsCollection; use Illuminate\Database\Eloquent\Casts\AsEnumCollection; use Illuminate\Database\Eloquent\Model; class AdvancedCast extends Model { protected function casts(): array { return [ 'cast_to_date_serialization' => 'date:Y-m-d', 'cast_to_datetime_serialization' => 'datetime:Y-m-d H:i:s', 'cast_to_custom_datetime' => 'custom_datetime:Y-m-d H:i:s', 'cast_to_immutable_date' => 'immutable_date', 'cast_to_immutable_custom_datetime' => 'immutable_custom_datetime:Y-m-d H:i:s', 'cast_to_immutable_datetime' => 'immutable_datetime', 'cast_to_timestamp' => 'timestamp', 'cast_to_encrypted' => 'encrypted', 'cast_to_encrypted_array' => 'encrypted:array', 'cast_to_encrypted_collection' => 'encrypted:collection', 'cast_to_encrypted_json' => 'encrypted:json', 'cast_to_encrypted_object' => 'encrypted:object', 'cast_to_as_collection' => AsCollection::class, 'cast_to_as_collection_of' => AsCollection::class . ':,' . AdvancedCastMap::class, // since 12.10 'cast_to_as_collection_using' => AsCollection::using(AdvancedCastCollection::class), 'cast_to_as_collection_using_and_map' => AsCollection::class . ':' . AdvancedCastCollection::class . ',' . AdvancedCastMap::class, // since 12.10 'cast_to_as_enum_collection' => AsEnumCollection::class, 'cast_to_as_enum_collection_of' => AsEnumCollection::of(AdvancedCastEnum::class), 'cast_to_as_array_object' => AsArrayObject::class, ]; } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/ArrayCastsWithComment/Test.php
tests/Console/ModelsCommand/ArrayCastsWithComment/Test.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ArrayCastsWithComment; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; class Test extends AbstractModelsCommand { public function test(): void { $command = $this->app->make(ModelsCommand::class); $tester = $this->runCommand($command, [ '--write' => true, ]); $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/ArrayCastsWithComment/__snapshots__/Test__test__1.php
tests/Console/ModelsCommand/ArrayCastsWithComment/__snapshots__/Test__test__1.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ArrayCastsWithComment\Models; use Illuminate\Database\Eloquent\Model; /** * @property array<int, string>|null $cast_to_array -- These three should not be duplicated * @property array<int, string> $cast_to_json some-description * @property \Illuminate\Support\Collection<int, string> $cast_to_collection some-description * @property array|null $cast_to_encrypted_array -- These three are OK (no types) * @property array $cast_to_encrypted_json some-description * @property \Illuminate\Support\Collection $cast_to_encrypted_collection some-description * @property string $cast_to_string -- The next three are OK (no description), this not included * @property array<int, string>|null $cast_to_immutable_date * @property array<int, string> $cast_to_immutable_date_serialization * @property \Illuminate\Support\Collection<int, string> $cast_to_immutable_custom_datetime * @property string $cast_to_int * @property string $cast_to_integer * @property string $cast_to_real * @property string $cast_to_float * @property string $cast_to_double * @property string $cast_to_decimal * @property string $cast_to_bool * @property string $cast_to_boolean * @property string $cast_to_object * @property string $cast_to_date * @property string $cast_to_datetime * @property string $cast_to_date_serialization * @property string $cast_to_datetime_serialization * @property string $cast_to_custom_datetime * @property string $cast_to_immutable_datetime * @property string $cast_to_immutable_datetime_serialization * @property string $cast_to_timestamp * @property string $cast_to_encrypted * @property string $cast_to_encrypted_object * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment newQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment query() * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToArray($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToBool($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToBoolean($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToCollection($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToCustomDatetime($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToDate($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToDateSerialization($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToDatetime($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToDatetimeSerialization($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToDecimal($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToDouble($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToEncrypted($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToEncryptedArray($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToEncryptedCollection($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToEncryptedJson($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToEncryptedObject($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToFloat($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToImmutableCustomDatetime($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToImmutableDate($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToImmutableDateSerialization($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToImmutableDatetime($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToImmutableDatetimeSerialization($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToInt($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToInteger($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToJson($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToObject($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToReal($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToString($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|ArrayCastsWithComment whereCastToTimestamp($value) * @mixin \Eloquent */ class ArrayCastsWithComment extends Model { protected $table = 'simple_casts'; protected $casts = [ 'cast_to_array' => 'array', 'cast_to_json' => 'json', 'cast_to_collection' => 'collection', 'cast_to_encrypted_array' => 'array', 'cast_to_encrypted_json' => 'json', 'cast_to_encrypted_collection' => 'collection', 'cast_to_string' => 'string', 'cast_to_immutable_date' => 'array', 'cast_to_immutable_date_serialization' => 'json', 'cast_to_immutable_custom_datetime' => 'collection', ]; }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/ArrayCastsWithComment/Models/ArrayCastsWithComment.php
tests/Console/ModelsCommand/ArrayCastsWithComment/Models/ArrayCastsWithComment.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ArrayCastsWithComment\Models; use Illuminate\Database\Eloquent\Model; /** * @property array<int, string>|null $cast_to_array -- These three should not be duplicated * @property array<int, string> $cast_to_json some-description * @property \Illuminate\Support\Collection<int, string> $cast_to_collection some-description * * @property array|null $cast_to_encrypted_array -- These three are OK (no types) * @property array $cast_to_encrypted_json some-description * @property \Illuminate\Support\Collection $cast_to_encrypted_collection some-description * * @property string $cast_to_string -- The next three are OK (no description), this not included * * @property array<int, string>|null $cast_to_immutable_date * @property array<int, string> $cast_to_immutable_date_serialization * @property \Illuminate\Support\Collection<int, string> $cast_to_immutable_custom_datetime */ class ArrayCastsWithComment extends Model { protected $table = 'simple_casts'; protected $casts = [ 'cast_to_array' => 'array', 'cast_to_json' => 'json', 'cast_to_collection' => 'collection', 'cast_to_encrypted_array' => 'array', 'cast_to_encrypted_json' => 'json', 'cast_to_encrypted_collection' => 'collection', 'cast_to_string' => 'string', 'cast_to_immutable_date' => 'array', 'cast_to_immutable_date_serialization' => 'json', 'cast_to_immutable_custom_datetime' => 'collection', ]; }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Test.php
tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Test.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpDocWithTypedScopeParameter; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; class Test extends AbstractModelsCommand { public function test(): void { $command = $this->app->make(ModelsCommand::class); $tester = $this->runCommand($command, [ '--write' => true, ]); $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/__snapshots__/Test__test__1.php
tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/__snapshots__/Test__test__1.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpDocWithTypedScopeParameter\Models; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; /** * @method static Builder<static>|Comment newModelQuery() * @method static Builder<static>|Comment newQuery() * @method static Builder<static>|Comment query() * @method static Builder<static>|Comment typed01(bool $value) Scope with required boolean parameter * @method static Builder<static>|Comment typed02(bool $value = true) Scope with optional boolean parameter and default true * @method static Builder<static>|Comment typed03(bool $value = false) Scope with optional boolean parameter and default false * @method static Builder<static>|Comment typed04(string $value) Scope with required string parameter * @method static Builder<static>|Comment typed05(string $value = 'dummy123') Scope with optional string parameter and default value * @method static Builder<static>|Comment typed06(int $value) Scope with required integer parameter * @method static Builder<static>|Comment typed07(int $value = 123) Scope with optional integer parameter and default positive value * @method static Builder<static>|Comment typed08(int $value = -123) Scope with optional integer parameter and default negative value * @method static Builder<static>|Comment typed09(float $value) Scope with required float parameter * @method static Builder<static>|Comment typed10(float $value = 123) Scope with optional float parameter and default positive integer value * @method static Builder<static>|Comment typed11(float $value = -123) Scope with optional float parameter and default negative integer value * @method static Builder<static>|Comment typed12(float $value = 1.23) Scope with optional float parameter and default positive float value * @method static Builder<static>|Comment typed13(float $value = -1.23) Scope with optional float parameter and default negative float value * @method static Builder<static>|Comment typed14(?bool $value) Scope with required nullable boolean parameter * @method static Builder<static>|Comment typed15(?bool $value = true) Scope with optional nullable boolean parameter and default true * @method static Builder<static>|Comment typed16(?bool $value = false) Scope with optional nullable boolean parameter and default false * @method static Builder<static>|Comment typed17(?bool $value = null) Scope with optional nullable boolean parameter and default null * @method static Builder<static>|Comment typed18(?string $value) Scope with required nullable string parameter * @method static Builder<static>|Comment typed19(?string $value = 'dummy123') Scope with optional nullable string parameter and default value * @method static Builder<static>|Comment typed20(?string $value = null) Scope with optional nullable string parameter and default null * @method static Builder<static>|Comment typed21(?int $value) Scope with required nullable integer parameter * @method static Builder<static>|Comment typed22(?int $value = 123) Scope with optional nullable integer parameter and default positive value * @method static Builder<static>|Comment typed23(?int $value = -123) Scope with optional nullable integer parameter and default negative value * @method static Builder<static>|Comment typed24(?int $value = null) Scope with optional nullable integer parameter and default null * @method static Builder<static>|Comment typed25(?float $value) Scope with required float nullable parameter * @method static Builder<static>|Comment typed26(?float $value = 123) Scope with optional nullable float parameter and default positive integer value * @method static Builder<static>|Comment typed27(?float $value = -123) Scope with optional nullable float parameter and default negative integer value * @method static Builder<static>|Comment typed28(?float $value = 1.23) Scope with optional float parameter and default positive float value * @method static Builder<static>|Comment typed29(?float $value = -1.23) Scope with optional float parameter and default negative float value * @method static Builder<static>|Comment typed30(?float $value = null) Scope with optional float parameter and default null * @mixin \Eloquent */ class Comment extends Model { /** * @comment Scope with required boolean parameter */ protected function scopeTyped01(Builder $query, bool $value) { $query->where('type', $value); } /** * @comment Scope with optional boolean parameter and default true */ protected function scopeTyped02(Builder $query, bool $value = true) { $query->where('type', $value); } /** * @comment Scope with optional boolean parameter and default false */ protected function scopeTyped03(Builder $query, bool $value = false) { $query->where('type', $value); } /** * @comment Scope with required string parameter */ protected function scopeTyped04(Builder $query, string $value) { $query->where('type', $value); } /** * @comment Scope with optional string parameter and default value */ protected function scopeTyped05(Builder $query, string $value = 'dummy123') { $query->where('type', $value); } /** * @comment Scope with required integer parameter */ protected function scopeTyped06(Builder $query, int $value) { $query->where('type', $value); } /** * @comment Scope with optional integer parameter and default positive value */ protected function scopeTyped07(Builder $query, int $value = 123) { $query->where('type', $value); } /** * @comment Scope with optional integer parameter and default negative value */ protected function scopeTyped08(Builder $query, int $value = -123) { $query->where('type', $value); } /** * @comment Scope with required float parameter */ protected function scopeTyped09(Builder $query, float $value) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default positive integer value */ protected function scopeTyped10(Builder $query, float $value = 123) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default negative integer value */ protected function scopeTyped11(Builder $query, float $value = -123) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default positive float value */ protected function scopeTyped12(Builder $query, float $value = 1.23) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default negative float value */ protected function scopeTyped13(Builder $query, float $value = -1.23) { $query->where('type', $value); } /** * @comment Scope with required nullable boolean parameter */ protected function scopeTyped14(Builder $query, ?bool $value) { $query->where('type', $value); } /** * @comment Scope with optional nullable boolean parameter and default true */ protected function scopeTyped15(Builder $query, ?bool $value = true) { $query->where('type', $value); } /** * @comment Scope with optional nullable boolean parameter and default false */ protected function scopeTyped16(Builder $query, ?bool $value = false) { $query->where('type', $value); } /** * @comment Scope with optional nullable boolean parameter and default null */ protected function scopeTyped17(Builder $query, ?bool $value = null) { $query->where('type', $value); } /** * @comment Scope with required nullable string parameter */ protected function scopeTyped18(Builder $query, ?string $value) { $query->where('type', $value); } /** * @comment Scope with optional nullable string parameter and default value */ protected function scopeTyped19(Builder $query, ?string $value = 'dummy123') { $query->where('type', $value); } /** * @comment Scope with optional nullable string parameter and default null */ protected function scopeTyped20(Builder $query, ?string $value = null) { $query->where('type', $value); } /** * @comment Scope with required nullable integer parameter */ protected function scopeTyped21(Builder $query, ?int $value) { $query->where('type', $value); } /** * @comment Scope with optional nullable integer parameter and default positive value */ protected function scopeTyped22(Builder $query, ?int $value = 123) { $query->where('type', $value); } /** * @comment Scope with optional nullable integer parameter and default negative value */ protected function scopeTyped23(Builder $query, ?int $value = -123) { $query->where('type', $value); } /** * @comment Scope with optional nullable integer parameter and default null */ protected function scopeTyped24(Builder $query, ?int $value = null) { $query->where('type', $value); } /** * @comment Scope with required float nullable parameter */ protected function scopeTyped25(Builder $query, ?float $value) { $query->where('type', $value); } /** * @comment Scope with optional nullable float parameter and default positive integer value */ protected function scopeTyped26(Builder $query, ?float $value = 123) { $query->where('type', $value); } /** * @comment Scope with optional nullable float parameter and default negative integer value */ protected function scopeTyped27(Builder $query, ?float $value = -123) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default positive float value */ protected function scopeTyped28(Builder $query, ?float $value = 1.23) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default negative float value */ protected function scopeTyped29(Builder $query, ?float $value = -1.23) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default null */ protected function scopeTyped30(Builder $query, ?float $value = null) { $query->where('type', $value); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Models/Comment.php
tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Models/Comment.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpDocWithTypedScopeParameter\Models; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; class Comment extends Model { /** * @comment Scope with required boolean parameter */ protected function scopeTyped01(Builder $query, bool $value) { $query->where('type', $value); } /** * @comment Scope with optional boolean parameter and default true */ protected function scopeTyped02(Builder $query, bool $value = true) { $query->where('type', $value); } /** * @comment Scope with optional boolean parameter and default false */ protected function scopeTyped03(Builder $query, bool $value = false) { $query->where('type', $value); } /** * @comment Scope with required string parameter */ protected function scopeTyped04(Builder $query, string $value) { $query->where('type', $value); } /** * @comment Scope with optional string parameter and default value */ protected function scopeTyped05(Builder $query, string $value = 'dummy123') { $query->where('type', $value); } /** * @comment Scope with required integer parameter */ protected function scopeTyped06(Builder $query, int $value) { $query->where('type', $value); } /** * @comment Scope with optional integer parameter and default positive value */ protected function scopeTyped07(Builder $query, int $value = 123) { $query->where('type', $value); } /** * @comment Scope with optional integer parameter and default negative value */ protected function scopeTyped08(Builder $query, int $value = -123) { $query->where('type', $value); } /** * @comment Scope with required float parameter */ protected function scopeTyped09(Builder $query, float $value) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default positive integer value */ protected function scopeTyped10(Builder $query, float $value = 123) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default negative integer value */ protected function scopeTyped11(Builder $query, float $value = -123) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default positive float value */ protected function scopeTyped12(Builder $query, float $value = 1.23) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default negative float value */ protected function scopeTyped13(Builder $query, float $value = -1.23) { $query->where('type', $value); } /** * @comment Scope with required nullable boolean parameter */ protected function scopeTyped14(Builder $query, ?bool $value) { $query->where('type', $value); } /** * @comment Scope with optional nullable boolean parameter and default true */ protected function scopeTyped15(Builder $query, ?bool $value = true) { $query->where('type', $value); } /** * @comment Scope with optional nullable boolean parameter and default false */ protected function scopeTyped16(Builder $query, ?bool $value = false) { $query->where('type', $value); } /** * @comment Scope with optional nullable boolean parameter and default null */ protected function scopeTyped17(Builder $query, ?bool $value = null) { $query->where('type', $value); } /** * @comment Scope with required nullable string parameter */ protected function scopeTyped18(Builder $query, ?string $value) { $query->where('type', $value); } /** * @comment Scope with optional nullable string parameter and default value */ protected function scopeTyped19(Builder $query, ?string $value = 'dummy123') { $query->where('type', $value); } /** * @comment Scope with optional nullable string parameter and default null */ protected function scopeTyped20(Builder $query, ?string $value = null) { $query->where('type', $value); } /** * @comment Scope with required nullable integer parameter */ protected function scopeTyped21(Builder $query, ?int $value) { $query->where('type', $value); } /** * @comment Scope with optional nullable integer parameter and default positive value */ protected function scopeTyped22(Builder $query, ?int $value = 123) { $query->where('type', $value); } /** * @comment Scope with optional nullable integer parameter and default negative value */ protected function scopeTyped23(Builder $query, ?int $value = -123) { $query->where('type', $value); } /** * @comment Scope with optional nullable integer parameter and default null */ protected function scopeTyped24(Builder $query, ?int $value = null) { $query->where('type', $value); } /** * @comment Scope with required float nullable parameter */ protected function scopeTyped25(Builder $query, ?float $value) { $query->where('type', $value); } /** * @comment Scope with optional nullable float parameter and default positive integer value */ protected function scopeTyped26(Builder $query, ?float $value = 123) { $query->where('type', $value); } /** * @comment Scope with optional nullable float parameter and default negative integer value */ protected function scopeTyped27(Builder $query, ?float $value = -123) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default positive float value */ protected function scopeTyped28(Builder $query, ?float $value = 1.23) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default negative float value */ protected function scopeTyped29(Builder $query, ?float $value = -1.23) { $query->where('type', $value); } /** * @comment Scope with optional float parameter and default null */ protected function scopeTyped30(Builder $query, ?float $value = null) { $query->where('type', $value); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/Morphs/Test.php
tests/Console/ModelsCommand/Morphs/Test.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Morphs; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; class Test extends AbstractModelsCommand { public function test(): void { $command = $this->app->make(ModelsCommand::class); $tester = $this->runCommand($command, [ '--write' => true, ]); $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/Morphs/__snapshots__/Test__test__1.php
tests/Console/ModelsCommand/Morphs/__snapshots__/Test__test__1.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Morphs\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; /** * @property string $relation_morph_to_type * @property int $relation_morph_to_id * @property string|null $nullable_relation_morph_to_type * @property int|null $nullable_relation_morph_to_id * @property-read Model|\Eloquent|null $nullableRelationMorphTo * @property-read Model|\Eloquent $relationMorphTo * @method static \Illuminate\Database\Eloquent\Builder<static>|Morphs newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|Morphs newQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|Morphs query() * @method static \Illuminate\Database\Eloquent\Builder<static>|Morphs whereNullableRelationMorphToId($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|Morphs whereNullableRelationMorphToType($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|Morphs whereRelationMorphToId($value) * @method static \Illuminate\Database\Eloquent\Builder<static>|Morphs whereRelationMorphToType($value) * @mixin \Eloquent */ class Morphs extends Model { public function relationMorphTo(): MorphTo { return $this->morphTo(); } public function nullableRelationMorphTo(): MorphTo { return $this->morphTo(); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/Morphs/Models/Morphs.php
tests/Console/ModelsCommand/Morphs/Models/Morphs.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Morphs\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; class Morphs extends Model { public function relationMorphTo(): MorphTo { return $this->morphTo(); } public function nullableRelationMorphTo(): MorphTo { return $this->morphTo(); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/GenericsSyntaxDisabled/Test.php
tests/Console/ModelsCommand/GenericsSyntaxDisabled/Test.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenericsSyntaxDisabled; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; class Test extends AbstractModelsCommand { protected function getEnvironmentSetUp($app) { parent::getEnvironmentSetUp($app); $app['config']->set('ide-helper.use_generics_annotations', false); } public function test(): void { $command = $this->app->make(ModelsCommand::class); $tester = $this->runCommand($command, [ '--write' => true, ]); $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/GenericsSyntaxDisabled/__snapshots__/Test__test__1.php
tests/Console/ModelsCommand/GenericsSyntaxDisabled/__snapshots__/Test__test__1.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenericsSyntaxDisabled\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; /** * @property int $id * @property-read \Illuminate\Database\Eloquent\Collection|Simple[] $regularBelongsToMany * @property-read int|null $regular_belongs_to_many_count * @property-read bool|null $regular_belongs_to_many_exists * @property-read \Illuminate\Database\Eloquent\Collection|Simple[] $regularHasMany * @property-read int|null $regular_has_many_count * @property-read bool|null $regular_has_many_exists * @method static \Illuminate\Database\Eloquent\Builder<static>|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder<static>|Simple query() * @method static \Illuminate\Database\Eloquent\Builder<static>|Simple whereId($value) * @mixin \Eloquent */ class Simple extends Model { // Regular relations public function regularHasMany(): HasMany { return $this->hasMany(Simple::class); } public function regularBelongsToMany(): BelongsToMany { return $this->belongsToMany(Simple::class); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/ModelsCommand/GenericsSyntaxDisabled/Models/Simple.php
tests/Console/ModelsCommand/GenericsSyntaxDisabled/Models/Simple.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenericsSyntaxDisabled\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; class Simple extends Model { // Regular relations public function regularHasMany(): HasMany { return $this->hasMany(Simple::class); } public function regularBelongsToMany(): BelongsToMany { return $this->belongsToMany(Simple::class); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/MetaCommand/MetaCommandTest.php
tests/Console/MetaCommand/MetaCommandTest.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\MetaCommand; use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider; use Barryvdh\LaravelIdeHelper\Tests\TestCase; use Illuminate\Filesystem\Filesystem; use Mockery\MockInterface; use stdClass; class MetaCommandTest extends TestCase { protected function setUp(): void { parent::setUp(); $this->mockFilesystem(); } public function testCommand(): void { /** @var Filesystem|MockInterface $mockFileSystem */ $mockFileSystem = $this->app->make(Filesystem::class); $this->instance(Filesystem::class, $mockFileSystem); $mockFileSystem ->shouldReceive('getRequire') ->andReturnUsing(function ($__path, $__data = []) { return (static function () use ($__path, $__data) { extract($__data, EXTR_SKIP); return require $__path; })(); }); $this->artisan('ide-helper:meta'); // We're not testing the whole file, just some basic structure elements self::assertStringContainsString("namespace PHPSTORM_META {\n", $this->mockFilesystemOutput); self::assertStringContainsString("PhpStorm Meta file, to provide autocomplete information for PhpStorm\n", $this->mockFilesystemOutput); self::assertStringContainsString('override(', $this->mockFilesystemOutput); } public function testUnregisterAutoloader(): void { $current = spl_autoload_functions(); $appended = function () { }; $this->app->bind('registers-autoloader', function () use ($appended) { spl_autoload_register($appended); return new stdClass(); }); /** @var Filesystem|MockInterface $mockFileSystem */ $mockFileSystem = $this->app->make(Filesystem::class); $this->instance(Filesystem::class, $mockFileSystem); $mockFileSystem ->shouldReceive('getRequire') ->andReturnUsing(function ($__path, $__data = []) { return (static function () use ($__path, $__data) { extract($__data, EXTR_SKIP); return require $__path; })(); }); $this->artisan('ide-helper:meta'); self::assertSame(array_merge($current, [$appended]), spl_autoload_functions()); } /** * Get package providers. * * @param \Illuminate\Foundation\Application $app * * @return array */ protected function getPackageProviders($app) { return [IdeHelperServiceProvider::class]; } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/GeneratorCommand/AbstractGeneratorCommand.php
tests/Console/GeneratorCommand/AbstractGeneratorCommand.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\GeneratorCommand; use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider; use Barryvdh\LaravelIdeHelper\Tests\TestCase; abstract class AbstractGeneratorCommand extends TestCase { protected function setUp(): void { parent::setUp(); $this->mockFilesystem(); } /** * Get package providers. * * @param \Illuminate\Foundation\Application $app * * @return array */ protected function getPackageProviders($app) { return [IdeHelperServiceProvider::class]; } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/GeneratorCommand/GenerateEloquentOnly/Test.php
tests/Console/GeneratorCommand/GenerateEloquentOnly/Test.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\GeneratorCommand\GenerateEloquentOnly; use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\GeneratorCommand\AbstractGeneratorCommand; class Test extends AbstractGeneratorCommand { public function testGenerator(): void { $command = $this->app->make(GeneratorCommand::class); $tester = $this->runCommand($command, [ '--eloquent' => true, ]); $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('A new helper file was written to _ide_helper.php', $tester->getDisplay()); $this->assertStringNotContainsString('public static function configure($basePath = null)', $this->mockFilesystemOutput); $this->assertStringContainsString('class Eloquent extends \Illuminate\Database\Eloquent\Model', $this->mockFilesystemOutput); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php
tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\GeneratorCommand\GenerateIdeHelper; use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\GeneratorCommand\AbstractGeneratorCommand; use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; class Test extends AbstractGeneratorCommand { public function testGenerator(): void { Arr::macro('arr_custom_macro', function () { }); DB::macro('db_custom_macro', function () { }); $this->app['config']->set('ide-helper.macro_default_return_types', [Arr::class => 'Custom_Fake_Class']); $command = $this->app->make(GeneratorCommand::class); $tester = $this->runCommand($command); $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('A new helper file was written to _ide_helper.php', $tester->getDisplay()); $this->assertStringContainsString('public static function configure($basePath = null)', $this->mockFilesystemOutput); $this->assertStringContainsString('* @return \Custom_Fake_Class', $this->mockFilesystemOutput); $this->assertStringContainsString('public static function arr_custom_macro()', $this->mockFilesystemOutput); $this->assertStringContainsString('public static function db_custom_macro()', $this->mockFilesystemOutput); } public function testFilename(): void { $command = $this->app->make(GeneratorCommand::class); $tester = $this->runCommand($command, [ 'filename' => 'foo.php', ]); $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('A new helper file was written to foo.php', $tester->getDisplay()); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/Factories/AllTest.php
tests/Factories/AllTest.php
<?php declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Factories; use Barryvdh\LaravelIdeHelper\Factories; use PHPUnit\Framework\TestCase; class AllTest extends TestCase { public function testAll(): void { $factories = Factories::all(); self::assertEmpty($factories); } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/stubs/facade-9431b04ec1494fc71a1bc848f020044aba2af7b1.php
tests/stubs/facade-9431b04ec1494fc71a1bc848f020044aba2af7b1.php
<?php declare(strict_types=1); namespace Facades\App\Exceptions; use Illuminate\Support\Facades\Facade; /** * @see \App\Exceptions\Handler */ class Handler extends Facade { /** * Get the registered name of the component. */ protected static function getFacadeAccessor(): string { return 'App\Exceptions\Handler'; } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/tests/stubs/facade-0e0385307adf5db34c7986ecbd11646061356ec8.php
tests/stubs/facade-0e0385307adf5db34c7986ecbd11646061356ec8.php
<?php declare(strict_types=1); namespace Facades\Illuminate\Foundation\Exceptions; use Illuminate\Support\Facades\Facade; /** * @see \Illuminate\Foundation\Exceptions\Handler */ class Handler extends Facade { /** * Get the registered name of the component. */ protected static function getFacadeAccessor(): string { return 'Illuminate\Foundation\Exceptions\Handler'; } }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/config/ide-helper.php
config/ide-helper.php
<?php return [ /* |-------------------------------------------------------------------------- | Filename |-------------------------------------------------------------------------- | | The default filename. | */ 'filename' => '_ide_helper.php', /* |-------------------------------------------------------------------------- | Models filename |-------------------------------------------------------------------------- | | The default filename for the models helper file. | */ 'models_filename' => '_ide_helper_models.php', /* |-------------------------------------------------------------------------- | PhpStorm meta filename |-------------------------------------------------------------------------- | | PhpStorm also supports the directory `.phpstorm.meta.php/` with arbitrary | files in it, should you need additional files for your project; e.g. | `.phpstorm.meta.php/laravel_ide_Helper.php'. | */ 'meta_filename' => '.phpstorm.meta.php', /* |-------------------------------------------------------------------------- | Fluent helpers |-------------------------------------------------------------------------- | | Set to true to generate commonly used Fluent methods. | */ 'include_fluent' => false, /* |-------------------------------------------------------------------------- | Factory builders |-------------------------------------------------------------------------- | | Set to true to generate factory generators for better factory() | method auto-completion. | | Deprecated for Laravel 8 or latest. | */ 'include_factory_builders' => false, /* |-------------------------------------------------------------------------- | Write model magic methods |-------------------------------------------------------------------------- | | Set to false to disable write magic methods of model. | */ 'write_model_magic_where' => true, /* |-------------------------------------------------------------------------- | Write model external Eloquent builder methods |-------------------------------------------------------------------------- | | Set to false to disable write external Eloquent builder methods. | */ 'write_model_external_builder_methods' => true, /* |-------------------------------------------------------------------------- | Write model relation count and exists properties |-------------------------------------------------------------------------- | | Set to false to disable writing of relation count and exists properties | to model DocBlocks. | */ 'write_model_relation_count_properties' => true, 'write_model_relation_exists_properties' => false, /* |-------------------------------------------------------------------------- | Write Eloquent model mixins |-------------------------------------------------------------------------- | | This will add the necessary DocBlock mixins to the model class | contained in the Laravel framework. This helps the IDE with | auto-completion. | | Please be aware that this setting changes a file within the /vendor directory. | */ 'write_eloquent_model_mixins' => false, /* |-------------------------------------------------------------------------- | Helper files to include |-------------------------------------------------------------------------- | | Include helper files. By default not included, but can be toggled with the | -- helpers (-H) option. Extra helper files can be included. | */ 'include_helpers' => false, 'helper_files' => [ base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php', base_path() . '/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php', ], /* |-------------------------------------------------------------------------- | Model locations to include |-------------------------------------------------------------------------- | | Define in which directories the ide-helper:models command should look | for models. | | glob patterns are supported to easier reach models in sub-directories, | e.g. `app/Services/* /Models` (without the space). | */ 'model_locations' => [ 'app', ], /* |-------------------------------------------------------------------------- | Models to ignore |-------------------------------------------------------------------------- | | Define which models should be ignored. | */ 'ignored_models' => [ // App\MyModel::class, ], /* |-------------------------------------------------------------------------- | Models hooks |-------------------------------------------------------------------------- | | Define which hook classes you want to run for models to add custom information. | | Hooks should implement Barryvdh\LaravelIdeHelper\Contracts\ModelHookInterface. | */ 'model_hooks' => [ // App\Support\IdeHelper\MyModelHook::class ], /* |-------------------------------------------------------------------------- | Extra classes |-------------------------------------------------------------------------- | | These implementations are not really extended, but called with magic functions. | */ 'extra' => [ 'Eloquent' => ['Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'], 'Session' => ['Illuminate\Session\Store'], ], 'magic' => [], /* |-------------------------------------------------------------------------- | Interface implementations |-------------------------------------------------------------------------- | | These interfaces will be replaced with the implementing class. Some interfaces | are detected by the helpers, others can be listed below. | */ 'interfaces' => [ // App\MyInterface::class => App\MyImplementation::class, ], /* |-------------------------------------------------------------------------- | Support for camel cased models |-------------------------------------------------------------------------- | | There are some Laravel packages (such as Eloquence) that allow for accessing | Eloquent model properties via camel case, instead of snake case. | | Enabling this option will support these packages by saving all model | properties as camel case, instead of snake case. | | For example, normally you would see this: | | * @property \Illuminate\Support\Carbon $created_at | * @property \Illuminate\Support\Carbon $updated_at | | With this enabled, the properties will be this: | | * @property \Illuminate\Support\Carbon $createdAt | * @property \Illuminate\Support\Carbon $updatedAt | | Note, it is currently an all-or-nothing option. | */ 'model_camel_case_properties' => false, /* |-------------------------------------------------------------------------- | Property casts |-------------------------------------------------------------------------- | | Cast the given "real type" to the given "type". | */ 'type_overrides' => [ 'integer' => 'int', 'boolean' => 'bool', ], /* |-------------------------------------------------------------------------- | Include DocBlocks from classes |-------------------------------------------------------------------------- | | Include DocBlocks from classes to allow additional code inspection for | magic methods and properties. | */ 'include_class_docblocks' => false, /* |-------------------------------------------------------------------------- | Force FQN usage |-------------------------------------------------------------------------- | | Use the fully qualified (class) name in DocBlocks, | even if the class exists in the same namespace | or there is an import (use className) of the class. | */ 'force_fqn' => false, /* |-------------------------------------------------------------------------- | Use generics syntax |-------------------------------------------------------------------------- | | Use generics syntax within DocBlocks, | e.g. `Collection<User>` instead of `Collection|User[]`. | */ 'use_generics_annotations' => true, /* |-------------------------------------------------------------------------- | Default return types for macros |-------------------------------------------------------------------------- | | Define default return types for macros without explicit return types. | e.g. `\Illuminate\Database\Query\Builder::class => 'static'`, | `\Illuminate\Support\Str::class => 'string'` | */ 'macro_default_return_types' => [ Illuminate\Http\Client\Factory::class => Illuminate\Http\Client\PendingRequest::class, ], /* |-------------------------------------------------------------------------- | Additional relation types |-------------------------------------------------------------------------- | | Sometimes it's needed to create custom relation types. The key of the array | is the relationship method name. The value of the array is the fully-qualified | class name of the relationship, e.g. `'relationName' => RelationShipClass::class`. | */ 'additional_relation_types' => [], /* |-------------------------------------------------------------------------- | Additional relation return types |-------------------------------------------------------------------------- | | When using custom relation types its possible for the class name to not contain | the proper return type of the relation. The key of the array is the relationship | method name. The value of the array is the return type of the relation ('many' | or 'morphTo'). | e.g. `'relationName' => 'many'`. | */ 'additional_relation_return_types' => [], /* |-------------------------------------------------------------------------- | Enforce nullable Eloquent relationships on not null columns |-------------------------------------------------------------------------- | | When set to true (default), this option enforces nullable Eloquent relationships. | However, in cases where the application logic ensures the presence of related | records it may be desirable to set this option to false to avoid unwanted null warnings. | | Default: true | A not null column with no foreign key constraint will have a "nullable" relationship. | * @property int $not_null_column_with_no_foreign_key_constraint | * @property-read BelongsToVariation|null $notNullColumnWithNoForeignKeyConstraint | | Option: false | A not null column with no foreign key constraint will have a "not nullable" relationship. | * @property int $not_null_column_with_no_foreign_key_constraint | * @property-read BelongsToVariation $notNullColumnWithNoForeignKeyConstraint | */ 'enforce_nullable_relationships' => true, /* |-------------------------------------------------------------------------- | Run artisan commands after migrations to generate model helpers |-------------------------------------------------------------------------- | | The specified commands should run after migrations are finished running. | */ 'post_migrate' => [ // 'ide-helper:models --nowrite', ], ];
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/resources/views/meta.php
resources/views/meta.php
<?= '<?php' ?> /* @noinspection ALL */ // @formatter:off // phpcs:ignoreFile namespace PHPSTORM_META { /** * PhpStorm Meta file, to provide autocomplete information for PhpStorm * * @author Barry vd. Heuvel <barryvdh@gmail.com> * @see https://github.com/barryvdh/laravel-ide-helper */ <?php foreach ($methods as $method) : ?> override(<?= $method ?>, map([ '' => '@', <?php foreach ($bindings as $abstract => $class) : ?> '<?= $abstract ?>' => \<?= $class ?>::class, <?php endforeach; ?> ])); <?php endforeach; ?> <?php foreach ($userMethods as $method) : ?> override(<?= $method ?>, map([ '' => \<?= $userModel ?>::class, ])); <?php endforeach; ?> <?php foreach ($configMethods as $method) : ?> override(<?= $method ?>, map([ <?php foreach ($configValues as $name => $value) : ?> '<?= $name ?>' => '<?= $value ?>', <?php endforeach; ?> ])); <?php endforeach; ?> <?php if (count($factories)) : ?> override(\factory(0), map([ '' => '@FactoryBuilder', <?php foreach ($factories as $factory) : ?> '<?= $factory->getName() ?>' => \<?= $factory->getName() ?>FactoryBuilder::class, <?php endforeach; ?> ])); <?php endif; ?> override(\Illuminate\Foundation\Testing\Concerns\InteractsWithContainer::mock(0), map(["" => "@&\Mockery\MockInterface"])); override(\Illuminate\Foundation\Testing\Concerns\InteractsWithContainer::partialMock(0), map(["" => "@&\Mockery\MockInterface"])); override(\Illuminate\Foundation\Testing\Concerns\InteractsWithContainer::instance(0), type(1)); override(\Illuminate\Foundation\Testing\Concerns\InteractsWithContainer::spy(0), map(["" => "@&\Mockery\MockInterface"])); override(\Illuminate\Support\Arr::add(0), type(0)); override(\Illuminate\Support\Arr::except(0), type(0)); override(\Illuminate\Support\Arr::first(0), elementType(0)); override(\Illuminate\Support\Arr::last(0), elementType(0)); override(\Illuminate\Support\Arr::get(0), elementType(0)); override(\Illuminate\Support\Arr::only(0), type(0)); override(\Illuminate\Support\Arr::prepend(0), type(0)); override(\Illuminate\Support\Arr::pull(0), elementType(0)); override(\Illuminate\Support\Arr::set(0), type(0)); override(\Illuminate\Support\Arr::shuffle(0), type(0)); override(\Illuminate\Support\Arr::sort(0), type(0)); override(\Illuminate\Support\Arr::sortRecursive(0), type(0)); override(\Illuminate\Support\Arr::where(0), type(0)); override(\array_add(0), type(0)); override(\array_except(0), type(0)); override(\array_first(0), elementType(0)); override(\array_last(0), elementType(0)); override(\array_get(0), elementType(0)); override(\array_only(0), type(0)); override(\array_prepend(0), type(0)); override(\array_pull(0), elementType(0)); override(\array_set(0), type(0)); override(\array_sort(0), type(0)); override(\array_sort_recursive(0), type(0)); override(\array_where(0), type(0)); override(\head(0), elementType(0)); override(\last(0), elementType(0)); override(\with(0), type(0)); override(\tap(0), type(0)); override(\optional(0), type(0)); <?php if (isset($expectedArgumentSets)): ?> <?php foreach ($expectedArgumentSets as $name => $argumentsList) : ?> registerArgumentsSet('<?= $name ?>', <?php foreach ($argumentsList as $i => $arg) : ?><?php if ($i % 5 == 0) { echo "\n"; } ?><?= var_export($arg, true); ?>,<?php endforeach; ?>); <?php endforeach; ?> <?php endif ?> <?php if (isset($expectedArguments)) : ?> <?php foreach ($expectedArguments as $arguments) : ?> <?php $classes = isset($arguments['class']) ? (array) $arguments['class'] : [null]; $index = $arguments['index'] ?? 0; $argumentSet = $arguments['argumentSet']; $functions = []; foreach ($classes as $class) { foreach ((array) $arguments['method'] as $method) { $functions[] = '\\' . ($class ? ltrim($class, '\\') . '::' : '') . $method . '()'; } } ?> <?php foreach ($functions as $function) : ?> expectedArguments(<?= $function ?>, <?= $index ?>, argumentsSet('<?= $argumentSet ?>')); <?php endforeach; ?> <?php endforeach; ?> <?php endif; ?> }
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
barryvdh/laravel-ide-helper
https://github.com/barryvdh/laravel-ide-helper/blob/2ac73f2953f59e43b798e959a352e09305cb5320/resources/views/helper.php
resources/views/helper.php
<?= '<?php' ?> <?php /** * @var Barryvdh\LaravelIdeHelper\Alias[][] $namespaces_by_alias_ns * @var Barryvdh\LaravelIdeHelper\Alias[][] $namespaces_by_extends_ns * @var bool $include_fluent * @var string $helpers */ ?> /* @noinspection ALL */ // @formatter:off // phpcs:ignoreFile /** * A helper file for Laravel, to provide autocomplete information to your IDE * Generated for Laravel <?= app()->version() ?>. * * This file should not be included in your code, only analyzed by your IDE! * * @author Barry vd. Heuvel <barryvdh@gmail.com> * @see https://github.com/barryvdh/laravel-ide-helper */ <?php $s1 = ' '; $s2 = $s1 . $s1; $s3 = $s1 . $s2; ?> <?php foreach ($namespaces_by_extends_ns as $namespace => $aliases) : ?> namespace <?= $namespace === '__root' ? '' : trim($namespace, '\\') ?> { <?php foreach ($aliases as $alias) : ?> <?php echo trim($alias->getDocComment($s1)) . "\n{$s1}" . $alias->getClassType() ?> <?= $alias->getExtendsClass() ?><?php if ($alias->shouldExtendParentClass()): ?> extends <?= $alias->getParentClass() ?><?php endif; ?> { <?php foreach ($alias->getMethods() as $method) : ?> <?= trim($method->getDocComment($s2)) . "\n{$s2}" ?>public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>) {<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?> <?= "\n" . $s3?>//Method inherited from <?= $method->getDeclaringClass() ?> <?php endif; ?> <?php if ($method->isInstanceCall()) : ?> <?= $s3 ?>/** @var <?=$method->getRoot()?> $instance */ <?php endif?> <?= $s3 . ($method->shouldReturn() ? 'return ' : '') ?><?= $method->getRootMethodCall() ?>; } <?php endforeach; ?> } <?php endforeach; ?> } <?php endforeach; ?> <?php foreach ($namespaces_by_alias_ns as $namespace => $aliases) : ?> namespace <?= $namespace === '__root' ? '' : trim($namespace, '\\') ?> { <?php foreach ($aliases as $alias) : ?> <?php if ($alias->getExtendsNamespace() === '\Illuminate\Database\Eloquent') : ?> <?= "\n" . $alias->getPhpDocTemplates($s1) . "\n" ?> <?php endif?> <?= $s1 . $alias->getClassType() ?> <?= $alias->getShortName() ?> extends <?= $alias->getExtends() ?> {<?php if ($alias->getExtendsNamespace() === '\Illuminate\Database\Eloquent') : ?> <?php foreach ($alias->getMethods() as $method) : ?> <?= $s2 . trim($method->getDocComment($s2)) . "\n" ?> <?= $s2 ?>public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>) <?= $s2?>{<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?> <?= $s2 ?>//Method inherited from <?= $method->getDeclaringClass() ?> <?php endif; ?> <?php if ($method->isInstanceCall()) : ?> <?= $s3 ?>/** @var <?=$method->getRoot()?> $instance */ <?php endif?> <?= $s3 . ($method->shouldReturn() ? 'return ' : '') ?><?= $method->getRootMethodCall() ?>; <?= $s2 ?>} <?php endforeach; ?> <?php endif; ?>} <?php endforeach; ?> } <?php endforeach; ?> <?php foreach ($real_time_facades as $name): ?> <?php $nested = explode('\\', str_replace('\\' . class_basename($name), '', $name)); ?> namespace <?php echo implode('\\', $nested); ?> { /** * @mixin <?= str_replace('Facades', '', $name) ?> */ class <?= class_basename($name) ?> extends <?= str_replace('Facades', '', $name) ?> {} } <?php endforeach; ?> <?php if ($helpers) : ?> namespace { <?= $helpers ?> } <?php endif; ?> <?php if ($include_fluent) : ?> namespace Illuminate\Support { /** * Methods commonly used in migrations * * @method Fluent after(string $column) Add the after modifier * @method Fluent charset(string $charset) Add the character set modifier * @method Fluent collation(string $collation) Add the collation modifier * @method Fluent comment(string $comment) Add comment * @method Fluent default($value) Add the default modifier * @method Fluent first() Select first row * @method Fluent index(string $name = null) Add the in dex clause * @method Fluent on(string $table) `on` of a foreign key * @method Fluent onDelete(string $action) `on delete` of a foreign key * @method Fluent onUpdate(string $action) `on update` of a foreign key * @method Fluent primary() Add the primary key modifier * @method Fluent references(string $column) `references` of a foreign key * @method Fluent nullable(bool $value = true) Add the nullable modifier * @method Fluent unique(string $name = null) Add unique index clause * @method Fluent unsigned() Add the unsigned modifier * @method Fluent useCurrent() Add the default timestamp value * @method Fluent change() Add the change modifier */ class Fluent {} } <?php endif ?> <?php foreach ($factories as $factory) : ?> namespace <?=$factory->getNamespaceName()?> { /** * @method \Illuminate\Database\Eloquent\Collection|<?=$factory->getShortName()?>[]|<?=$factory->getShortName()?> create($attributes = []) * @method \Illuminate\Database\Eloquent\Collection|<?=$factory->getShortName()?>[]|<?=$factory->getShortName()?> make($attributes = []) */ class <?=$factory->getShortName()?>FactoryBuilder extends \Illuminate\Database\Eloquent\FactoryBuilder {} } <?php endforeach; ?>
php
MIT
2ac73f2953f59e43b798e959a352e09305cb5320
2026-01-04T15:02:42.026190Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Collection.php
src/Collection.php
<?php declare(strict_types=1); namespace Intervention\Image; use Intervention\Image\Interfaces\CollectionInterface; use ArrayIterator; use Countable; use Traversable; use IteratorAggregate; /** * @implements IteratorAggregate<int|string, mixed> */ class Collection implements CollectionInterface, IteratorAggregate, Countable { /** * Create new collection object * * @param array<int|string, mixed> $items * @return void */ public function __construct(protected array $items = []) { // } /** * Static constructor * * @param array<int|string, mixed> $items * @return self<int|string, mixed> */ public static function create(array $items = []): self { return new self($items); } /** * {@inheritdoc} * * @see CollectionInterface::has() */ public function has(int|string $key): bool { return array_key_exists($key, $this->items); } /** * Returns Iterator * * @return Traversable<int|string, mixed> */ public function getIterator(): Traversable { return new ArrayIterator($this->items); } /** * {@inheritdoc} * * @see CollectionInterface::toArray() */ public function toArray(): array { return $this->items; } /** * Count items in collection */ public function count(): int { return count($this->items); } /** * Append new item to collection * * @return CollectionInterface<int|string, mixed> */ public function push(mixed $item): CollectionInterface { $this->items[] = $item; return $this; } /** * Return first item in collection */ public function first(): mixed { if ($item = reset($this->items)) { return $item; } return null; } /** * Returns last item in collection */ public function last(): mixed { if ($item = end($this->items)) { return $item; } return null; } /** * Return item at given position starting at 0 */ public function getAtPosition(int $key = 0, mixed $default = null): mixed { if ($this->count() == 0) { return $default; } $positions = array_values($this->items); if (!array_key_exists($key, $positions)) { return $default; } return $positions[$key]; } /** * {@inheritdoc} * * @see CollectionInterface::get() */ public function get(int|string $query, mixed $default = null): mixed { if ($this->count() == 0) { return $default; } if (is_int($query) && array_key_exists($query, $this->items)) { return $this->items[$query]; } if (is_string($query) && !str_contains($query, '.')) { return array_key_exists($query, $this->items) ? $this->items[$query] : $default; } $query = explode('.', (string) $query); $result = $default; $items = $this->items; foreach ($query as $key) { if (!is_array($items) || !array_key_exists($key, $items)) { $result = $default; break; } $result = $items[$key]; $items = $result; } return $result; } /** * Map each item of collection by given callback */ public function map(callable $callback): self { return new self( array_map( fn(mixed $item) => $callback($item), $this->items, ) ); } /** * Run callback on each item of the collection an remove it if it does not return true */ public function filter(callable $callback): self { return new self( array_filter( $this->items, fn(mixed $item) => $callback($item), ) ); } /** * {@inheritdoc} * * @see CollectionInterface::empty() */ public function empty(): CollectionInterface { $this->items = []; return $this; } /** * {@inheritdoc} * * @see CollectionInterface::slice() */ public function slice(int $offset, ?int $length = null): CollectionInterface { $this->items = array_slice($this->items, $offset, $length); return $this; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/EncodedImage.php
src/EncodedImage.php
<?php declare(strict_types=1); namespace Intervention\Image; use Intervention\Image\Interfaces\EncodedImageInterface; class EncodedImage extends File implements EncodedImageInterface { /** * Create new instance * * @param string|resource $data */ public function __construct( mixed $data, protected string $mediaType = 'application/octet-stream' ) { parent::__construct($data); } /** * {@inheritdoc} * * @see EncodedImageInterface::mediaType() */ public function mediaType(): string { return $this->mediaType; } /** * {@inheritdoc} * * @see EncodedImageInterface::mimetype() */ public function mimetype(): string { return $this->mediaType(); } /** * {@inheritdoc} * * @see EncodedImageInterface::toDataUri() */ public function toDataUri(): string { return sprintf('data:%s;base64,%s', $this->mediaType(), base64_encode((string) $this)); } /** * Show debug info for the current image * * @return array<string, mixed> */ public function __debugInfo(): array { return [ 'mediaType' => $this->mediaType(), 'size' => $this->size(), ]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/MediaType.php
src/MediaType.php
<?php declare(strict_types=1); namespace Intervention\Image; use Error; use Intervention\Image\Exceptions\NotSupportedException; enum MediaType: string { case IMAGE_JPEG = 'image/jpeg'; case IMAGE_JPG = 'image/jpg'; case IMAGE_PJPEG = 'image/pjpeg'; case IMAGE_X_JPEG = 'image/x-jpeg'; case IMAGE_WEBP = 'image/webp'; case IMAGE_X_WEBP = 'image/x-webp'; case IMAGE_GIF = 'image/gif'; case IMAGE_PNG = 'image/png'; case IMAGE_X_PNG = 'image/x-png'; case IMAGE_AVIF = 'image/avif'; case IMAGE_X_AVIF = 'image/x-avif'; case IMAGE_BMP = 'image/bmp'; case IMAGE_MS_BMP = 'image/ms-bmp'; case IMAGE_X_BITMAP = 'image/x-bitmap'; case IMAGE_X_BMP = 'image/x-bmp'; case IMAGE_X_MS_BMP = 'image/x-ms-bmp'; case IMAGE_X_WINDOWS_BMP = 'image/x-windows-bmp'; case IMAGE_X_WIN_BITMAP = 'image/x-win-bitmap'; case IMAGE_X_XBITMAP = 'image/x-xbitmap'; case IMAGE_X_BMP3 = 'image/x-bmp3'; case IMAGE_TIFF = 'image/tiff'; case IMAGE_JP2 = 'image/jp2'; case IMAGE_X_JP2_CODESTREAM = 'image/x-jp2-codestream'; case IMAGE_JPX = 'image/jpx'; case IMAGE_JPM = 'image/jpm'; case IMAGE_HEIC = 'image/heic'; case IMAGE_X_HEIC = 'image/x-heic'; case IMAGE_HEIF = 'image/heif'; /** * Create media type from given identifier * * @param string|Format|MediaType|FileExtension $identifier * @throws NotSupportedException */ public static function create(string|self|Format|FileExtension $identifier): self { if ($identifier instanceof self) { return $identifier; } if ($identifier instanceof Format) { return $identifier->mediaType(); } if ($identifier instanceof FileExtension) { return $identifier->mediaType(); } try { $type = self::from(strtolower($identifier)); } catch (Error) { try { $type = FileExtension::from(strtolower($identifier))->mediaType(); } catch (Error) { throw new NotSupportedException('Unable to create media type from "' . $identifier . '".'); } } return $type; } /** * Try to create media type from given identifier and return null on failure * * @param string|Format|MediaType|FileExtension $identifier * @return MediaType|null */ public static function tryCreate(string|self|Format|FileExtension $identifier): ?self { try { return self::create($identifier); } catch (NotSupportedException) { return null; } } /** * Return the matching format for the current media (MIME) type */ public function format(): Format { return match ($this) { self::IMAGE_JPEG, self::IMAGE_JPG, self::IMAGE_PJPEG, self::IMAGE_X_JPEG => Format::JPEG, self::IMAGE_WEBP, self::IMAGE_X_WEBP => Format::WEBP, self::IMAGE_GIF => Format::GIF, self::IMAGE_PNG, self::IMAGE_X_PNG => Format::PNG, self::IMAGE_AVIF, self::IMAGE_X_AVIF => Format::AVIF, self::IMAGE_BMP, self::IMAGE_MS_BMP, self::IMAGE_X_BITMAP, self::IMAGE_X_BMP, self::IMAGE_X_MS_BMP, self::IMAGE_X_XBITMAP, self::IMAGE_X_WINDOWS_BMP, self::IMAGE_X_BMP3, self::IMAGE_X_WIN_BITMAP => Format::BMP, self::IMAGE_TIFF => Format::TIFF, self::IMAGE_JP2, self::IMAGE_JPX, self::IMAGE_X_JP2_CODESTREAM, self::IMAGE_JPM => Format::JP2, self::IMAGE_HEIF, self::IMAGE_HEIC, self::IMAGE_X_HEIC => Format::HEIC, }; } /** * Return the possible file extension for the current media type * * @return array<FileExtension> */ public function fileExtensions(): array { return $this->format()->fileExtensions(); } /** * Return the first file extension for the current media type */ public function fileExtension(): FileExtension { return $this->format()->fileExtension(); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/InputHandler.php
src/InputHandler.php
<?php declare(strict_types=1); namespace Intervention\Image; use Intervention\Image\Colors\Cmyk\Decoders\StringColorDecoder as CmykStringColorDecoder; use Intervention\Image\Colors\Hsl\Decoders\StringColorDecoder as HslStringColorDecoder; use Intervention\Image\Colors\Hsv\Decoders\StringColorDecoder as HsvStringColorDecoder; use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder as RgbHexColorDecoder; use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder; use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder as RgbStringColorDecoder; use Intervention\Image\Colors\Rgb\Decoders\TransparentColorDecoder; use Intervention\Image\Decoders\Base64ImageDecoder; use Intervention\Image\Decoders\BinaryImageDecoder; use Intervention\Image\Decoders\ColorObjectDecoder; use Intervention\Image\Decoders\DataUriImageDecoder; use Intervention\Image\Decoders\EncodedImageObjectDecoder; use Intervention\Image\Decoders\FilePathImageDecoder; use Intervention\Image\Decoders\FilePointerImageDecoder; use Intervention\Image\Decoders\ImageObjectDecoder; use Intervention\Image\Decoders\NativeObjectDecoder; use Intervention\Image\Decoders\SplFileInfoImageDecoder; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Exceptions\DriverException; use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\InputHandlerInterface; class InputHandler implements InputHandlerInterface { /** * Decoder classnames in hierarchical order * * @var array<string|DecoderInterface> */ protected array $decoders = [ NativeObjectDecoder::class, ImageObjectDecoder::class, ColorObjectDecoder::class, RgbHexColorDecoder::class, RgbStringColorDecoder::class, CmykStringColorDecoder::class, HsvStringColorDecoder::class, HslStringColorDecoder::class, TransparentColorDecoder::class, HtmlColornameDecoder::class, FilePointerImageDecoder::class, FilePathImageDecoder::class, SplFileInfoImageDecoder::class, BinaryImageDecoder::class, DataUriImageDecoder::class, Base64ImageDecoder::class, EncodedImageObjectDecoder::class, ]; /** * Driver with which the decoder classes are specialized */ protected ?DriverInterface $driver = null; /** * Create new input handler instance with given decoder classnames * * @param array<string|DecoderInterface> $decoders * @return void */ public function __construct(array $decoders = [], ?DriverInterface $driver = null) { $this->decoders = count($decoders) ? $decoders : $this->decoders; $this->driver = $driver; } /** * Static factory method * * @param array<string|DecoderInterface> $decoders */ public static function withDecoders(array $decoders, ?DriverInterface $driver = null): self { return new self($decoders, $driver); } /** * {@inheritdoc} * * @see InputHandlerInterface::handle() */ public function handle(mixed $input): ImageInterface|ColorInterface { foreach ($this->decoders as $decoder) { try { // decode with driver specialized decoder return $this->resolve($decoder)->decode($input); } catch (DecoderException | NotSupportedException $e) { // try next decoder } } if (isset($e)) { throw new ($e::class)($e->getMessage()); } throw new DecoderException('Unable to decode input.'); } /** * Resolve the given classname to an decoder object * * @throws DriverException * @throws NotSupportedException */ private function resolve(string|DecoderInterface $decoder): DecoderInterface { if (($decoder instanceof DecoderInterface) && empty($this->driver)) { return $decoder; } if (($decoder instanceof DecoderInterface) && !empty($this->driver)) { return $this->driver->specialize($decoder); } if (empty($this->driver)) { return new $decoder(); } return $this->driver->specialize(new $decoder()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Image.php
src/Image.php
<?php declare(strict_types=1); namespace Intervention\Image; use Closure; use Intervention\Image\Exceptions\RuntimeException; use Traversable; use Intervention\Image\Analyzers\ColorspaceAnalyzer; use Intervention\Image\Analyzers\HeightAnalyzer; use Intervention\Image\Analyzers\PixelColorAnalyzer; use Intervention\Image\Analyzers\PixelColorsAnalyzer; use Intervention\Image\Analyzers\ProfileAnalyzer; use Intervention\Image\Analyzers\ResolutionAnalyzer; use Intervention\Image\Analyzers\WidthAnalyzer; use Intervention\Image\Encoders\AutoEncoder; use Intervention\Image\Encoders\AvifEncoder; use Intervention\Image\Encoders\BmpEncoder; use Intervention\Image\Encoders\FileExtensionEncoder; use Intervention\Image\Encoders\FilePathEncoder; use Intervention\Image\Encoders\GifEncoder; use Intervention\Image\Encoders\HeicEncoder; use Intervention\Image\Encoders\Jpeg2000Encoder; use Intervention\Image\Encoders\JpegEncoder; use Intervention\Image\Encoders\MediaTypeEncoder; use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Encoders\TiffEncoder; use Intervention\Image\Encoders\WebpEncoder; use Intervention\Image\Exceptions\EncoderException; use Intervention\Image\Geometry\Bezier; use Intervention\Image\Geometry\Circle; use Intervention\Image\Geometry\Ellipse; use Intervention\Image\Geometry\Factories\BezierFactory; use Intervention\Image\Geometry\Factories\CircleFactory; use Intervention\Image\Geometry\Factories\EllipseFactory; use Intervention\Image\Geometry\Factories\LineFactory; use Intervention\Image\Geometry\Factories\PolygonFactory; use Intervention\Image\Geometry\Factories\RectangleFactory; use Intervention\Image\Geometry\Line; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Polygon; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\CollectionInterface; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; use Intervention\Image\Interfaces\CoreInterface; use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\EncodedImageInterface; use Intervention\Image\Interfaces\EncoderInterface; use Intervention\Image\Interfaces\FontInterface; use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ModifierInterface; use Intervention\Image\Interfaces\ProfileInterface; use Intervention\Image\Interfaces\ResolutionInterface; use Intervention\Image\Interfaces\SizeInterface; use Intervention\Image\Modifiers\AlignRotationModifier; use Intervention\Image\Modifiers\BlendTransparencyModifier; use Intervention\Image\Modifiers\BlurModifier; use Intervention\Image\Modifiers\BrightnessModifier; use Intervention\Image\Modifiers\ColorizeModifier; use Intervention\Image\Modifiers\ColorspaceModifier; use Intervention\Image\Modifiers\ContainModifier; use Intervention\Image\Modifiers\ContrastModifier; use Intervention\Image\Modifiers\CropModifier; use Intervention\Image\Modifiers\DrawBezierModifier; use Intervention\Image\Modifiers\DrawEllipseModifier; use Intervention\Image\Modifiers\DrawLineModifier; use Intervention\Image\Modifiers\DrawPixelModifier; use Intervention\Image\Modifiers\DrawPolygonModifier; use Intervention\Image\Modifiers\DrawRectangleModifier; use Intervention\Image\Modifiers\FillModifier; use Intervention\Image\Modifiers\CoverDownModifier; use Intervention\Image\Modifiers\CoverModifier; use Intervention\Image\Modifiers\FlipModifier; use Intervention\Image\Modifiers\FlopModifier; use Intervention\Image\Modifiers\GammaModifier; use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Modifiers\InvertModifier; use Intervention\Image\Modifiers\PadModifier; use Intervention\Image\Modifiers\PixelateModifier; use Intervention\Image\Modifiers\PlaceModifier; use Intervention\Image\Modifiers\ProfileModifier; use Intervention\Image\Modifiers\ProfileRemovalModifier; use Intervention\Image\Modifiers\QuantizeColorsModifier; use Intervention\Image\Modifiers\RemoveAnimationModifier; use Intervention\Image\Modifiers\ResizeCanvasModifier; use Intervention\Image\Modifiers\ResizeCanvasRelativeModifier; use Intervention\Image\Modifiers\ResizeDownModifier; use Intervention\Image\Modifiers\ResizeModifier; use Intervention\Image\Modifiers\ResolutionModifier; use Intervention\Image\Modifiers\RotateModifier; use Intervention\Image\Modifiers\ScaleDownModifier; use Intervention\Image\Modifiers\ScaleModifier; use Intervention\Image\Modifiers\SharpenModifier; use Intervention\Image\Modifiers\SliceAnimationModifier; use Intervention\Image\Modifiers\TextModifier; use Intervention\Image\Modifiers\TrimModifier; use Intervention\Image\Typography\FontFactory; final class Image implements ImageInterface { /** * The origin from which the image was created */ private Origin $origin; /** * Create new instance * * @throws RuntimeException * @return void */ public function __construct( private DriverInterface $driver, private CoreInterface $core, private CollectionInterface $exif = new Collection() ) { $this->origin = new Origin(); } /** * {@inheritdoc} * * @see ImageInterface::driver() */ public function driver(): DriverInterface { return $this->driver; } /** * {@inheritdoc} * * @see ImageInterface::core() */ public function core(): CoreInterface { return $this->core; } /** * {@inheritdoc} * * @see ImageInterface::origin() */ public function origin(): Origin { return $this->origin; } /** * {@inheritdoc} * * @see ImageInterface::setOrigin() */ public function setOrigin(Origin $origin): ImageInterface { $this->origin = $origin; return $this; } /** * {@inheritdoc} * * @see ImageInterface::count() */ public function count(): int { return $this->core->count(); } /** * Implementation of IteratorAggregate * * @return Traversable<FrameInterface> */ public function getIterator(): Traversable { return $this->core; } /** * {@inheritdoc} * * @see ImageInterface::isAnimated() */ public function isAnimated(): bool { return $this->count() > 1; } /** * {@inheritdoc} * * @see ImageInterface::removeAnimation( */ public function removeAnimation(int|string $position = 0): ImageInterface { return $this->modify(new RemoveAnimationModifier($position)); } /** * {@inheritdoc} * * @see ImageInterface::sliceAnimation() */ public function sliceAnimation(int $offset = 0, ?int $length = null): ImageInterface { return $this->modify(new SliceAnimationModifier($offset, $length)); } /** * {@inheritdoc} * * @see ImageInterface::loops() */ public function loops(): int { return $this->core->loops(); } /** * {@inheritdoc} * * @see ImageInterface::setLoops() */ public function setLoops(int $loops): ImageInterface { $this->core->setLoops($loops); return $this; } /** * {@inheritdoc} * * @see ImageInterface::exif() */ public function exif(?string $query = null): mixed { return is_null($query) ? $this->exif : $this->exif->get($query); } /** * {@inheritdoc} * * @see ImageInterface::setExif() */ public function setExif(CollectionInterface $exif): ImageInterface { $this->exif = $exif; return $this; } /** * {@inheritdoc} * * @see ImageInterface::modify() */ public function modify(ModifierInterface $modifier): ImageInterface { return $this->driver->specialize($modifier)->apply($this); } /** * {@inheritdoc} * * @see ImageInterface::analyze() */ public function analyze(AnalyzerInterface $analyzer): mixed { return $this->driver->specialize($analyzer)->analyze($this); } /** * {@inheritdoc} * * @see ImageInterface::encode() */ public function encode(EncoderInterface $encoder = new AutoEncoder()): EncodedImageInterface { return $this->driver->specialize($encoder)->encode($this); } /** * {@inheritdoc} * * @see ImageInterface::save() */ public function save(?string $path = null, mixed ...$options): ImageInterface { $path = is_null($path) ? $this->origin()->filePath() : $path; if (is_null($path)) { throw new EncoderException('Could not determine file path to save.'); } try { // try to determine encoding format by file extension of the path $encoded = $this->encodeByPath($path, ...$options); } catch (EncoderException) { // fallback to encoding format by media type $encoded = $this->encodeByMediaType(null, ...$options); } $encoded->save($path); return $this; } /** * {@inheritdoc} * * @see ImageInterface::width() */ public function width(): int { return $this->analyze(new WidthAnalyzer()); } /** * {@inheritdoc} * * @see ImageInterface::height() */ public function height(): int { return $this->analyze(new HeightAnalyzer()); } /** * {@inheritdoc} * * @see ImageInterface::size() */ public function size(): SizeInterface { return new Rectangle($this->width(), $this->height()); } /** * {@inheritdoc} * * @see ImageInterface::colorspace() */ public function colorspace(): ColorspaceInterface { return $this->analyze(new ColorspaceAnalyzer()); } /** * {@inheritdoc} * * @see ImageInterface::setColorspace() */ public function setColorspace(string|ColorspaceInterface $colorspace): ImageInterface { return $this->modify(new ColorspaceModifier($colorspace)); } /** * {@inheritdoc} * * @see ImageInterface::resolution() */ public function resolution(): ResolutionInterface { return $this->analyze(new ResolutionAnalyzer()); } /** * {@inheritdoc} * * @see ImageInterface::setResolution() */ public function setResolution(float $x, float $y): ImageInterface { return $this->modify(new ResolutionModifier($x, $y)); } /** * {@inheritdoc} * * @see ImageInterface::pickColor() */ public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface { return $this->analyze(new PixelColorAnalyzer($x, $y, $frame_key)); } /** * {@inheritdoc} * * @see ImageInterface::pickColors() */ public function pickColors(int $x, int $y): CollectionInterface { return $this->analyze(new PixelColorsAnalyzer($x, $y)); } /** * {@inheritdoc} * * @see ImageInterface::blendingColor() */ public function blendingColor(): ColorInterface { return $this->driver()->handleInput( $this->driver()->config()->blendingColor ); } /** * {@inheritdoc} * * @see ImageInterface::setBlendingColor() */ public function setBlendingColor(mixed $color): ImageInterface { $this->driver()->config()->setOptions( blendingColor: $this->driver()->handleInput($color) ); return $this; } /** * {@inheritdoc} * * @see ImageInterface::blendTransparency() */ public function blendTransparency(mixed $color = null): ImageInterface { return $this->modify(new BlendTransparencyModifier($color)); } /** * {@inheritdoc} * * @see ImageInterface::profile() */ public function profile(): ProfileInterface { return $this->analyze(new ProfileAnalyzer()); } /** * {@inheritdoc} * * @see ImageInterface::setProfile() */ public function setProfile(ProfileInterface $profile): ImageInterface { return $this->modify(new ProfileModifier($profile)); } /** * {@inheritdoc} * * @see ImageInterface::removeProfile() */ public function removeProfile(): ImageInterface { return $this->modify(new ProfileRemovalModifier()); } /** * {@inheritdoc} * * @see ImageInterface::reduceColors() */ public function reduceColors(int $limit, mixed $background = 'transparent'): ImageInterface { return $this->modify(new QuantizeColorsModifier($limit, $background)); } /** * {@inheritdoc} * * @see ImageInterface::sharpen() */ public function sharpen(int $amount = 10): ImageInterface { return $this->modify(new SharpenModifier($amount)); } /** * {@inheritdoc} * * @see ImageInterface::invert() */ public function invert(): ImageInterface { return $this->modify(new InvertModifier()); } /** * {@inheritdoc} * * @see ImageInterface::pixelate() */ public function pixelate(int $size): ImageInterface { return $this->modify(new PixelateModifier($size)); } /** * {@inheritdoc} * * @see ImageInterface::greyscale() */ public function greyscale(): ImageInterface { return $this->modify(new GreyscaleModifier()); } /** * {@inheritdoc} * * @see ImageInterface::brightness() */ public function brightness(int $level): ImageInterface { return $this->modify(new BrightnessModifier($level)); } /** * {@inheritdoc} * * @see ImageInterface::contrast() */ public function contrast(int $level): ImageInterface { return $this->modify(new ContrastModifier($level)); } /** * {@inheritdoc} * * @see ImageInterface::gamma() */ public function gamma(float $gamma): ImageInterface { return $this->modify(new GammaModifier($gamma)); } /** * {@inheritdoc} * * @see ImageInterface::colorize() */ public function colorize(int $red = 0, int $green = 0, int $blue = 0): ImageInterface { return $this->modify(new ColorizeModifier($red, $green, $blue)); } /** * {@inheritdoc} * * @see ImageInterface::flip() */ public function flip(): ImageInterface { return $this->modify(new FlipModifier()); } /** * {@inheritdoc} * * @see ImageInterface::flop() */ public function flop(): ImageInterface { return $this->modify(new FlopModifier()); } /** * {@inheritdoc} * * @see ImageInterface::blur() */ public function blur(int $amount = 5): ImageInterface { return $this->modify(new BlurModifier($amount)); } /** * {@inheritdoc} * * @see ImageInterface::rotate() */ public function rotate(float $angle, mixed $background = 'ffffff'): ImageInterface { return $this->modify(new RotateModifier($angle, $background)); } /** * {@inheritdoc} * * @see ImageInterface::orient() */ public function orient(): ImageInterface { return $this->modify(new AlignRotationModifier()); } /** * {@inheritdoc} * * @see ImageInterface::text() */ public function text(string $text, int $x, int $y, callable|Closure|FontInterface $font): ImageInterface { return $this->modify( new TextModifier( $text, new Point($x, $y), call_user_func(new FontFactory($font)), ), ); } /** * {@inheritdoc} * * @see ImageInterface::resize() */ public function resize(?int $width = null, ?int $height = null): ImageInterface { return $this->modify(new ResizeModifier($width, $height)); } /** * {@inheritdoc} * * @see ImageInterface::resizeDown() */ public function resizeDown(?int $width = null, ?int $height = null): ImageInterface { return $this->modify(new ResizeDownModifier($width, $height)); } /** * {@inheritdoc} * * @see ImageInterface::scale() */ public function scale(?int $width = null, ?int $height = null): ImageInterface { return $this->modify(new ScaleModifier($width, $height)); } /** * {@inheritdoc} * * @see ImageInterface::scaleDown() */ public function scaleDown(?int $width = null, ?int $height = null): ImageInterface { return $this->modify(new ScaleDownModifier($width, $height)); } /** * {@inheritdoc} * * @see ImageInterface::cover() */ public function cover(int $width, int $height, string $position = 'center'): ImageInterface { return $this->modify(new CoverModifier($width, $height, $position)); } /** * {@inheritdoc} * * @see ImageInterface::coverDown() */ public function coverDown(int $width, int $height, string $position = 'center'): ImageInterface { return $this->modify(new CoverDownModifier($width, $height, $position)); } /** * {@inheritdoc} * * @see ImageInterface::resizeCanvas() */ public function resizeCanvas( ?int $width = null, ?int $height = null, mixed $background = 'ffffff', string $position = 'center' ): ImageInterface { return $this->modify(new ResizeCanvasModifier($width, $height, $background, $position)); } /** * {@inheritdoc} * * @see ImageInterface::resizeCanvasRelative() */ public function resizeCanvasRelative( ?int $width = null, ?int $height = null, mixed $background = 'ffffff', string $position = 'center' ): ImageInterface { return $this->modify(new ResizeCanvasRelativeModifier($width, $height, $background, $position)); } /** * {@inheritdoc} * * @see ImageInterface::padDown() */ public function pad( int $width, int $height, mixed $background = 'ffffff', string $position = 'center' ): ImageInterface { return $this->modify(new PadModifier($width, $height, $background, $position)); } /** * {@inheritdoc} * * @see ImageInterface::pad() */ public function contain( int $width, int $height, mixed $background = 'ffffff', string $position = 'center' ): ImageInterface { return $this->modify(new ContainModifier($width, $height, $background, $position)); } /** * {@inheritdoc} * * @see ImageInterface::crop() */ public function crop( int $width, int $height, int $offset_x = 0, int $offset_y = 0, mixed $background = 'ffffff', string $position = 'top-left' ): ImageInterface { return $this->modify(new CropModifier($width, $height, $offset_x, $offset_y, $background, $position)); } /** * {@inheritdoc} * * @see ImageInterface::trim() */ public function trim(int $tolerance = 0): ImageInterface { return $this->modify(new TrimModifier($tolerance)); } /** * {@inheritdoc} * * @see ImageInterface::place() */ public function place( mixed $element, string $position = 'top-left', int $offset_x = 0, int $offset_y = 0, int $opacity = 100 ): ImageInterface { return $this->modify(new PlaceModifier($element, $position, $offset_x, $offset_y, $opacity)); } /** * {@inheritdoc} * * @see ImageInterface::fill() */ public function fill(mixed $color, ?int $x = null, ?int $y = null): ImageInterface { return $this->modify( new FillModifier( $color, is_null($x) || is_null($y) ? null : new Point($x, $y), ), ); } /** * {@inheritdoc} * * @see ImageInterface::drawPixel() */ public function drawPixel(int $x, int $y, mixed $color): ImageInterface { return $this->modify(new DrawPixelModifier(new Point($x, $y), $color)); } /** * {@inheritdoc} * * @see ImageInterface::drawRectangle() */ public function drawRectangle(int $x, int $y, callable|Closure|Rectangle $init): ImageInterface { return $this->modify( new DrawRectangleModifier( call_user_func(new RectangleFactory(new Point($x, $y), $init)), ), ); } /** * {@inheritdoc} * * @see ImageInterface::drawEllipse() */ public function drawEllipse(int $x, int $y, callable|Closure|Ellipse $init): ImageInterface { return $this->modify( new DrawEllipseModifier( call_user_func(new EllipseFactory(new Point($x, $y), $init)), ), ); } /** * {@inheritdoc} * * @see ImageInterface::drawCircle() */ public function drawCircle(int $x, int $y, callable|Closure|Circle $init): ImageInterface { return $this->modify( new DrawEllipseModifier( call_user_func(new CircleFactory(new Point($x, $y), $init)), ), ); } /** * {@inheritdoc} * * @see ImageInterface::drawPolygon() */ public function drawPolygon(callable|Closure|Polygon $init): ImageInterface { return $this->modify( new DrawPolygonModifier( call_user_func(new PolygonFactory($init)), ), ); } /** * {@inheritdoc} * * @see ImageInterface::drawLine() */ public function drawLine(callable|Closure|Line $init): ImageInterface { return $this->modify( new DrawLineModifier( call_user_func(new LineFactory($init)), ), ); } /** * {@inheritdoc} * * @see ImageInterface::drawBezier() */ public function drawBezier(callable|Closure|Bezier $init): ImageInterface { return $this->modify( new DrawBezierModifier( call_user_func(new BezierFactory($init)), ), ); } /** * {@inheritdoc} * * @see ImageInterface::encodeByMediaType() */ public function encodeByMediaType(null|string|MediaType $type = null, mixed ...$options): EncodedImageInterface { return $this->encode(new MediaTypeEncoder($type, ...$options)); } /** * {@inheritdoc} * * @see ImageInterface::encodeByExtension() */ public function encodeByExtension( null|string|FileExtension $extension = null, mixed ...$options ): EncodedImageInterface { return $this->encode(new FileExtensionEncoder($extension, ...$options)); } /** * {@inheritdoc} * * @see ImageInterface::encodeByPath() */ public function encodeByPath(?string $path = null, mixed ...$options): EncodedImageInterface { return $this->encode(new FilePathEncoder($path, ...$options)); } /** * {@inheritdoc} * * @see ImageInterface::toJpeg() */ public function toJpeg(mixed ...$options): EncodedImageInterface { return $this->encode(new JpegEncoder(...$options)); } /** * Alias of self::toJpeg() * * @throws RuntimeException */ public function toJpg(mixed ...$options): EncodedImageInterface { return $this->toJpeg(...$options); } /** * {@inheritdoc} * * @see ImageInterface::toJpeg() */ public function toJpeg2000(mixed ...$options): EncodedImageInterface { return $this->encode(new Jpeg2000Encoder(...$options)); } /** * ALias of self::toJpeg2000() * * @throws RuntimeException */ public function toJp2(mixed ...$options): EncodedImageInterface { return $this->toJpeg2000(...$options); } /** * {@inheritdoc} * * @see ImageInterface::toPng() */ public function toPng(mixed ...$options): EncodedImageInterface { return $this->encode(new PngEncoder(...$options)); } /** * {@inheritdoc} * * @see ImageInterface::toGif() */ public function toGif(mixed ...$options): EncodedImageInterface { return $this->encode(new GifEncoder(...$options)); } /** * {@inheritdoc} * * @see ImageInterface::toWebp() */ public function toWebp(mixed ...$options): EncodedImageInterface { return $this->encode(new WebpEncoder(...$options)); } /** * {@inheritdoc} * * @see ImageInterface::toBitmap() */ public function toBitmap(mixed ...$options): EncodedImageInterface { return $this->encode(new BmpEncoder(...$options)); } /** * Alias if self::toBitmap() * * @throws RuntimeException */ public function toBmp(mixed ...$options): EncodedImageInterface { return $this->toBitmap(...$options); } /** * {@inheritdoc} * * @see ImageInterface::toAvif() */ public function toAvif(mixed ...$options): EncodedImageInterface { return $this->encode(new AvifEncoder(...$options)); } /** * {@inheritdoc} * * @see ImageInterface::toTiff() */ public function toTiff(mixed ...$options): EncodedImageInterface { return $this->encode(new TiffEncoder(...$options)); } /** * Alias of self::toTiff() * * @throws RuntimeException */ public function toTif(mixed ...$options): EncodedImageInterface { return $this->toTiff(...$options); } /** * {@inheritdoc} * * @see ImageInterface::toHeic() */ public function toHeic(mixed ...$options): EncodedImageInterface { return $this->encode(new HeicEncoder(...$options)); } /** * Show debug info for the current image * * @return array<string, int> */ public function __debugInfo(): array { try { return [ 'width' => $this->width(), 'height' => $this->height(), ]; } catch (RuntimeException) { return []; } } /** * Clone image */ public function __clone(): void { $this->driver = clone $this->driver; $this->core = clone $this->core; $this->exif = clone $this->exif; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Origin.php
src/Origin.php
<?php declare(strict_types=1); namespace Intervention\Image; class Origin { /** * Create new origin instance * * @return void */ public function __construct( protected string $mediaType = 'application/octet-stream', protected ?string $filePath = null ) { // } /** * Return media type of origin */ public function mediaType(): string { return $this->mediaType; } /** * Alias of self::mediaType() */ public function mimetype(): string { return $this->mediaType(); } /** * Set media type of current instance */ public function setMediaType(string|MediaType $type): self { $this->mediaType = match (true) { is_string($type) => $type, default => $type->value, }; return $this; } /** * Return file path of origin */ public function filePath(): ?string { return $this->filePath; } /** * Set file path for origin */ public function setFilePath(string $path): self { $this->filePath = $path; return $this; } /** * Return file extension if origin was created from file path */ public function fileExtension(): ?string { return pathinfo($this->filePath ?: '', PATHINFO_EXTENSION) ?: null; } /** * Show debug info for the current image * * @return array<string, null|string> */ public function __debugInfo(): array { return [ 'mediaType' => $this->mediaType(), 'filePath' => $this->filePath(), ]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/ModifierStack.php
src/ModifierStack.php
<?php declare(strict_types=1); namespace Intervention\Image; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ModifierInterface; class ModifierStack implements ModifierInterface { /** * Create new modifier stack object with an array of modifier objects * * @param array<ModifierInterface> $modifiers * @return void */ public function __construct(protected array $modifiers) { // } /** * Apply all modifiers in stack to the given image */ public function apply(ImageInterface $image): ImageInterface { foreach ($this->modifiers as $modifier) { $modifier->apply($image); } return $image; } /** * Append new modifier to the stack */ public function push(ModifierInterface $modifier): self { $this->modifiers[] = $modifier; return $this; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/FileExtension.php
src/FileExtension.php
<?php declare(strict_types=1); namespace Intervention\Image; use Error; use Intervention\Image\Exceptions\NotSupportedException; enum FileExtension: string { case JPG = 'jpg'; case JPEG = 'jpeg'; case WEBP = 'webp'; case AVIF = 'avif'; case BMP = 'bmp'; case GIF = 'gif'; case PNG = 'png'; case TIF = 'tif'; case TIFF = 'tiff'; case JP2 = 'jp2'; case J2K = 'j2k'; case JP2K = 'jp2k'; case JPF = 'jpf'; case JPM = 'jpm'; case JPG2 = 'jpg2'; case J2C = 'j2c'; case JPC = 'jpc'; case JPX = 'jpx'; case HEIC = 'heic'; case HEIF = 'heif'; /** * Create file extension from given identifier * * @param string|Format|MediaType|FileExtension $identifier * @throws NotSupportedException */ public static function create(string|self|Format|MediaType $identifier): self { if ($identifier instanceof self) { return $identifier; } if ($identifier instanceof Format) { return $identifier->fileExtension(); } if ($identifier instanceof MediaType) { return $identifier->fileExtension(); } try { $extension = self::from(strtolower($identifier)); } catch (Error) { try { $extension = MediaType::from(strtolower($identifier))->fileExtension(); } catch (Error) { throw new NotSupportedException('Unable to create file extension from "' . $identifier . '".'); } } return $extension; } /** * Try to create media type from given identifier and return null on failure * * @param string|Format|MediaType|FileExtension $identifier * @return FileExtension|null */ public static function tryCreate(string|self|Format|MediaType $identifier): ?self { try { return self::create($identifier); } catch (NotSupportedException) { return null; } } /** * Return the matching format for the current file extension */ public function format(): Format { return match ($this) { self::JPEG, self::JPG => Format::JPEG, self::WEBP => Format::WEBP, self::GIF => Format::GIF, self::PNG => Format::PNG, self::AVIF => Format::AVIF, self::BMP => Format::BMP, self::TIF, self::TIFF => Format::TIFF, self::JP2, self::JP2K, self::J2K, self::JPF, self::JPM, self::JPG2, self::J2C, self::JPC, self::JPX => Format::JP2, self::HEIC, self::HEIF => Format::HEIC, }; } /** * Return media types for the current format * * @return array<MediaType> */ public function mediaTypes(): array { return $this->format()->mediaTypes(); } /** * Return the first found media type for the current format */ public function mediaType(): MediaType { return $this->format()->mediaType(); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Config.php
src/Config.php
<?php declare(strict_types=1); namespace Intervention\Image; use Intervention\Image\Exceptions\InputException; class Config { /** * Create config object instance * * @return void */ public function __construct( public bool $autoOrientation = true, public bool $decodeAnimation = true, public mixed $blendingColor = 'ffffff', public bool $strip = false, ) { // } /** * Set values of given config options * * @throws InputException */ public function setOptions(mixed ...$options): self { foreach ($this->prepareOptions($options) as $name => $value) { if (!property_exists($this, $name)) { throw new InputException('Property ' . $name . ' does not exists for ' . $this::class . '.'); } $this->{$name} = $value; } return $this; } /** * This method makes it possible to call self::setOptions() with a single * array instead of named parameters * * @param array<mixed> $options * @return array<string, mixed> */ private function prepareOptions(array $options): array { if ($options === []) { return $options; } if (count($options) > 1) { return $options; } if (!array_key_exists(0, $options)) { return $options; } if (!is_array($options[0])) { return $options; } return $options[0]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Format.php
src/Format.php
<?php declare(strict_types=1); namespace Intervention\Image; use Error; use Intervention\Image\Encoders\AvifEncoder; use Intervention\Image\Encoders\BmpEncoder; use Intervention\Image\Encoders\GifEncoder; use Intervention\Image\Encoders\HeicEncoder; use Intervention\Image\Encoders\Jpeg2000Encoder; use Intervention\Image\Encoders\JpegEncoder; use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Encoders\TiffEncoder; use Intervention\Image\Encoders\WebpEncoder; use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\Interfaces\EncoderInterface; use ReflectionClass; use ReflectionParameter; enum Format { case AVIF; case BMP; case GIF; case HEIC; case JP2; case JPEG; case PNG; case TIFF; case WEBP; /** * Create format from given identifier * * @param string|Format|MediaType|FileExtension $identifier * @throws NotSupportedException */ public static function create(string|self|MediaType|FileExtension $identifier): self { if ($identifier instanceof self) { return $identifier; } if ($identifier instanceof MediaType) { return $identifier->format(); } if ($identifier instanceof FileExtension) { return $identifier->format(); } try { $format = MediaType::from(strtolower($identifier))->format(); } catch (Error) { try { $format = FileExtension::from(strtolower($identifier))->format(); } catch (Error) { throw new NotSupportedException('Unable to create format from "' . $identifier . '".'); } } return $format; } /** * Try to create format from given identifier and return null on failure * * @param string|Format|MediaType|FileExtension $identifier * @return Format|null */ public static function tryCreate(string|self|MediaType|FileExtension $identifier): ?self { try { return self::create($identifier); } catch (NotSupportedException) { return null; } } /** * Return the possible media (MIME) types for the current format * * @return array<MediaType> */ public function mediaTypes(): array { return array_filter( MediaType::cases(), fn(MediaType $mediaType): bool => $mediaType->format() === $this ); } /** * Return the first found media type for the current format */ public function mediaType(): MediaType { $types = $this->mediaTypes(); return reset($types); } /** * Return the possible file extension for the current format * * @return array<FileExtension> */ public function fileExtensions(): array { return array_filter( FileExtension::cases(), fn(FileExtension $fileExtension): bool => $fileExtension->format() === $this ); } /** * Return the first found file extension for the current format */ public function fileExtension(): FileExtension { $extensions = $this->fileExtensions(); return reset($extensions); } /** * Create an encoder instance with given options that matches the format */ public function encoder(mixed ...$options): EncoderInterface { // get classname of target encoder from current format $classname = match ($this) { self::AVIF => AvifEncoder::class, self::BMP => BmpEncoder::class, self::GIF => GifEncoder::class, self::HEIC => HeicEncoder::class, self::JP2 => Jpeg2000Encoder::class, self::JPEG => JpegEncoder::class, self::PNG => PngEncoder::class, self::TIFF => TiffEncoder::class, self::WEBP => WebpEncoder::class, }; // get parameters of target encoder $parameters = []; $reflectionClass = new ReflectionClass($classname); if ($constructor = $reflectionClass->getConstructor()) { $parameters = array_map( fn(ReflectionParameter $parameter): string => $parameter->getName(), $constructor->getParameters(), ); } // filter out unavailable options of target encoder $options = array_filter( $options, fn(mixed $key): bool => in_array($key, $parameters), ARRAY_FILTER_USE_KEY, ); return new $classname(...$options); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/File.php
src/File.php
<?php declare(strict_types=1); namespace Intervention\Image; use Intervention\Image\Exceptions\NotWritableException; use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Interfaces\FileInterface; use Intervention\Image\Traits\CanBuildFilePointer; use Stringable; class File implements FileInterface, Stringable { use CanBuildFilePointer; /** * @var resource */ protected $pointer; /** * Create new instance * * @param string|resource|null $data * @throws RuntimeException */ public function __construct(mixed $data = null) { $this->pointer = $this->buildFilePointer($data); } /** * Create file object from path in file system * * @throws RuntimeException */ public static function fromPath(string $path): self { return new self(fopen($path, 'r')); } /** * {@inheritdoc} * * @see FileInterface::save() */ public function save(string $filepath): void { $dir = pathinfo($filepath, PATHINFO_DIRNAME); if (!is_dir($dir)) { throw new NotWritableException( "Can't write image to path. Directory does not exist." ); } if (!is_writable($dir)) { throw new NotWritableException( "Can't write image to path. Directory is not writable." ); } if (is_file($filepath) && !is_writable($filepath)) { throw new NotWritableException( sprintf("Can't write image. Path (%s) is not writable.", $filepath) ); } // write data $saved = @file_put_contents($filepath, $this->toFilePointer()); if ($saved === false) { throw new NotWritableException( sprintf("Can't write image data to path (%s).", $filepath) ); } } /** * {@inheritdoc} * * @see FileInterface::toString() */ public function toString(): string { return stream_get_contents($this->toFilePointer(), offset: 0); } /** * {@inheritdoc} * * @see FileInterface::toFilePointer() */ public function toFilePointer() { rewind($this->pointer); return $this->pointer; } /** * {@inheritdoc} * * @see FileInterface::size() */ public function size(): int { $info = fstat($this->toFilePointer()); return intval($info['size']); } /** * {@inheritdoc} * * @see FileInterface::__toString() */ public function __toString(): string { return $this->toString(); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/ImageManager.php
src/ImageManager.php
<?php declare(strict_types=1); namespace Intervention\Image; use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Drivers\Gd\Driver as GdDriver; use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; use Intervention\Image\Exceptions\DriverException; use Intervention\Image\Exceptions\InputException; use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\ImageManagerInterface; final class ImageManager implements ImageManagerInterface { private DriverInterface $driver; /** * @link https://image.intervention.io/v3/basics/configuration-drivers#create-a-new-image-manager-instance * * @throws DriverException * @throws InputException */ public function __construct(string|DriverInterface $driver, mixed ...$options) { $this->driver = $this->resolveDriver($driver, ...$options); } /** * Create image manager with given driver * * @link https://image.intervention.io/v3/basics/configuration-drivers#static-constructor * * @throws DriverException * @throws InputException */ public static function withDriver(string|DriverInterface $driver, mixed ...$options): self { return new self(self::resolveDriver($driver, ...$options)); } /** * Create image manager with GD driver * * @link https://image.intervention.io/v3/basics/configuration-drivers#static-gd-driver-constructor * * @throws DriverException * @throws InputException */ public static function gd(mixed ...$options): self { return self::withDriver(new GdDriver(), ...$options); } /** * Create image manager with Imagick driver * * @link https://image.intervention.io/v3/basics/configuration-drivers#static-imagick-driver-constructor * * @throws DriverException * @throws InputException */ public static function imagick(mixed ...$options): self { return self::withDriver(new ImagickDriver(), ...$options); } /** * {@inheritdoc} * * @see ImageManagerInterface::create() */ public function create(int $width, int $height): ImageInterface { return $this->driver->createImage($width, $height); } /** * {@inheritdoc} * * @see ImageManagerInterface::read() */ public function read(mixed $input, string|array|DecoderInterface $decoders = []): ImageInterface { return $this->driver->handleInput( $input, match (true) { is_string($decoders), is_a($decoders, DecoderInterface::class) => [$decoders], default => $decoders, } ); } /** * {@inheritdoc} * * @see ImageManagerInterface::animate() */ public function animate(callable $init): ImageInterface { return $this->driver->createAnimation($init); } /** * {@inheritdoc} * * @see ImageManagerInterface::driver() */ public function driver(): DriverInterface { return $this->driver; } /** * Return driver object from given input which might be driver classname or instance of DriverInterface * * @throws DriverException * @throws InputException */ private static function resolveDriver(string|DriverInterface $driver, mixed ...$options): DriverInterface { $driver = match (true) { $driver instanceof DriverInterface => $driver, class_exists($driver) => new $driver(), default => throw new DriverException( 'Unable to resolve driver. Argment must be either an instance of ' . DriverInterface::class . '::class or a qualified namespaced name of the driver class.', ), }; if (!$driver instanceof DriverInterface) { throw new DriverException( 'Unable to resolve driver. Driver object must implement ' . DriverInterface::class . '.', ); } $driver->config()->setOptions(...$options); return $driver; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Resolution.php
src/Resolution.php
<?php declare(strict_types=1); namespace Intervention\Image; use ArrayIterator; use Intervention\Image\Interfaces\ResolutionInterface; use IteratorAggregate; use Stringable; use Traversable; /** * @implements IteratorAggregate<float> */ class Resolution implements ResolutionInterface, Stringable, IteratorAggregate { public const PER_INCH = 1; public const PER_CM = 2; /** * Create new instance */ public function __construct( protected float $x, protected float $y, protected int $per_unit = self::PER_INCH ) { // } /** * {@inheritdoc} * * @see IteratorAggregate::getIterator() */ public function getIterator(): Traversable { return new ArrayIterator([$this->x, $this->y]); } /** * {@inheritdoc} * * @see ResolutionInterface::x() */ public function x(): float { return $this->x; } /** * {@inheritdoc} * * @see ResolutionInterface::setX() */ public function setX(float $x): self { $this->x = $x; return $this; } /** * {@inheritdoc} * * @see ResolutionInterface::y() */ public function y(): float { return $this->y; } /** * {@inheritdoc} * * @see ResolutionInterface::setY() */ public function setY(float $y): self { $this->y = $y; return $this; } /** * {@inheritdoc} * * @see ResolutionInterface::setPerUnit() */ protected function setPerUnit(int $per_unit): self { $this->per_unit = $per_unit; return $this; } /** * {@inheritdoc} * * @see ResolutionInterface::unit() */ public function unit(): string { return match ($this->per_unit) { self::PER_CM => 'dpcm', default => 'dpi', }; } /** * {@inheritdoc} * * @see ResolutionInterface::perInch() */ public function perInch(): self { return match ($this->per_unit) { self::PER_CM => $this ->setPerUnit(self::PER_INCH) ->setX($this->x * 2.54) ->setY($this->y * 2.54), default => $this }; } /** * {@inheritdoc} * * @see ResolutionInterface::perCm() */ public function perCm(): self { return match ($this->per_unit) { self::PER_INCH => $this ->setPerUnit(self::PER_CM) ->setX($this->x / 2.54) ->setY($this->y / 2.54), default => $this, }; } /** * {@inheritdoc} * * @see ResolutionInterface::toString() */ public function toString(): string { return sprintf("%1\$.2f x %2\$.2f %3\$s", $this->x, $this->y, $this->unit()); } /** * {@inheritdoc} * * @see ResolutionInterface::__toString() */ public function __toString(): string { return $this->toString(); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/InputException.php
src/Exceptions/InputException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class InputException extends RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/NotSupportedException.php
src/Exceptions/NotSupportedException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class NotSupportedException extends RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/ColorException.php
src/Exceptions/ColorException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class ColorException extends RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/AnimationException.php
src/Exceptions/AnimationException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class AnimationException extends RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/DecoderException.php
src/Exceptions/DecoderException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class DecoderException extends RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/FontException.php
src/Exceptions/FontException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class FontException extends RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/DriverException.php
src/Exceptions/DriverException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class DriverException extends RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/EncoderException.php
src/Exceptions/EncoderException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class EncoderException extends RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/GeometryException.php
src/Exceptions/GeometryException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class GeometryException extends RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/NotWritableException.php
src/Exceptions/NotWritableException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class NotWritableException extends RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Exceptions/RuntimeException.php
src/Exceptions/RuntimeException.php
<?php declare(strict_types=1); namespace Intervention\Image\Exceptions; class RuntimeException extends \RuntimeException { // }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/TiffEncoder.php
src/Encoders/TiffEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Drivers\SpecializableEncoder; class TiffEncoder extends SpecializableEncoder { /** * Create new encoder object * * @param null|bool $strip Strip EXIF metadata * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, public ?bool $strip = null ) { // } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/BmpEncoder.php
src/Encoders/BmpEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Drivers\SpecializableEncoder; class BmpEncoder extends SpecializableEncoder { public function __construct() { // } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/Jpeg2000Encoder.php
src/Encoders/Jpeg2000Encoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Drivers\SpecializableEncoder; class Jpeg2000Encoder extends SpecializableEncoder { /** * Create new encoder object * * @param null|bool $strip Strip EXIF metadata * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, public ?bool $strip = null ) { // } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/FileExtensionEncoder.php
src/Encoders/FileExtensionEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Error; use Intervention\Image\Exceptions\EncoderException; use Intervention\Image\FileExtension; use Intervention\Image\Interfaces\EncodedImageInterface; use Intervention\Image\Interfaces\EncoderInterface; use Intervention\Image\Interfaces\ImageInterface; class FileExtensionEncoder extends AutoEncoder { /** * Encoder options * * @var array<string, mixed> */ protected array $options = []; /** * Create new encoder instance to encode to format of given file extension * * @param null|string|FileExtension $extension Target file extension for example "png" * @return void */ public function __construct(public null|string|FileExtension $extension = null, mixed ...$options) { $this->options = $options; } /** * {@inheritdoc} * * @see EncoderInterface::encode() */ public function encode(ImageInterface $image): EncodedImageInterface { $extension = is_null($this->extension) ? $image->origin()->fileExtension() : $this->extension; return $image->encode( $this->encoderByFileExtension( $extension ) ); } /** * Create matching encoder for given file extension * * @throws EncoderException */ protected function encoderByFileExtension(null|string|FileExtension $extension): EncoderInterface { if (empty($extension)) { throw new EncoderException('No encoder found for empty file extension.'); } try { $extension = is_string($extension) ? FileExtension::from(strtolower($extension)) : $extension; } catch (Error) { throw new EncoderException('No encoder found for file extension (' . $extension . ').'); } return $extension->format()->encoder(...$this->options); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/AutoEncoder.php
src/Encoders/AutoEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Interfaces\EncodedImageInterface; use Intervention\Image\Interfaces\ImageInterface; class AutoEncoder extends MediaTypeEncoder { /** * {@inheritdoc} * * @see EncoderInterface::encode() */ public function encode(ImageInterface $image): EncodedImageInterface { return $image->encode( $this->encoderByMediaType( $image->origin()->mediaType() ) ); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/FilePathEncoder.php
src/Encoders/FilePathEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\EncodedImageInterface; class FilePathEncoder extends FileExtensionEncoder { /** * Create new encoder instance to encode to format of file extension in given path * * @return void */ public function __construct(protected ?string $path = null, mixed ...$options) { parent::__construct( is_null($path) ? $path : pathinfo($path, PATHINFO_EXTENSION), ...$options ); } /** * {@inheritdoc} * * @see EncoderInterface::encode() */ public function encode(ImageInterface $image): EncodedImageInterface { return $image->encode( $this->encoderByFileExtension( is_null($this->path) ? $image->origin()->fileExtension() : pathinfo($this->path, PATHINFO_EXTENSION) ) ); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/PngEncoder.php
src/Encoders/PngEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Drivers\SpecializableEncoder; class PngEncoder extends SpecializableEncoder { /** * Create new encoder object * * @return void */ public function __construct(public bool $interlaced = false, public bool $indexed = false) { // } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/JpegEncoder.php
src/Encoders/JpegEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Drivers\SpecializableEncoder; class JpegEncoder extends SpecializableEncoder { /** * Create new encoder object * * @param null|bool $strip Strip EXIF metadata * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, public bool $progressive = false, public ?bool $strip = null ) { // } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/AvifEncoder.php
src/Encoders/AvifEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Drivers\SpecializableEncoder; class AvifEncoder extends SpecializableEncoder { /** * Create new encoder object * * @param null|bool $strip Strip EXIF metadata * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, public ?bool $strip = null ) { // } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/GifEncoder.php
src/Encoders/GifEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Drivers\SpecializableEncoder; class GifEncoder extends SpecializableEncoder { /** * Create new encoder object * * @return void */ public function __construct(public bool $interlaced = false) { // } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/HeicEncoder.php
src/Encoders/HeicEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Drivers\SpecializableEncoder; class HeicEncoder extends SpecializableEncoder { /** * Create new encoder object * * @param null|bool $strip Strip EXIF metadata * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, public ?bool $strip = null ) { // } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/WebpEncoder.php
src/Encoders/WebpEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Intervention\Image\Drivers\SpecializableEncoder; class WebpEncoder extends SpecializableEncoder { /** * Create new encoder object * * @param null|bool $strip Strip EXIF metadata * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, public ?bool $strip = null ) { // } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Encoders/MediaTypeEncoder.php
src/Encoders/MediaTypeEncoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Encoders; use Error; use Intervention\Image\Drivers\AbstractEncoder; use Intervention\Image\Exceptions\EncoderException; use Intervention\Image\Interfaces\EncodedImageInterface; use Intervention\Image\Interfaces\EncoderInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\MediaType; class MediaTypeEncoder extends AbstractEncoder { /** * Encoder options * * @var array<string, mixed> */ protected array $options = []; /** * Create new encoder instance * * @param null|string|MediaType $mediaType Target media type for example "image/jpeg" * @return void */ public function __construct(public null|string|MediaType $mediaType = null, mixed ...$options) { $this->options = $options; } /** * {@inheritdoc} * * @see EncoderInterface::encode() */ public function encode(ImageInterface $image): EncodedImageInterface { $mediaType = is_null($this->mediaType) ? $image->origin()->mediaType() : $this->mediaType; return $image->encode( $this->encoderByMediaType($mediaType) ); } /** * Return new encoder by given media (MIME) type * * @throws EncoderException */ protected function encoderByMediaType(string|MediaType $mediaType): EncoderInterface { try { $mediaType = is_string($mediaType) ? MediaType::from($mediaType) : $mediaType; } catch (Error) { throw new EncoderException('No encoder found for media type (' . $mediaType . ').'); } return $mediaType->format()->encoder(...$this->options); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/AbstractColorChannel.php
src/Colors/AbstractColorChannel.php
<?php declare(strict_types=1); namespace Intervention\Image\Colors; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Interfaces\ColorChannelInterface; use Stringable; abstract class AbstractColorChannel implements ColorChannelInterface, Stringable { protected int $value; /** * {@inheritdoc} * * @see ColorChannelInterface::__construct() */ public function __construct(?int $value = null, ?float $normalized = null) { $this->value = $this->validate( match (true) { is_null($value) && is_numeric($normalized) => intval(round($normalized * $this->max())), is_numeric($value) && is_null($normalized) => $value, default => throw new ColorException('Color channels must either have a value or a normalized value') } ); } /** * Alias of value() */ public function toInt(): int { return $this->value; } /** * {@inheritdoc} * * @see ColorChannelInterface::value() */ public function value(): int { return $this->value; } /** * {@inheritdoc} * * @see ColorChannelInterface::normalize() */ public function normalize(int $precision = 32): float { return round(($this->value() - $this->min()) / ($this->max() - $this->min()), $precision); } /** * {@inheritdoc} * * @see ColorChannelInterface::validate() */ public function validate(mixed $value): mixed { if ($value < $this->min() || $value > $this->max()) { throw new ColorException('Color channel value must be in range ' . $this->min() . ' to ' . $this->max()); } return $value; } /** * {@inheritdoc} * * @see ColorChannelInterface::toString() */ public function toString(): string { return (string) $this->value(); } /** * {@inheritdoc} * * @see ColorChannelInterface::__toString() */ public function __toString(): string { return $this->toString(); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Profile.php
src/Colors/Profile.php
<?php declare(strict_types=1); namespace Intervention\Image\Colors; use Intervention\Image\File; use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Interfaces\ProfileInterface; class Profile extends File implements ProfileInterface { /** * Create profile object from path in file system * * @throws RuntimeException */ public static function fromPath(string $path): self { return new self(fopen($path, 'r')); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/AbstractColor.php
src/Colors/AbstractColor.php
<?php declare(strict_types=1); namespace Intervention\Image\Colors; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Interfaces\ColorChannelInterface; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; use ReflectionClass; use Stringable; abstract class AbstractColor implements ColorInterface, Stringable { /** * Color channels * * @var array<ColorChannelInterface> */ protected array $channels; /** * {@inheritdoc} * * @see ColorInterface::channels() */ public function channels(): array { return $this->channels; } /** * {@inheritdoc} * * @see ColorInterface::channel() */ public function channel(string $classname): ColorChannelInterface { $channels = array_filter( $this->channels(), fn(ColorChannelInterface $channel): bool => $channel::class === $classname, ); if (count($channels) == 0) { throw new ColorException('Color channel ' . $classname . ' could not be found.'); } return reset($channels); } /** * {@inheritdoc} * * @see ColorInterface::normalize() */ public function normalize(): array { return array_map( fn(ColorChannelInterface $channel): float => $channel->normalize(), $this->channels(), ); } /** * {@inheritdoc} * * @see ColorInterface::toArray() */ public function toArray(): array { return array_map( fn(ColorChannelInterface $channel): int => $channel->value(), $this->channels() ); } /** * {@inheritdoc} * * @see ColorInterface::convertTo() */ public function convertTo(string|ColorspaceInterface $colorspace): ColorInterface { $colorspace = match (true) { is_object($colorspace) => $colorspace, default => new $colorspace(), }; return $colorspace->importColor($this); } /** * Show debug info for the current color * * @return array<string, int> */ public function __debugInfo(): array { return array_reduce($this->channels(), function (array $result, ColorChannelInterface $item) { $key = strtolower((new ReflectionClass($item))->getShortName()); $result[$key] = $item->value(); return $result; }, []); } /** * {@inheritdoc} * * @see ColorInterface::__toString() */ public function __toString(): string { return $this->toString(); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsv/Colorspace.php
src/Colors/Hsv/Colorspace.php
<?php declare(strict_types=1); namespace Intervention\Image\Colors\Hsv; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Colors\Rgb\Color as RgbColor; 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; class Colorspace implements ColorspaceInterface { /** * Channel class names of colorspace * * @var array<string> */ public static array $channels = [ Channels\Hue::class, Channels\Saturation::class, Channels\Value::class ]; /** * {@inheritdoc} * * @see ColorspaceInterface::colorFromNormalized() */ public function colorFromNormalized(array $normalized): ColorInterface { return new Color(...array_map( fn(string $classname, float $value_normalized) => (new $classname(normalized: $value_normalized))->value(), self::$channels, $normalized )); } /** * @throws ColorException */ public function importColor(ColorInterface $color): ColorInterface { return match ($color::class) { CmykColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)), RgbColor::class => $this->importRgbColor($color), HslColor::class => $this->importHslColor($color), default => $color, }; } /** * @throws ColorException */ protected function importRgbColor(ColorInterface $color): ColorInterface { if (!($color instanceof RgbColor)) { throw new ColorException('Unabled to import color of type ' . $color::class . '.'); } // normalized values of rgb channels $values = array_map(fn(ColorChannelInterface $channel): float => $channel->normalize(), $color->channels()); // take only RGB $values = array_slice($values, 0, 3); // calculate chroma $min = min(...$values); $max = max(...$values); $chroma = $max - $min; // calculate value $v = 100 * $max; if ($chroma == 0) { // greyscale color return new Color(0, 0, intval(round($v))); } // calculate saturation $s = 100 * ($chroma / $max); // calculate hue [$r, $g, $b] = $values; $h = match (true) { ($r == $min) => 3 - (($g - $b) / $chroma), ($b == $min) => 1 - (($r - $g) / $chroma), default => 5 - (($b - $r) / $chroma), } * 60; return new Color( intval(round($h)), intval(round($s)), intval(round($v)) ); } /** * @throws ColorException */ protected function importHslColor(ColorInterface $color): ColorInterface { if (!($color instanceof HslColor)) { throw new ColorException('Unabled to import color of type ' . $color::class . '.'); } // normalized values of hsl channels [$h, $s, $l] = array_map( fn(ColorChannelInterface $channel): float => $channel->normalize(), $color->channels() ); $v = $l + $s * min($l, 1 - $l); $s = ($v == 0) ? 0 : 2 * (1 - $l / $v); return $this->colorFromNormalized([$h, $s, $v]); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsv/Color.php
src/Colors/Hsv/Color.php
<?php declare(strict_types=1); namespace Intervention\Image\Colors\Hsv; use Intervention\Image\Colors\AbstractColor; use Intervention\Image\Colors\Hsv\Channels\Hue; use Intervention\Image\Colors\Hsv\Channels\Saturation; use Intervention\Image\Colors\Hsv\Channels\Value; use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace; use Intervention\Image\InputHandler; use Intervention\Image\Interfaces\ColorChannelInterface; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; class Color extends AbstractColor { /** * Create new color object * * @return void */ public function __construct(int $h, int $s, int $v) { /** @throws void */ $this->channels = [ new Hue($h), new Saturation($s), new Value($v), ]; } /** * {@inheritdoc} * * @see ColorInterface::colorspace() */ public function colorspace(): ColorspaceInterface { return new Colorspace(); } /** * {@inheritdoc} * * @see ColorInterface::create() */ public static function create(mixed $input): ColorInterface { return InputHandler::withDecoders([ Decoders\StringColorDecoder::class, ])->handle($input); } /** * Return the Hue channel */ public function hue(): ColorChannelInterface { /** @throws void */ return $this->channel(Hue::class); } /** * Return the Saturation channel */ public function saturation(): ColorChannelInterface { /** @throws void */ return $this->channel(Saturation::class); } /** * Return the Value channel */ public function value(): ColorChannelInterface { /** @throws void */ return $this->channel(Value::class); } public function toHex(string $prefix = ''): string { return $this->convertTo(RgbColorspace::class)->toHex($prefix); } /** * {@inheritdoc} * * @see ColorInterface::toString() */ public function toString(): string { return sprintf( 'hsv(%d, %d%%, %d%%)', $this->hue()->value(), $this->saturation()->value(), $this->value()->value() ); } /** * {@inheritdoc} * * @see ColorInterface::isGreyscale() */ public function isGreyscale(): bool { return $this->saturation()->value() == 0; } /** * {@inheritdoc} * * @see ColorInterface::isTransparent() */ public function isTransparent(): bool { return false; } /** * {@inheritdoc} * * @see ColorInterface::isClear() */ public function isClear(): bool { return false; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsv/Channels/Value.php
src/Colors/Hsv/Channels/Value.php
<?php declare(strict_types=1); namespace Intervention\Image\Colors\Hsv\Channels; use Intervention\Image\Colors\AbstractColorChannel; class Value extends AbstractColorChannel { /** * {@inheritdoc} * * @see ColorChannelInterface::min() */ public function min(): int { return 0; } /** * {@inheritdoc} * * @see ColorChannelInterface::max() */ public function max(): int { return 100; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsv/Channels/Saturation.php
src/Colors/Hsv/Channels/Saturation.php
<?php declare(strict_types=1); namespace Intervention\Image\Colors\Hsv\Channels; use Intervention\Image\Colors\AbstractColorChannel; class Saturation extends AbstractColorChannel { /** * {@inheritdoc} * * @see ColorChannelInterface::min() */ public function min(): int { return 0; } /** * {@inheritdoc} * * @see ColorChannelInterface::max() */ public function max(): int { return 100; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsv/Channels/Hue.php
src/Colors/Hsv/Channels/Hue.php
<?php declare(strict_types=1); namespace Intervention\Image\Colors\Hsv\Channels; use Intervention\Image\Colors\AbstractColorChannel; class Hue extends AbstractColorChannel { /** * {@inheritdoc} * * @see ColorChannelInterface::min() */ public function min(): int { return 0; } /** * {@inheritdoc} * * @see ColorChannelInterface::max() */ public function max(): int { return 360; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsv/Decoders/StringColorDecoder.php
src/Colors/Hsv/Decoders/StringColorDecoder.php
<?php declare(strict_types=1); namespace Intervention\Image\Colors\Hsv\Decoders; use Intervention\Image\Colors\Hsv\Color; use Intervention\Image\Drivers\AbstractDecoder; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\ImageInterface; class StringColorDecoder extends AbstractDecoder implements DecoderInterface { /** * Decode hsv/hsb color strings */ public function decode(mixed $input): ImageInterface|ColorInterface { if (!is_string($input)) { throw new DecoderException('Unable to decode input'); } $pattern = '/^hs(v|b)\((?P<h>[0-9\.]+), ?(?P<s>[0-9\.]+%?), ?(?P<v>[0-9\.]+%?)\)$/i'; if (preg_match($pattern, $input, $matches) != 1) { throw new DecoderException('Unable to decode input'); } $values = array_map(function (string $value): int { return match (strpos($value, '%')) { false => intval(trim($value)), default => intval(trim(str_replace('%', '', $value))), }; }, [$matches['h'], $matches['s'], $matches['v']]); return new Color(...$values); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsl/Colorspace.php
src/Colors/Hsl/Colorspace.php
<?php declare(strict_types=1); namespace Intervention\Image\Colors\Hsl; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Colors\Rgb\Color as RgbColor; 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; class Colorspace implements ColorspaceInterface { /** * Channel class names of colorspace * * @var array<string> */ public static array $channels = [ Channels\Hue::class, Channels\Saturation::class, Channels\Luminance::class ]; /** * {@inheritdoc} * * @see ColorspaceInterface::colorFromNormalized() */ public function colorFromNormalized(array $normalized): ColorInterface { return new Color(...array_map( fn(string $classname, float $value_normalized) => (new $classname(normalized: $value_normalized))->value(), self::$channels, $normalized )); } /** * @throws ColorException */ public function importColor(ColorInterface $color): ColorInterface { return match ($color::class) { CmykColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)), RgbColor::class => $this->importRgbColor($color), HsvColor::class => $this->importHsvColor($color), default => $color, }; } /** * @throws ColorException */ protected function importRgbColor(ColorInterface $color): ColorInterface { if (!($color instanceof RgbColor)) { throw new ColorException('Unabled to import color of type ' . $color::class . '.'); } // normalized values of rgb channels $values = array_map( fn(ColorChannelInterface $channel): float => $channel->normalize(), $color->channels(), ); // take only RGB $values = array_slice($values, 0, 3); // calculate Luminance $min = min(...$values); $max = max(...$values); $luminance = ($max + $min) / 2; $delta = $max - $min; // calculate saturation $saturation = match (true) { $delta == 0 => 0, default => $delta / (1 - abs(2 * $luminance - 1)), }; // calculate hue [$r, $g, $b] = $values; $hue = match (true) { ($delta == 0) => 0, ($max == $r) => 60 * fmod((($g - $b) / $delta), 6), ($max == $g) => 60 * ((($b - $r) / $delta) + 2), ($max == $b) => 60 * ((($r - $g) / $delta) + 4), default => 0, }; $hue = ($hue + 360) % 360; // normalize hue return new Color( intval(round($hue)), intval(round($saturation * 100)), intval(round($luminance * 100)), ); } /** * @throws ColorException */ protected function importHsvColor(ColorInterface $color): ColorInterface { if (!($color instanceof HsvColor)) { throw new ColorException('Unabled to import color of type ' . $color::class . '.'); } // normalized values of hsv channels [$h, $s, $v] = array_map( fn(ColorChannelInterface $channel): float => $channel->normalize(), $color->channels(), ); // calculate Luminance $luminance = (2 - $s) * $v / 2; // calculate Saturation $saturation = match (true) { $luminance == 0 => $s, $luminance == 1 => 0, $luminance < .5 => $s * $v / ($luminance * 2), default => $s * $v / (2 - $luminance * 2), }; return new Color( intval(round($h * 360)), intval(round($saturation * 100)), intval(round($luminance * 100)), ); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false