Passed
Push — master ( 2137d7...b51f94 )
by Muhammed
37s
created

DebugInfoTrait   A

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