Skip to content

Commit 4bfeaf5

Browse files
committed
some annotations
1 parent 766b99e commit 4bfeaf5

File tree

7 files changed

+30
-22
lines changed

7 files changed

+30
-22
lines changed

src/Collection.php

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @phpstan-type NodeModel \Kalnoy\Nestedset\Contracts\Node<Tmodel>&Model
1414
*
1515
* @extends EloquentCollection<array-key,NodeModel>
16+
*
17+
* @implements NestedSetCollection<Tmodel>
1618
*/
1719
final class Collection extends EloquentCollection implements NestedSetCollection
1820
{

src/Contracts/NestedSetCollection.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
/**
66
* @template-covariant Tmodel of \Illuminate\Database\Eloquent\Model
77
*
8-
* @phpstan-type NodeModel Node<Tmodel>
8+
* @phpstan-type NodeModel Node<Tmodel>&Tmodel
99
*
1010
* @require-extends \Illuminate\Database\Eloquent\Collection
1111
*
12-
* @method NestedSetCollection groupBy(string $column)
13-
* @method array<int,NodeModel> all()
12+
* @method NestedSetCollection<NodeModel> groupBy(string $column)
13+
* @method array<int,NodeModel> all()
1414
*/
1515
interface NestedSetCollection
1616
{
@@ -19,7 +19,7 @@ interface NestedSetCollection
1919
*
2020
* This will overwrite any previously set relations.
2121
*
22-
* @return $this
22+
* @return NestedSetCollection<Tmodel>
2323
*/
2424
public function linkNodes();
2525

src/Contracts/Node.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
*
2828
* @require-extends \Illuminate\Database\Eloquent\Model
2929
*
30-
* @method mixed getKey()
31-
* @method mixed getKeyName()
32-
* @method Node setRelation($relation, $value)
33-
* @method mixed save()
34-
* @method string getTable()
35-
* @method mixed getAttribute($key)
36-
* @method string getDeletedAtColumn()
37-
* @method Node getRelationValue($key)
38-
* @method bool usesSoftDelete()
30+
* @method mixed getKey()
31+
* @method mixed getKeyName()
32+
* @method Node<Tmodel> setRelation($relation, $value)
33+
* @method mixed save()
34+
* @method string getTable()
35+
* @method mixed getAttribute($key)
36+
* @method string getDeletedAtColumn()
37+
* @method Node<Tmodel> getRelationValue($key)
38+
* @method bool usesSoftDelete()
3939
*/
4040
interface Node
4141
{

src/QueryBuilder.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ public function orWhereNodeBetween(array $values): NodeQueryBuilder
215215
* @since 2.0
216216
*
217217
* @param ?Node<Tmodel> $id
218-
* @param string $boolean
219-
* @param bool $not
220-
* @param bool $andSelf
218+
* @param string $boolean
219+
* @param bool $not
220+
* @param bool $andSelf
221221
*
222222
* @return QueryBuilder<Tmodel>
223223
*/
@@ -271,8 +271,8 @@ public function orWhereNotDescendantOf(mixed $id): NodeQueryBuilder
271271

272272
/**
273273
* @param Node<Tmodel> $id
274-
* @param string $boolean
275-
* @param bool $not
274+
* @param string $boolean
275+
* @param bool $not
276276
*
277277
* @return QueryBuilder<Tmodel>
278278
*/
@@ -868,7 +868,7 @@ public function fixTree($root = null): int
868868

869869
$dictionary = $this->model
870870
->newNestedSetQuery()
871-
->when($root !== null, function (self $query) use ($root) {
871+
->when($root !== null, function (self $query) use ($root) {
872872
return $query->whereDescendantOf($root);
873873
})
874874
->defaultOrder()

tests/models/Category.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
class Category extends Model implements Node
1212
{
1313
use SoftDeletes;
14+
/** @use NodeTrait<Category,int> */
1415
use NodeTrait;
1516

1617
protected $fillable = ['name', 'parent_id'];
1718

1819
public $timestamps = false;
1920

20-
public static function resetActionsPerformed()
21+
public static function resetActionsPerformed(): void
2122
{
2223
static::$actionsPerformed = 0;
2324
}

tests/models/DuplicateCategory.php

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
class DuplicateCategory extends Model implements Node
1111
{
12+
/** @use NodeTrait<DuplicateCategory,int> */
1213
use NodeTrait;
1314

1415
protected $table = 'categories';

tests/models/MenuItem.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@
99
*/
1010
class MenuItem extends Model implements Node
1111
{
12+
/** @use NodeTrait<MenuItem,int> */
1213
use NodeTrait;
1314

1415
public $timestamps = false;
1516

1617
protected $fillable = ['menu_id', 'parent_id'];
1718

18-
public static function resetActionsPerformed()
19+
public static function resetActionsPerformed(): void
1920
{
2021
static::$actionsPerformed = 0;
2122
}
2223

23-
protected function getScopeAttributes()
24+
/**
25+
* @return list<string>
26+
*/
27+
protected function getScopeAttributes(): array
2428
{
2529
return ['menu_id'];
2630
}

0 commit comments

Comments
 (0)