| Conditions | 6 | 
| Paths | 4 | 
| Total Lines | 29 | 
| Code Lines | 16 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 16 | 
| CRAP Score | 6 | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php  | 
            ||
| 24 | 4 | public static function fromLevelOrderList(array $list, callable $nodeCreator): ?Node  | 
            |
| 25 |     { | 
            ||
| 26 | 4 | $tailIdx = count($list) - 1;  | 
            |
| 27 | 4 |         if ($tailIdx < 0 || (0 === $tailIdx && null === $list[0])) { | 
            |
| 28 | 2 | return null;  | 
            |
| 29 | }  | 
            ||
| 30 | |||
| 31 | /** @var \SplQueue<Node> $queue */  | 
            ||
| 32 | 2 | $queue = new \SplQueue();  | 
            |
| 33 | |||
| 34 | 2 | $root = call_user_func($nodeCreator, $list[0]); // @phpstan-ignore argument.type  | 
            |
| 35 | 2 | $queue->enqueue($root);  | 
            |
| 36 | |||
| 37 | 2 | $idx = 2; // Should be index 1, but it contains the null value indicating end of children for "root" level !  | 
            |
| 38 | 2 |         while ($idx <= $tailIdx) { | 
            |
| 39 | 2 | $parentNode = $queue->bottom(); // =peek() => next value to dequeue from a SplQueue!  | 
            |
| 40 | |||
| 41 | // Append children to the current parent node until a null value is found  | 
            ||
| 42 | 2 |             if (null !== $list[$idx]) { | 
            |
| 43 | 2 | $parentNode->children[] = $node = call_user_func($nodeCreator, $list[$idx]);  | 
            |
| 44 | 2 | $queue->enqueue($node);  | 
            |
| 45 |             } else { | 
            ||
| 46 | // Drop current parent node as there is no more children to attach  | 
            ||
| 47 | 2 | $queue->dequeue();  | 
            |
| 48 | }  | 
            ||
| 49 | 2 | ++$idx;  | 
            |
| 50 | }  | 
            ||
| 51 | |||
| 52 | 2 | return $root;  | 
            |
| 53 | }  | 
            ||
| 55 |