BreadCrumbs::create()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 4
nc 4
nop 1
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