| Total Complexity | 6 | 
| Total Lines | 29 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php  | 
            ||
| 4 | class EncapsulatedStack  | 
            ||
| 5 | { | 
            ||
| 6 | private array $stack = [];  | 
            ||
| 7 | |||
| 8 | public function push(DatabaseItem $encapsulated): void  | 
            ||
| 9 |     { | 
            ||
| 10 | $this->stack[] = $encapsulated;  | 
            ||
| 11 | }  | 
            ||
| 12 | |||
| 13 | public function pop(): DatabaseItem  | 
            ||
| 16 | }  | 
            ||
| 17 | |||
| 18 | public function top(): DatabaseItem  | 
            ||
| 21 | }  | 
            ||
| 22 | |||
| 23 | public function hasItems(): bool  | 
            ||
| 24 |     { | 
            ||
| 25 | return !empty($this->stack);  | 
            ||
| 26 | }  | 
            ||
| 27 | |||
| 28 | public function purge(): void  | 
            ||
| 33 | }  | 
            ||
| 34 | }  | 
            ||
| 37 | 
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: