Skip to content
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

Merged
merged 1 commit into from
Sep 4, 2023

Conversation

phansys
Copy link
Collaborator

@phansys phansys commented Sep 3, 2023

No description provided.

@codecov
Copy link

codecov bot commented Sep 3, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01% ⚠️

Comparison is base (5502bae) 79.55% compared to head (b804c32) 79.55%.

❗ Current head b804c32 differs from pull request most recent head 157363b. Consider uploading reports for the commit 157363b to get more accurate results

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     
Files Changed Coverage Δ
...gable/Entity/MappedSuperclass/AbstractLogEntry.php 86.66% <ø> (ø)
src/Mapping/Driver/AbstractAnnotationDriver.php 63.63% <ø> (+0.30%) ⬆️
src/Mapping/Driver/File.php 58.33% <ø> (ø)
src/Mapping/ExtensionMetadataFactory.php 83.13% <ø> (ø)
src/ReferenceIntegrity/Mapping/Validator.php 100.00% <ø> (ø)
...SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php 76.92% <ø> (ø)
.../Sortable/Entity/Repository/SortableRepository.php 91.17% <ø> (ø)
src/Sortable/Mapping/Driver/Yaml.php 86.20% <ø> (ø)
src/Sortable/Mapping/Event/Adapter/ORM.php 80.70% <ø> (ø)
src/Sortable/SortableListener.php 93.84% <ø> (ø)
... and 13 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@phansys phansys force-pushed the phpstan_6 branch 13 times, most recently from b4433e8 to 58baa01 Compare September 3, 2023 20:36
@phansys phansys requested a review from franmomu September 3, 2023 21:14
@phansys phansys marked this pull request as ready for review September 3, 2023 21:14
phpstan.neon.dist Show resolved Hide resolved
@franmomu franmomu merged commit a47b675 into doctrine-extensions:main Sep 4, 2023
21 checks passed
@franmomu
Copy link
Collaborator

franmomu commented Sep 4, 2023

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>>
Copy link

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

Copy link
Collaborator Author

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:

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) {
    }
  }
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phansys

the contract takes object nodes:

* @param object[] $nodes The nodes to build the tree from

the concrete implementaton appends object nodes:

$nestedTree[$i] = $item;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants