Skip to content

Commit

Permalink
Fix composer etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Oct 23, 2024
1 parent a99aab9 commit 1fea27b
Show file tree
Hide file tree
Showing 10 changed files with 992 additions and 984 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpunit/phpunit": "^10.5",
"lychee-org/phpstan-lychee": "^1.0.4",
"nunomaduro/larastan": "^2.0",
"larastan/larastan": "^2.0",
"orchestra/testbench": "^9.0"
},
"autoload": {
Expand Down
1,724 changes: 873 additions & 851 deletions composer.lock

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- vendor/nunomaduro/larastan/extension.neon
- vendor/larastan/larastan/extension.neon
- vendor/lychee-org/phpstan-lychee/phpstan.neon

parameters:
Expand All @@ -15,9 +15,3 @@ parameters:
# - '#Dynamic call to static method Kalnoy\\Nestedset\\QueryBuilder<.*>::whereRaw\(\).#'
- '#Dynamic call to static method Kalnoy\\Nestedset\\QueryBuilder<.*>::whereNested\(\).#'
- '#Dynamic call to static method Kalnoy\\Nestedset\\QueryBuilder<.*>::whereIn\(\).#'
- '#Parameter .* \$models .* of method .*::initRelation\(\) should be contravariant with parameter \$models .* of method .*::initRelation\(\)#'
- '#Parameter .* \$models .* of method .*::addEagerConstraints\(\) should be contravariant with parameter \$models .* of method .*::addEagerConstraints\(\)#'
- '#Parameter .* \$models .* of method .*::match\(\) should be contravariant with parameter \$models .* of method .*::match\(\)#'
- '#Parameter .* \$query .* of method .*::getRelationExistenceQuery\(\) should be contravariant with parameter \$query .* of method .*::getRelationExistenceQuery\(\)#'
- '#Parameter .* \$parentQuery .* of method .*::getRelationExistenceQuery\(\) should be contravariant with parameter \$parentQuery .* of method .*::getRelationExistenceQuery\(\)#'
- '#Parameter .* \$results .* of method .*::match\(\) should be contravariant with parameter \$results .* of method .*::match\(\)#'
7 changes: 3 additions & 4 deletions src/AncestorsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
use Illuminate\Database\Eloquent\Model;

/**
* @template Tmodelkey
* @template Tmodel of Model
*
* @phpstan-type NodeModel Node<Tmodelkey,Tmodel>&Tmodel
* @phpstan-type NodeModel Node<Tmodel>&Tmodel
*
* @disregard P1037
*
* @extends BaseRelation<Tmodelkey,Tmodel>
* @extends BaseRelation<Tmodel>
*/
class AncestorsRelation extends BaseRelation
{
Expand Down Expand Up @@ -43,7 +42,7 @@ protected function matches(Model $model, $related): bool
}

/**
* @param QueryBuilder<Tmodelkey,Tmodel> $query
* @param QueryBuilder<Tmodel> $query
* @param NodeModel $model
*
* @return void
Expand Down
29 changes: 15 additions & 14 deletions src/BaseRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
use Illuminate\Database\Query\Builder;

/**
* @template Tmodelkey
* @template Tmodel of Model
*
* @phpstan-type NodeModel Node<Tmodelkey,Tmodel>&Tmodel
* @phpstan-type NodeModel Node<Tmodel>&Tmodel
*
* @extends Relation<NodeModel>
* @extends Relation<NodeModel,NodeModel,EloquentCollection<int,NodeModel>>
*
* @property NodeModel $related
* @property NodeModel $parent
Expand All @@ -24,7 +23,7 @@
abstract class BaseRelation extends Relation
{
/**
* @var QueryBuilder<Tmodelkey,Tmodel>
* @var QueryBuilder<Tmodel>
*/
protected $query;

Expand All @@ -43,7 +42,7 @@ abstract class BaseRelation extends Relation
/**
* AncestorsRelation constructor.
*
* @param QueryBuilder<Tmodelkey,Tmodel> $builder
* @param QueryBuilder<Tmodel> $builder
* @param NodeModel $model
*/
public function __construct(QueryBuilder $builder, Model $model)
Expand All @@ -64,7 +63,7 @@ public function __construct(QueryBuilder $builder, Model $model)
abstract protected function matches(Model&Node $model, Node $related): bool;

/**
* @param QueryBuilder<Tmodelkey,Tmodel> $query
* @param QueryBuilder<Tmodel> $query
* @param NodeModel $model
*
* @return void
Expand All @@ -86,10 +85,10 @@ abstract protected function relationExistenceCondition(string $hash, string $tab
* @param EloquentBuilder<NodeModel> $parentQuery
* @param mixed $columns
*
* @return QueryBuilder<Tmodelkey,Tmodel>
* @return QueryBuilder<Tmodel>
*/
public function getRelationExistenceQuery(EloquentBuilder $query, EloquentBuilder $parentQuery,
$columns = ['*']
$columns = ['*'],
) {
$query = $this->getParent()->replicate()->newScopedQuery()->select($columns);

Expand All @@ -113,10 +112,10 @@ public function getRelationExistenceQuery(EloquentBuilder $query, EloquentBuilde
/**
* Initialize the relation on a set of models.
*
* @param array<int,Tmodel> $models
* @param array<int,NodeModel> $models
* @param string $relation
*
* @return array<int,Tmodel>
* @return array<int,NodeModel>
*/
public function initRelation(array $models, $relation)
{
Expand All @@ -138,11 +137,13 @@ public function getRelationCountHash($incrementJoinCount = true)
/**
* Get the results of the relationship.
*
* @return mixed
* @return Collection<NodeModel>
*/
public function getResults()
{
return $this->query->get();
/** @var Collection<NodeModel> */
$result = $this->query->get();
return $result;
}

/**
Expand Down Expand Up @@ -195,11 +196,11 @@ public function match(array $models, EloquentCollection $results, $relation)
* @param NodeModel $model
* @param EloquentCollection<int,NodeModel> $results
*
* @return Collection<int,Tmodelkey,Tmodel>
* @return Collection<Tmodel>
*/
protected function matchForModel(Model $model, EloquentCollection $results)
{
/** @var Collection<int,Tmodelkey,Tmodel> */
/** @var Collection<Tmodel> */
$result = $this->related->newCollection();

foreach ($results as $related) {
Expand Down
22 changes: 10 additions & 12 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
use Illuminate\Database\Eloquent\Model;

/**
* @template TKey of array-key
* @template Tmodelkey
* @template Tmodel of Model
*
* @phpstan-type NodeModel Node<Tmodelkey,Tmodel>&Tmodel
* @phpstan-type NodeModel Node<Tmodel>&Tmodel
*
* @extends EloquentCollection<TKey,NodeModel>
* @extends EloquentCollection<array-key,NodeModel>
*/
final class Collection extends EloquentCollection
{
Expand Down Expand Up @@ -61,7 +59,7 @@ public function linkNodes()
*
* @param mixed $root
*
* @return Collection<TKey,Tmodelkey,Tmodel>
* @return Collection<Tmodel>
*/
public function toTree($root = false)
{
Expand All @@ -88,7 +86,7 @@ public function toTree($root = false)
/**
* @param mixed $root
*
* @return Tmodelkey
* @return array-key
*/
protected function getRootNodeId($root = false)
{
Expand Down Expand Up @@ -125,11 +123,11 @@ protected function getRootNodeId($root = false)
*
* @param bool $root
*
* @return Collection<TKey,Tmodelkey,Tmodel>
* @return Collection<Tmodel>
*/
public function toFlatTree($root = false): Collection
{
/** @Var Collection<TKey,Tmodelkey,Tmodel> */
/** @Var Collection<Tmodel> */
$result = new Collection();

if ($this->isEmpty()) {
Expand All @@ -138,7 +136,7 @@ public function toFlatTree($root = false): Collection

/** @var NodeModel */
$first = $this->first();
/** @var Collection<TKey,Tmodelkey,NodeModel> */
/** @var Collection<NodeModel> */
$groupedNodes = $this->groupBy($first->getParentIdName());

return $result->flattenTree($groupedNodes, $this->getRootNodeId($root)); /** @phpstan-ignore-line */
Expand All @@ -147,10 +145,10 @@ public function toFlatTree($root = false): Collection
/**
* Flatten a tree into a non recursive array.
*
* @param Collection<TKey,Tmodelkey,Tmodel> $groupedNodes
* @param Tmodelkey $parentId
* @param Collection<Tmodel> $groupedNodes
* @param array-key $parentId
*
* @return Collection<TKey,Tmodelkey,Tmodel>
* @return Collection<Tmodel>
*/
protected function flattenTree(Collection $groupedNodes, $parentId): Collection
{
Expand Down
7 changes: 3 additions & 4 deletions src/DescendantsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
use Illuminate\Database\Eloquent\Model;

/**
* @template Tmodelkey
* @template Tmodel of Model
*
* @phpstan-type NodeModel Node<Tmodelkey,Tmodel>&Tmodel
* @phpstan-type NodeModel Node<Tmodel>&Tmodel
*
* @disregard P1037
*
* @extends BaseRelation<Tmodelkey,Tmodel>
* @extends BaseRelation<Tmodel>
*/
class DescendantsRelation extends BaseRelation
{
Expand All @@ -32,7 +31,7 @@ public function addConstraints()
}

/**
* @param QueryBuilder<Tmodelkey,Tmodel> $query
* @param QueryBuilder<Tmodel> $query
* @param NodeModel $model
*/
protected function addEagerConstraint($query, $model)
Expand Down
Loading

0 comments on commit 1fea27b

Please sign in to comment.