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

ProductBreadcrumbGenerator::generate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 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