Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
NodeIdFactory
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 getNextNodeId
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace pvc\struct\tree\node;
4
5class NodeIdFactory
6{
7    /**
8     * @var NodeIdFactory
9     */
10    protected static NodeIdFactory $instance;
11
12    /**
13     * @var non-negative-int
14     */
15    protected static int $nextNodeId;
16
17    /**
18     * @return non-negative-int
19     */
20    public static function getNextNodeId(): int
21    {
22        if (!isset(self::$instance)) {
23            self::$instance = new NodeIdFactory();
24            self::$nextNodeId = 0;
25        }
26        return self::$instance::$nextNodeId++;
27    }
28}