-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
485076c
commit b8fb6fc
Showing
14 changed files
with
350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
includes: | ||
- ./vendor/larastan/larastan/extension.neon | ||
parameters: | ||
level: 9 | ||
paths: | ||
- types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Tree; | ||
|
||
use Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function test(Node $node): void | ||
{ | ||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->newQuery() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Graph\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasGraphRelationships; | ||
|
||
class Node extends Model | ||
{ | ||
use HasGraphRelationships; | ||
|
||
public function getPivotTableName(): string | ||
{ | ||
return 'edges'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Graph; | ||
|
||
use Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function test(Node $node): void | ||
{ | ||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->ancestors() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->ancestorsAndSelf() | ||
); | ||
|
||
assertType( | ||
'Illuminate\Database\Eloquent\Relations\BelongsToMany<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->children() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Descendants<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->childrenAndSelf() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Descendants<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->descendants() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Descendants<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->descendantsAndSelf() | ||
); | ||
|
||
assertType( | ||
'Illuminate\Database\Eloquent\Relations\BelongsToMany<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->parents() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->parentsAndSelf() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Graph; | ||
|
||
use Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function test(Node $node): void | ||
{ | ||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->ancestors()->subgraph(fn () => null) | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->ancestors()->whereDepth(3) | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->ancestors()->breadthFirst() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->ancestors()->depthFirst() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Graph\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Graph\Models\Node>', | ||
$node->ancestors()->whereDepth(3)->breadthFirst() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Tree; | ||
|
||
use Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function test(User $user): void | ||
{ | ||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->newQuery() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Tree\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Post extends Model | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Tree\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Role extends Model | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Tree\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Tag extends Model | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Tree\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships; | ||
|
||
class User extends Model | ||
{ | ||
use HasRecursiveRelationships; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Tree; | ||
|
||
use Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\Post; | ||
use Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\Role; | ||
use Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\Tag; | ||
use Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function test(User $user): void | ||
{ | ||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->ancestors() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->ancestorsAndSelf() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Bloodline<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->bloodline() | ||
); | ||
|
||
assertType( | ||
'Illuminate\Database\Eloquent\Relations\HasMany<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->children() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Descendants<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->childrenAndSelf() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Descendants<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->descendants() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Descendants<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->descendantsAndSelf() | ||
); | ||
|
||
assertType( | ||
'Illuminate\Database\Eloquent\Relations\BelongsTo<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User, Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->parent() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->parentAndSelf() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\RootAncestor<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->rootAncestor() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\RootAncestorOrSelf<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->rootAncestorOrSelf() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Siblings<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->siblings() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Siblings<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->siblingsAndSelf() | ||
); | ||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\BelongsToManyOfDescendants<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\Role>', | ||
$user->belongsToManyOfDescendants(Role::class) | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\BelongsToManyOfDescendants<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\Role>', | ||
$user->belongsToManyOfDescendantsAndSelf(Role::class) | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\Post>', | ||
$user->hasManyOfDescendantsAndSelf(Post::class) | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\Post>', | ||
$user->hasManyOfDescendantsAndSelf(Post::class) | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\Tag>', | ||
$user->morphToManyOfDescendants(Tag::class, 'taggable') | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\Tag>', | ||
$user->morphToManyOfDescendantsAndSelf(Tag::class, 'taggable') | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Types\Tree; | ||
|
||
use Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function test(User $user): void | ||
{ | ||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->tree() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->treeOf(fn () => null) | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->ancestors()->doesntHaveChildren() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->ancestors()->hasChildren() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->ancestors()->hasParent() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->ancestors()->isLeaf() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->ancestors()->isRoot() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->ancestors()->breadthFirst() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->ancestors()->depthFirst() | ||
); | ||
|
||
assertType( | ||
'Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<Staudenmeir\LaravelAdjacencyList\Types\Tree\Models\User>', | ||
$user->ancestors()->hasChildren()->breadthFirst() | ||
); | ||
} |