Skip to content

Commit

Permalink
phpstan typing progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Jun 8, 2024
1 parent ddcfb3d commit 5644895
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 217 deletions.
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ parameters:
excludePaths:
stubFiles:
ignoreErrors:
- identifier: missingType.generics
- identifier: missingType.generics
- '#Interface must be located in "Contract" or "Contracts" namespace#'
12 changes: 5 additions & 7 deletions src/AncestorsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Database\Eloquent\Model;

/**
* @template T
*/
class AncestorsRelation extends BaseRelation
{
/**
Expand Down Expand Up @@ -44,14 +47,9 @@ protected function addEagerConstraint($query, $model)
}

/**
* @param $hash
* @param $table
* @param $lft
* @param $rgt
*
* @return string
* {@inheritdoc}
*/
protected function relationExistenceCondition($hash, $table, $lft, $rgt)
protected function relationExistenceCondition(string $hash, string $table, string $lft, string $rgt): string
{
$key = $this->getBaseQuery()->getGrammar()->wrap($this->parent->getKeyName());

Expand Down
14 changes: 7 additions & 7 deletions src/BaseRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class BaseRelation extends Relation
protected $query;

/**
* @var NodeTrait|Model
* @var Node&Model
*/
protected $parent;

Expand Down Expand Up @@ -59,19 +59,19 @@ abstract protected function matches(Model $model, $related);
abstract protected function addEagerConstraint($query, $model);

/**
* @param $hash
* @param $table
* @param $lft
* @param $rgt
* @param string $hash
* @param string $table
* @param string $lft
* @param string $rgt
*
* @return string
*/
abstract protected function relationExistenceCondition($hash, $table, $lft, $rgt);
abstract protected function relationExistenceCondition(string $hash, string $table, string $lft, string $rgt): string;

/**
* @param EloquentBuilder $query
* @param EloquentBuilder $parent
* @param array $columns
* @param string[] $columns
*
* @return mixed
*/
Expand Down
14 changes: 7 additions & 7 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public function linkNodes()

$groupedNodes = $this->groupBy($this->first()->getParentIdName());

/** @var NodeTrait|Model $node */
/** @var Node&Model $node */
foreach ($this->items as $node) {
if (!$node->getParentId()) {
if ($node->getParentId() === null) {
$node->setRelation('parent', null);
}

$children = $groupedNodes->get($node->getKey(), []);

/** @var Model|NodeTrait $child */
/** @var Model&Node $child */
foreach ($children as $child) {
$child->setRelation('parent', $node);
}
Expand Down Expand Up @@ -64,9 +64,9 @@ public function toTree($root = false)

$root = $this->getRootNodeId($root);

/** @var Model|NodeTrait $node */
/** @var Model&Node $node */
foreach ($this->items as $node) {
if ($node->getParentId() == $root) {
if ($node->getParentId() === $root) {
$items[] = $node;
}
}
Expand All @@ -77,7 +77,7 @@ public function toTree($root = false)
/**
* @param mixed $root
*
* @return int
* @return int|string|null
*/
protected function getRootNodeId($root = false)
{
Expand All @@ -93,7 +93,7 @@ protected function getRootNodeId($root = false)
// least lft value as root node id.
$leastValue = null;

/** @var Model|NodeTrait $node */
/** @var Model&Node $node */
foreach ($this->items as $node) {
if ($leastValue === null || $node->getLft() < $leastValue) {
$leastValue = $node->getLft();
Expand Down
9 changes: 2 additions & 7 deletions src/DescendantsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,9 @@ protected function matches(Model $model, $related)
}

/**
* @param $hash
* @param $table
* @param $lft
* @param $rgt
*
* @return string
* {@inheritdoc}
*/
protected function relationExistenceCondition($hash, $table, $lft, $rgt)
protected function relationExistenceCondition(string $hash, string $table, string $lft, string $rgt): string
{
return "{$hash}.{$lft} between {$table}.{$lft} + 1 and {$table}.{$rgt}";
}
Expand Down
10 changes: 5 additions & 5 deletions src/NestedSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class NestedSet
*
* @param \Illuminate\Database\Schema\Blueprint $table
*/
public static function columns(Blueprint $table)
public static function columns(Blueprint $table): void
{
$table->unsignedInteger(self::LFT)->default(0);
$table->unsignedInteger(self::RGT)->default(0);
Expand All @@ -50,7 +50,7 @@ public static function columns(Blueprint $table)
*
* @param \Illuminate\Database\Schema\Blueprint $table
*/
public static function dropColumns(Blueprint $table)
public static function dropColumns(Blueprint $table): void
{
$columns = static::getDefaultColumns();

Expand All @@ -61,9 +61,9 @@ public static function dropColumns(Blueprint $table)
/**
* Get a list of default columns.
*
* @return array
* @return string[]
*/
public static function getDefaultColumns()
public static function getDefaultColumns(): array
{
return [static::LFT, static::RGT, static::PARENT_ID];
}
Expand All @@ -75,7 +75,7 @@ public static function getDefaultColumns()
*
* @return bool
*/
public static function isNode($node)
public static function isNode(mixed $node): bool
{
return $node instanceof Node;
}
Expand Down
Loading

0 comments on commit 5644895

Please sign in to comment.