DebugInfoTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 10
wmc 5
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __debugInfo() 0 17 5
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Itertools\lib\Traits;
7
8
trait DebugInfoTrait
9
{
10
    /**
11
     * This method is called by var_dump() when dumping an object to get the properties that should be shown.
12
     *
13
     * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
14
     * @return array
15
     */
16 2
    public function __debugInfo() // phpcs:ignore Zicht.NamingConventions.Functions.MethodNaming
17
    {
18 2
        $duplicateKeys = [];
19 2
        $info = ['__length__' => 0];
20 2
        if ($this instanceof \Traversable) {
21 2
            foreach ($this as $key => $value) {
22 2
                $key = (string)$key;
23 2
                while (array_key_exists($key, $info)) {
24 1
                    $duplicateKeys[$key] = array_key_exists($key, $duplicateKeys) ? $duplicateKeys[$key] + 1 : 1;
25 1
                    $key = sprintf('%s__#%s__', $key, $duplicateKeys[$key]);
26
                }
27 2
                $info[$key] = $value;
28 2
                $info['__length__'] += 1;
29
            }
30
        }
31 2
        return $info;
32
    }
33
}
34