Completed
Pull Request — master (#290)
by
unknown
41:51
created

ProductBreadcrumbGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 11
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\SyliusShopApiPlugin\Generator;
6
7
use Sylius\Component\Core\Model\ProductInterface;
8
9
final class ProductBreadcrumbGenerator implements ProductBreadcrumbGeneratorInterface
10
{
11
    public function generate(ProductInterface $product, string $locale): string
12
    {
13
        $breadcrumb = $product->getTranslation($locale)->getSlug();
14
15
        $taxon = $product->getMainTaxon();
16
17
        return $taxon ? sprintf('%s/%s', $taxon->getTranslation($locale)->getSlug(), $breadcrumb) : $breadcrumb;
18
    }
19
}
20