Skip to content

Commit

Permalink
Fix phpdoc generate for custom cast with parameter (#986)
Browse files Browse the repository at this point in the history
* Fix phpdoc generate for custom cast with parameter

* Add param for cast

* Simplify cast class name normalizing

Co-authored-by: Markus Podar <[email protected]>

* Update changelog

* composer fix-style

Co-authored-by: Markus Podar <[email protected]>
  • Loading branch information
fatihdirikman and mfn committed Sep 7, 2020
1 parent 89a1cb9 commit abd42e7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
[Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.8.1...master)
--------------

### Added
- Fix phpdoc generate for custom cast with parameter [\#986 / artelkr](https://github.com/barryvdh/laravel-ide-helper/pull/986)

2020-09-07, 2.8.1
-----------------
### Added
Expand Down
3 changes: 3 additions & 0 deletions src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ protected function castPropertiesType($model)
$realType = '\Illuminate\Support\Collection';
break;
default:
// In case of an optional custom cast parameter , only evaluate
// the `$type` until the `:`
$type = strtok($type, ':');
$realType = class_exists($type) ? ('\\' . $type) : 'mixed';
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand All @@ -23,5 +24,6 @@ class CustomCast extends Model
'casted_property_with_return_primitive_docblock' => CustomCasterWithPrimitiveDocblockReturn::class,
'casted_property_with_return_nullable_primitive' => CustomCasterWithNullablePrimitiveReturn::class,
'casted_property_without_return' => CustomCasterWithoutReturnType::class,
'casted_property_with_param' => CustomCasterWithParam::class . ':param',
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand All @@ -23,9 +24,11 @@
* @property array|null $casted_property_with_return_primitive_docblock
* @property array|null $casted_property_with_return_nullable_primitive
* @property $casted_property_without_return
* @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_param
* @method static \Illuminate\Database\Eloquent\Builder|CustomCast newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|CustomCast newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|CustomCast query()
* @method static \Illuminate\Database\Eloquent\Builder|CustomCast whereCastedPropertyWithParam($value)
* @method static \Illuminate\Database\Eloquent\Builder|CustomCast whereCastedPropertyWithReturnDocblock($value)
* @method static \Illuminate\Database\Eloquent\Builder|CustomCast whereCastedPropertyWithReturnDocblockFqn($value)
* @method static \Illuminate\Database\Eloquent\Builder|CustomCast whereCastedPropertyWithReturnNullablePrimitive($value)
Expand All @@ -45,5 +48,6 @@ class CustomCast extends Model
'casted_property_with_return_primitive_docblock' => CustomCasterWithPrimitiveDocblockReturn::class,
'casted_property_with_return_nullable_primitive' => CustomCasterWithNullablePrimitiveReturn::class,
'casted_property_without_return' => CustomCasterWithoutReturnType::class,
'casted_property_with_param' => CustomCasterWithParam::class . ':param',
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function up(): void
$table->string('casted_property_with_return_primitive_docblock');
$table->string('casted_property_with_return_nullable_primitive');
$table->string('casted_property_without_return');
$table->string('casted_property_with_param');
});
}
}

0 comments on commit abd42e7

Please sign in to comment.