BreadCrumbs   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 30
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 4
1
<?php
2
3
namespace Beelab\SimplePageBundle\Util;
4
5
class BreadCrumbs
0 ignored issues
show
Coding Style introduced by
BreadCrumbs does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
6
{
7
    /**
8
     * Create breadcrumbs from a path
9
     * Example: if $path is "foo/bar/baz", $return is [
10
     *     'foo'         => 'foo',
11
     *     'foo/bar'     => 'bar',
12
     *     'foo/bar/baz' => 'baz',
13
     * ].
14
     *
15
     * @param string $path
16
     *
17
     * @return array
18
     */
19
    public static function create(string $path): array
20
    {
21
        $return = [];
22
        $breadCrumbs = explode('/', $path);
23
        $length = count($breadCrumbs);
24
        for ($i = 1; $i <= $length; ++$i) {
25
            $current = '';
26
            for ($j = 1; $j <= $i; ++$j) {
27
                $current .= $breadCrumbs[$j - 1].($j == $i ? '' : '/');
28
            }
29
            $return[$current] = $breadCrumbs[$i - 1];
30
        }
31
32
        return $return;
33
    }
34
}
35