From cb49a1f21552d9f941b738cab9413eb01c5ab1c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Gaulin?= Date: Tue, 25 Jan 2022 13:06:39 +0400 Subject: [PATCH] Add unsetProperty to in hooks to ignore some properties --- README.md | 1 + src/Console/ModelsCommand.php | 9 ++++++++- .../Attributes/__snapshots__/Test__test__1.php | 2 ++ .../Comment/__snapshots__/Test__test__1.php | 2 ++ .../__snapshots__/Test__test__1.php | 2 ++ .../Getter/__snapshots__/Test__test__1.php | 2 ++ .../ModelHooks/Hooks/UnsetProperty.php | 17 +++++++++++++++++ tests/Console/ModelsCommand/ModelHooks/Test.php | 2 ++ .../Test__testNoinspectionNotPresent__1.php | 2 ++ .../Test__testNoinspectionPresent__1.php | 2 ++ .../Relations/__snapshots__/Test__test__1.php | 2 ++ .../__snapshots__/Test__testNoReset__1.php | 2 ++ .../__snapshots__/Test__testReset__1.php | 2 ++ .../__snapshots__/Test__testSmartReset__1.php | 2 ++ .../SoftDeletes/__snapshots__/Test__test__1.php | 2 ++ .../Variadic/__snapshots__/Test__test__1.php | 2 ++ .../migrations/____simple_table.php | 1 + 17 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/Console/ModelsCommand/ModelHooks/Hooks/UnsetProperty.php diff --git a/README.md b/README.md index 866e05055..5dfe225a4 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,7 @@ class MyCustomHook implements ModelHookInterface return; } + $command->unsetProperty('hash'); $command->setProperty('custom', 'string', true, false, 'My custom property'); $command->unsetMethod('method'); $command->setMethod('method', $command->getMethodType($model, '\Some\Class'), ['$param']); diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 92f7ebd36..c4da0c17f 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -816,6 +816,13 @@ public function setProperty($name, $type = null, $read = null, $write = null, $c } } + public function unsetProperty($name) + { + unset($this->properties[$name]); + + $this->unsetMethod(Str::camel('where_' . $name)); + } + public function setMethod($name, $type = '', $arguments = [], $comment = '') { $methods = array_change_key_case($this->methods, CASE_LOWER); @@ -830,7 +837,7 @@ public function setMethod($name, $type = '', $arguments = [], $comment = '') public function unsetMethod($name) { - unset($this->methods[strtolower($name)]); + unset($this->methods[$name]); } public function getMethodType(Model $model, string $classType) diff --git a/tests/Console/ModelsCommand/Attributes/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Attributes/__snapshots__/Test__test__1.php index eabeffcbb..a80a2936d 100644 --- a/tests/Console/ModelsCommand/Attributes/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/Attributes/__snapshots__/Test__test__1.php @@ -11,11 +11,13 @@ * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Attributes\Models\Simple * * @property integer $id + * @property string $unset * @property string|null $name * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @mixin \Eloquent */ class Simple extends Model diff --git a/tests/Console/ModelsCommand/Comment/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Comment/__snapshots__/Test__test__1.php index 4f530e299..161b06a22 100644 --- a/tests/Console/ModelsCommand/Comment/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/Comment/__snapshots__/Test__test__1.php @@ -13,6 +13,7 @@ * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Comment\Models\Simple * * @property integer $id + * @property string $unset * @property string $both_same_name I'm a getter * @property string $both_without_getter_comment * @property-read string $faker_comment @@ -31,6 +32,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @mixin \Eloquent */ class Simple extends Model diff --git a/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php index 10818ac0a..20c1fefe1 100644 --- a/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php @@ -12,6 +12,7 @@ * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models\Simple * * @property integer $id + * @property string $unset * @property-read SimpleCollection|Simple[] $relationHasMany * @property-read int|null $relation_has_many_count * @method static SimpleCollection|static[] all($columns = ['*']) @@ -20,6 +21,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @mixin \Eloquent */ class Simple extends Model diff --git a/tests/Console/ModelsCommand/Getter/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Getter/__snapshots__/Test__test__1.php index ab67d5444..e64f359ae 100644 --- a/tests/Console/ModelsCommand/Getter/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/Getter/__snapshots__/Test__test__1.php @@ -11,6 +11,7 @@ * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter\Models\Simple * * @property integer $id + * @property string $unset * @property-read int|null $attribute_return_type_int_or_null * @property-read array $attribute_returns_array * @property-read bool $attribute_returns_bool @@ -35,6 +36,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @mixin \Eloquent */ class Simple extends Model diff --git a/tests/Console/ModelsCommand/ModelHooks/Hooks/UnsetProperty.php b/tests/Console/ModelsCommand/ModelHooks/Hooks/UnsetProperty.php new file mode 100644 index 000000000..83a9a45f8 --- /dev/null +++ b/tests/Console/ModelsCommand/ModelHooks/Hooks/UnsetProperty.php @@ -0,0 +1,17 @@ +unsetProperty('unset'); + } +} diff --git a/tests/Console/ModelsCommand/ModelHooks/Test.php b/tests/Console/ModelsCommand/ModelHooks/Test.php index 05ffea2ce..847563d29 100644 --- a/tests/Console/ModelsCommand/ModelHooks/Test.php +++ b/tests/Console/ModelsCommand/ModelHooks/Test.php @@ -9,6 +9,7 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks\CustomMethod; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks\CustomProperty; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks\UnsetMethod; +use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks\UnsetProperty; use Illuminate\Filesystem\Filesystem; use Mockery; @@ -28,6 +29,7 @@ protected function getEnvironmentSetUp($app) CustomProperty::class, CustomMethod::class, UnsetMethod::class, + UnsetProperty::class, ], ]); } diff --git a/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php b/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php index 25c0e3b6d..cbedddca4 100644 --- a/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php +++ b/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php @@ -10,10 +10,12 @@ * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple * * @property integer $id + * @property string $unset * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @mixin \Eloquent */ class Simple extends Model diff --git a/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionPresent__1.php b/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionPresent__1.php index 9cb1f276a..0543990ad 100644 --- a/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionPresent__1.php +++ b/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionPresent__1.php @@ -10,10 +10,12 @@ * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple * * @property integer $id + * @property string $unset * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @mixin \Eloquent * @noinspection PhpFullyQualifiedNameUsageInspection * @noinspection PhpUnnecessaryFullyQualifiedNameInspection diff --git a/tests/Console/ModelsCommand/Relations/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Relations/__snapshots__/Test__test__1.php index 445901d9d..8b20af4cc 100644 --- a/tests/Console/ModelsCommand/Relations/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/Relations/__snapshots__/Test__test__1.php @@ -73,6 +73,7 @@ public function nullableColumnWithNoForeignKeyConstraint(): BelongsTo * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple * * @property integer $id + * @property string $unset * @property-read Simple|null $relationBelongsTo * @property-read AnotherModel|null $relationBelongsToInAnotherNamespace * @property-read \Illuminate\Database\Eloquent\Collection|Simple[] $relationBelongsToMany @@ -99,6 +100,7 @@ public function nullableColumnWithNoForeignKeyConstraint(): BelongsTo * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @mixin \Eloquent */ class Simple extends Model diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php index 6e5b18017..b9b6e730d 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php @@ -11,10 +11,12 @@ * * @property string $foo * @property integer $id + * @property string $unset * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @mixin \Eloquent */ class Simple extends Model diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php index 08f1d063c..9e534b9a6 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php @@ -10,10 +10,12 @@ * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple * * @property integer $id + * @property string $unset * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @mixin \Eloquent */ class Simple extends Model diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testSmartReset__1.php b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testSmartReset__1.php index 3ba9c2b3d..fbaac0e91 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testSmartReset__1.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testSmartReset__1.php @@ -10,10 +10,12 @@ * Text of existing phpdoc * * @property integer $id + * @property string $unset * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @mixin \Eloquent */ class Simple extends Model diff --git a/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php index 167fa0ccf..1abd6cfc5 100644 --- a/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php @@ -11,11 +11,13 @@ * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models\Simple * * @property integer $id + * @property string $unset * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Query\Builder|Simple onlyTrashed() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereUnset($value) * @method static \Illuminate\Database\Query\Builder|Simple withTrashed() * @method static \Illuminate\Database\Query\Builder|Simple withoutTrashed() * @mixin \Eloquent diff --git a/tests/Console/ModelsCommand/Variadic/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Variadic/__snapshots__/Test__test__1.php index dd1a3d3d7..f2bcc1a86 100644 --- a/tests/Console/ModelsCommand/Variadic/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/Variadic/__snapshots__/Test__test__1.php @@ -11,11 +11,13 @@ * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Variadic\Models\Simple * * @property integer $id + * @property string $unset * @method static Builder|Simple newModelQuery() * @method static Builder|Simple newQuery() * @method static Builder|Simple query() * @method static Builder|Simple whereId($value) * @method static Builder|Simple whereTypedVariadic(int ...$values) + * @method static Builder|Simple whereUnset($value) * @method static Builder|Simple whereVariadic(...$values) * @mixin \Eloquent */ diff --git a/tests/Console/ModelsCommand/migrations/____simple_table.php b/tests/Console/ModelsCommand/migrations/____simple_table.php index 4547d3abb..008917918 100644 --- a/tests/Console/ModelsCommand/migrations/____simple_table.php +++ b/tests/Console/ModelsCommand/migrations/____simple_table.php @@ -12,6 +12,7 @@ public function up(): void { Schema::create('simples', function (Blueprint $table) { $table->bigIncrements('id'); + $table->string('unset'); }); } }