Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
some annotations
  • Loading branch information
ildyria committed Mar 25, 2025
commit 4bfeaf59ea36112c4deeb767cde1b3021522effe
2 changes: 2 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* @phpstan-type NodeModel \Kalnoy\Nestedset\Contracts\Node<Tmodel>&Model
*
* @extends EloquentCollection<array-key,NodeModel>
*
* @implements NestedSetCollection<Tmodel>
*/
final class Collection extends EloquentCollection implements NestedSetCollection
{
Expand Down
8 changes: 4 additions & 4 deletions src/Contracts/NestedSetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
/**
* @template-covariant Tmodel of \Illuminate\Database\Eloquent\Model
*
* @phpstan-type NodeModel Node<Tmodel>
* @phpstan-type NodeModel Node<Tmodel>&Tmodel
*
* @require-extends \Illuminate\Database\Eloquent\Collection
*
* @method NestedSetCollection groupBy(string $column)
* @method array<int,NodeModel> all()
* @method NestedSetCollection<NodeModel> groupBy(string $column)
* @method array<int,NodeModel> all()
*/
interface NestedSetCollection
{
Expand All @@ -19,7 +19,7 @@ interface NestedSetCollection
*
* This will overwrite any previously set relations.
*
* @return $this
* @return NestedSetCollection<Tmodel>
*/
public function linkNodes();

Expand Down
18 changes: 9 additions & 9 deletions src/Contracts/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
*
* @require-extends \Illuminate\Database\Eloquent\Model
*
* @method mixed getKey()
* @method mixed getKeyName()
* @method Node setRelation($relation, $value)
* @method mixed save()
* @method string getTable()
* @method mixed getAttribute($key)
* @method string getDeletedAtColumn()
* @method Node getRelationValue($key)
* @method bool usesSoftDelete()
* @method mixed getKey()
* @method mixed getKeyName()
* @method Node<Tmodel> setRelation($relation, $value)
* @method mixed save()
* @method string getTable()
* @method mixed getAttribute($key)
* @method string getDeletedAtColumn()
* @method Node<Tmodel> getRelationValue($key)
* @method bool usesSoftDelete()
*/
interface Node
{
Expand Down
12 changes: 6 additions & 6 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ public function orWhereNodeBetween(array $values): NodeQueryBuilder
* @since 2.0
*
* @param ?Node<Tmodel> $id
* @param string $boolean
* @param bool $not
* @param bool $andSelf
* @param string $boolean
* @param bool $not
* @param bool $andSelf
*
* @return QueryBuilder<Tmodel>
*/
Expand Down Expand Up @@ -271,8 +271,8 @@ public function orWhereNotDescendantOf(mixed $id): NodeQueryBuilder

/**
* @param Node<Tmodel> $id
* @param string $boolean
* @param bool $not
* @param string $boolean
* @param bool $not
*
* @return QueryBuilder<Tmodel>
*/
Expand Down Expand Up @@ -868,7 +868,7 @@ public function fixTree($root = null): int

$dictionary = $this->model
->newNestedSetQuery()
->when($root !== null, function (self $query) use ($root) {
->when($root !== null, function (self $query) use ($root) {
return $query->whereDescendantOf($root);
})
->defaultOrder()
Expand Down
3 changes: 2 additions & 1 deletion tests/models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
class Category extends Model implements Node
{
use SoftDeletes;
/** @use NodeTrait<Category,int> */
use NodeTrait;

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

public $timestamps = false;

public static function resetActionsPerformed()
public static function resetActionsPerformed(): void
{
static::$actionsPerformed = 0;
}
Expand Down
1 change: 1 addition & 0 deletions tests/models/DuplicateCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
class DuplicateCategory extends Model implements Node
{
/** @use NodeTrait<DuplicateCategory,int> */
use NodeTrait;

protected $table = 'categories';
Expand Down
8 changes: 6 additions & 2 deletions tests/models/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
*/
class MenuItem extends Model implements Node
{
/** @use NodeTrait<MenuItem,int> */
use NodeTrait;

public $timestamps = false;

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

public static function resetActionsPerformed()
public static function resetActionsPerformed(): void
{
static::$actionsPerformed = 0;
}

protected function getScopeAttributes()
/**
* @return list<string>
*/
protected function getScopeAttributes(): array
{
return ['menu_id'];
}
Expand Down