Completed
Push — master ( 944006...1e86f4 )
by
unknown
02:33 queued 11s
created

PathGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 17
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generatePath() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\MediaBundle\Generator;
15
16
use Sonata\MediaBundle\Model\MediaInterface;
17
18
/**
19
 * @final since sonata-project/media-bundle 3.21.0
20
 */
21
class PathGenerator implements GeneratorInterface
22
{
23
    public function generatePath(MediaInterface $media)
24
    {
25
        $segments = preg_split('#/#', $media->getId(), -1, PREG_SPLIT_NO_EMPTY);
26
27
        if (\count($segments) > 1) {
28
            // remove last part from id
29
            array_pop($segments);
30
            $path = implode('/', $segments);
31
        } else {
32
            $path = '';
33
        }
34
35
        return $path ? sprintf('%s/%s', $media->getContext(), $path) : $media->getContext();
36
    }
37
}
38