-
-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Class Was Not found" For Intersection Type #2057
Comments
Can you please share the code that causes the crash? |
I'm having trouble isolating exactly what is causing the crash. Here are the interface and the trait; I've removed the bodies of longer functions for brevity. <?php
namespace Domain\Shared\Models;
use Domain\Shared\Collections\TreeLikeCollection;
use Domain\Shared\Collections\TreeLikeCollectionInterface;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\App;
/**
* @see HierarchicalModelInterface
*
* @phpstan-import-type ParentId from HierarchicalModelInterface
*/
trait HierarchicalModelTrait
{
public function getParentKeyName(): int|string|null
{
return 'parent_id';
}
public function newCollection(array $models = []): TreeLikeCollectionInterface
{
return App::makeWith(TreeLikeCollection::class, ['items' => $models]);
}
public function parent(): BelongsTo
{
return $this->belongsTo(static::class, $this->getParentKeyName());
}
public function children(): HasMany
{
return $this->hasMany(static::class, $this->getParentKeyName());
}
/**
* Recursively retrieve all children of this instance.
*/
public function getDescendants(): Collection & TreeLikeCollectionInterface
{
}
/**
* Recursively retrieve all parents of this instance.
*/
public function getAncestors(): Collection & TreeLikeCollectionInterface
{
}
} <?php
namespace Domain\Shared\Models;
use Domain\Shared\Collections\TreeLikeCollectionInterface;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* @phpstan-type ParentId = int|string
*
* @phpstan-require-extends Model
*
* @property static $parent
* @property Collection<array-key, static>&TreeLikeCollectionInterface<static> $children
*/
interface HierarchicalModelInterface
{
/**
* Retrieve the name of the field which holds the key of this entity's parent.
*
* @return ?ParentId
*/
public function getParentKeyName(): int|string|null;
/**
* @see Model::newCollection()
*
* @param array<static> $models The models for the new collection
*
* @return Collection & TreeLikeCollectionInterface The new collection.
*/
public function newCollection(array $models = []): TreeLikeCollectionInterface;
/**
* Relationship to the parent entity.
*/
public function parent(): BelongsTo;
/**
* Relationship to the child entities.
*/
public function children(): HasMany;
/**
* Retrieves all children of this instance recursively.
*/
public function getDescendants(): Collection & TreeLikeCollectionInterface;
/**
* Retrieves all parents of this instance recursively.
*/
public function getAncestors(): Collection & TreeLikeCollectionInterface;
} The |
This is being caused in the larastan/src/Support/CollectionHelper.php Lines 84 to 85 in b0bfa09
We are not properly handling intersection types |
Thanks for the quick response! Looking forward to the fix 🙏 |
Description
As described in phpstan/phpstan#11812, there's a "class was not found" error for something that in fact an intersection type, and it only happens in some place and not another seemingly very similar place. Here's the complete output:
Laravel code where the issue was found
This code has nothing to do with Laravel per se: just an interface and a trait. But some types that it uses are from Laravel.
The text was updated successfully, but these errors were encountered: