Skip to content

Commit 3b75048

Browse files
authored
Support variadic parameters in models command (#1234)
1 parent b162347 commit 3b75048

File tree

6 files changed

+82
-1
lines changed

6 files changed

+82
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ All notable changes to this project will be documented in this file.
1010
### Fixed
1111
- Use platformName to determine db type when casting boolean types [\#1212 / stockalexander](https://github.com/barryvdh/laravel-ide-helper/pull/1212)
1212

13+
### Added
14+
- Add support of variadic parameters in `ide-helper:models` [\#1234 / shaffe-fr](https://github.com/barryvdh/laravel-ide-helper/pull/1234)
15+
1316
2021-04-09, 2.10.0
1417
------------------
1518
### Added

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ php artisan ide-helper:models "App\Models\Post"
166166
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post newQuery()
167167
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post query()
168168
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post whereTitle($value)
169+
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post forAuthors(\User ...$authors)
169170
* …
170171
*/
171172
```

src/Console/ModelsCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,8 @@ public function getParameters($method)
935935
$paramsWithDefault = [];
936936
/** @var \ReflectionParameter $param */
937937
foreach ($method->getParameters() as $param) {
938-
$paramStr = '$' . $param->getName();
938+
$paramStr = $param->isVariadic() ? '...$' . $param->getName() : '$' . $param->getName();
939+
939940
if ($paramType = $this->getParamType($method, $param)) {
940941
$paramStr = $paramType . ' ' . $paramStr;
941942
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Variadic\Models;
6+
7+
use DateTime;
8+
use Illuminate\Database\Eloquent\Builder;
9+
use Illuminate\Database\Eloquent\Model;
10+
11+
class Simple extends Model
12+
{
13+
public function scopeWhereVariadic(Builder $query, ...$values): void
14+
{
15+
}
16+
17+
public function scopeWhereTypedVariadic(Builder $query, int ...$values): void
18+
{
19+
}
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Variadic;
6+
7+
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
8+
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
9+
10+
class Test extends AbstractModelsCommand
11+
{
12+
public function test(): void
13+
{
14+
$command = $this->app->make(ModelsCommand::class);
15+
16+
$tester = $this->runCommand($command, [
17+
'--write' => true,
18+
]);
19+
20+
$this->assertSame(0, $tester->getStatusCode());
21+
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
22+
$this->assertMatchesMockedSnapshot();
23+
}
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Variadic\Models;
6+
7+
use DateTime;
8+
use Illuminate\Database\Eloquent\Builder;
9+
use Illuminate\Database\Eloquent\Model;
10+
11+
/**
12+
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Variadic\Models\Simple
13+
*
14+
* @property integer $id
15+
* @method static Builder|Simple newModelQuery()
16+
* @method static Builder|Simple newQuery()
17+
* @method static Builder|Simple query()
18+
* @method static Builder|Simple whereId($value)
19+
* @method static Builder|Simple whereTypedVariadic(int ...$values)
20+
* @method static Builder|Simple whereVariadic(...$values)
21+
* @mixin \Eloquent
22+
*/
23+
class Simple extends Model
24+
{
25+
public function scopeWhereVariadic(Builder $query, ...$values): void
26+
{
27+
}
28+
29+
public function scopeWhereTypedVariadic(Builder $query, int ...$values): void
30+
{
31+
}
32+
}

0 commit comments

Comments
 (0)