Allow casts with a return type of static or this to reference themselves (#1103)

* Allow casts with a return type of static or this to reference themselves

Supports

```php
/**
     * @param $model
     * @param string $key
     * @param $value
     * @param array $attributes
     * @return static
     */
    public function get($model, string $key, $value, array $attributes)
    {
        return new static($value);
    }
```

or

```php
/**
     * @param $model
     * @param string $key
     * @param $value
     * @param array $attributes
     * @return $this
     */
    public function get($model, string $key, $value, array $attributes)
    {
        return new static($value);
    }
```

* Update CHANGELOG.md
This commit is contained in:
Matthew Hailwood
2020-12-04 07:33:45 +01:00
committed by GitHub
parent b4138e5122
commit b3a79fe6c1
9 changed files with 118 additions and 4 deletions
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
class ExtendedSelfCastingCasterWithStaticDocblockReturn extends SelfCastingCasterWithStaticDocblockReturn
{
}
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
class ExtendedSelfCastingCasterWithThisDocblockReturn extends SelfCastingCasterWithStaticDocblockReturn
{
}
@@ -0,0 +1,26 @@
<?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.
}
}
@@ -0,0 +1,26 @@
<?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.
}
}