Neo4jResultExtension   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 76.47%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 3
dl 0
loc 54
ccs 13
cts 17
cp 0.7647
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilters() 0 6 1
A getType() 0 4 1
A getName() 0 4 1
B doGetType() 0 18 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neo4j\Neo4jBundle\Collector\Twig;
6
7
use GraphAware\Neo4j\Client\Formatter\Type\Node;
8
use Twig\Extension\AbstractExtension;
9
10
/**
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13
class Neo4jResultExtension extends AbstractExtension
14
{
15
    /**
16
     * {@inheritdoc}
17
     *
18
     * @return array
19
     */
20
    public function getFilters()
21
    {
22
        return [
23
            new \Twig_SimpleFilter('neo4jResult', [$this, 'getType']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
24
        ];
25
    }
26
27
    /**
28
     * @param mixed $object
29
     *
30
     * @return string
31
     */
32 6
    public function getType($object): string
33
    {
34 6
        return $this->doGetType($object, true);
35
    }
36
37
    public function getName(): string
38
    {
39
        return 'neo4j.result';
40
    }
41
42
    /**
43
     * @param mixed $object
44
     * @param bool  $recursive
45
     *
46
     * @return string
47
     */
48 6
    private function doGetType($object, bool $recursive): string
49
    {
50 6
        if ($object instanceof Node) {
51 1
            return sprintf('%s: %s', $object->identity(), implode(', ', $object->labels()));
52 5
        } elseif (is_array($object) && $recursive) {
53 3
            if (empty($object)) {
54 1
                return 'Empty array';
55
            }
56 2
            $ret = [];
57 2
            foreach ($object as $o) {
58 2
                $ret[] = $this->doGetType($o, false);
59
            }
60
61 2
            return sprintf('[%s]', implode(', ', $ret));
62
        }
63
64 4
        return is_object($object) ? get_class($object) : gettype($object);
65
    }
66
}
67