-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix some findings from PHPStan level 6 #2686
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2686 +/- ##
==========================================
- Coverage 79.55% 79.55% -0.01%
==========================================
Files 161 161
Lines 8409 8412 +3
==========================================
+ Hits 6690 6692 +2
- Misses 1719 1720 +1
☔ View full report in Codecov by Sentry. |
b4433e8
to
58baa01
Compare
thanks @phansys! |
@@ -63,7 +63,7 @@ public function buildTree(array $nodes, array $options = []); | |||
* | |||
* @param object[] $nodes The nodes to build the tree from | |||
* | |||
* @return array | |||
* @return array<int, array<string, mixed>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @phansys the actual implementation returns objects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the feedback @ro0NL.
Could you please elaborate? I'm inferring this type based on the results of this test:
DoctrineExtensions/tests/Gedmo/Tree/MaterializedPathORMRepositoryTest.php
Lines 238 to 295 in 157363b
public function testChildrenHierarchyMethod(): void | |
{ | |
$tree = $this->repo->childrenHierarchy(); | |
static::assertSame('Drinks', $tree[0]['title']); | |
static::assertSame('Whisky', $tree[0]['__children'][0]['title']); | |
static::assertSame('Best Whisky', $tree[0]['__children'][0]['__children'][0]['title']); | |
$vegitablesChildren = $tree[1]['__children'][1]['__children']; | |
static::assertSame('Food', $tree[1]['title']); | |
static::assertSame('Fruits', $tree[1]['__children'][0]['title']); | |
static::assertSame('Vegitables', $tree[1]['__children'][1]['title']); | |
static::assertSame('Carrots', $vegitablesChildren[0]['title']); | |
static::assertSame('Potatoes', $vegitablesChildren[1]['title']); | |
static::assertSame('Sports', $tree[2]['title']); | |
// Tree of one specific root, without the root node | |
$roots = $this->repo->getRootNodes(); | |
$tree = $this->repo->childrenHierarchy($roots[0]); | |
static::assertSame('Whisky', $tree[0]['title']); | |
static::assertSame('Best Whisky', $tree[0]['__children'][0]['title']); | |
// Tree of one specific root, with the root node | |
$tree = $this->repo->childrenHierarchy($roots[0], false, [], true); | |
static::assertSame('Drinks', $tree[0]['title']); | |
static::assertSame('Whisky', $tree[0]['__children'][0]['title']); | |
static::assertSame('Best Whisky', $tree[0]['__children'][0]['__children'][0]['title']); | |
// Tree of one specific root only with direct children, without the root node | |
$roots = $this->repo->getRootNodes(); | |
$tree = $this->repo->childrenHierarchy($roots[1], true); | |
static::assertCount(2, $tree); | |
static::assertSame('Fruits', $tree[0]['title']); | |
static::assertSame('Vegitables', $tree[1]['title']); | |
// Tree of one specific root only with direct children, with the root node | |
$tree = $this->repo->childrenHierarchy($roots[1], true, [], true); | |
static::assertCount(1, $tree); | |
static::assertCount(2, $tree[0]['__children']); | |
static::assertSame('Food', $tree[0]['title']); | |
static::assertSame('Fruits', $tree[0]['__children'][0]['title']); | |
static::assertSame('Vegitables', $tree[0]['__children'][1]['title']); | |
// HTML Tree of one specific root, without the root node | |
$roots = $this->repo->getRootNodes(); | |
$tree = $this->repo->childrenHierarchy($roots[0], false, ['decorate' => true], false); | |
static::assertSame('<ul><li>Whisky<ul><li>Best Whisky</li></ul></li></ul>', $tree); | |
// HTML Tree of one specific root, with the root node | |
$roots = $this->repo->getRootNodes(); | |
$tree = $this->repo->childrenHierarchy($roots[0], false, ['decorate' => true], true); | |
static::assertSame('<ul><li>Drinks<ul><li>Whisky<ul><li>Best Whisky</li></ul></li></ul></li></ul>', $tree); | |
} |
The return value for this method on that test is something like this:
array(3) {
[0]=>
array(6) {
["id"]=>
int(7)
["path"]=>
string(9) "Drinks-7,"
["title"]=>
string(6) "Drinks"
["level"]=>
int(1)
["treeRootValue"]=>
string(8) "Drinks-7"
["__children"]=>
array(1) {
[0]=>
array(6) {
["id"]=>
int(8)
["path"]=>
string(18) "Drinks-7,Whisky-8,"
["title"]=>
string(6) "Whisky"
["level"]=>
int(2)
["treeRootValue"]=>
string(8) "Drinks-7"
["__children"]=>
array(1) {
[0]=>
array(6) {
["id"]=>
int(9)
["path"]=>
string(32) "Drinks-7,Whisky-8,Best Whisky-9,"
["title"]=>
string(11) "Best Whisky"
["level"]=>
int(3)
["treeRootValue"]=>
string(8) "Drinks-7"
["__children"]=>
array(0) {
}
}
}
}
}
}
[1]=>
array(6) {
["id"]=>
int(1)
["path"]=>
string(7) "Food-1,"
["title"]=>
string(4) "Food"
["level"]=>
int(1)
["treeRootValue"]=>
string(6) "Food-1"
["__children"]=>
array(2) {
[0]=>
array(6) {
["id"]=>
int(3)
["path"]=>
string(16) "Food-1,Fruits-3,"
["title"]=>
string(6) "Fruits"
["level"]=>
int(2)
["treeRootValue"]=>
string(6) "Food-1"
["__children"]=>
array(0) {
}
}
[1]=>
array(6) {
["id"]=>
int(4)
["path"]=>
string(20) "Food-1,Vegitables-4,"
["title"]=>
string(10) "Vegitables"
["level"]=>
int(2)
["treeRootValue"]=>
string(6) "Food-1"
["__children"]=>
array(2) {
[0]=>
array(6) {
["id"]=>
int(5)
["path"]=>
string(30) "Food-1,Vegitables-4,Carrots-5,"
["title"]=>
string(7) "Carrots"
["level"]=>
int(3)
["treeRootValue"]=>
string(6) "Food-1"
["__children"]=>
array(0) {
}
}
[1]=>
array(6) {
["id"]=>
int(6)
["path"]=>
string(31) "Food-1,Vegitables-4,Potatoes-6,"
["title"]=>
string(8) "Potatoes"
["level"]=>
int(3)
["treeRootValue"]=>
string(6) "Food-1"
["__children"]=>
array(0) {
}
}
}
}
}
}
[2]=>
&array(6) {
["id"]=>
int(2)
["path"]=>
string(9) "Sports-2,"
["title"]=>
string(6) "Sports"
["level"]=>
int(1)
["treeRootValue"]=>
string(8) "Sports-2"
["__children"]=>
array(0) {
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the contract takes object nodes:
* @param object[] $nodes The nodes to build the tree from |
the concrete implementaton appends object nodes:
$nestedTree[$i] = $item; |
No description provided.