Completed
Pull Request — master (#12)
by Michael
01:18
created

ProductBundleRegistry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isProductBundle() 0 5 1
A getProductBundleForProduct() 0 8 2
1
<?php
2
declare(strict_types=1);
3
4
namespace SolutionDrive\SyliusProductBundlesPlugin\Service;
5
6
use SolutionDrive\SyliusProductBundlesPlugin\Entity\ProductBundleInterface;
7
use SolutionDrive\SyliusProductBundlesPlugin\Exception\ProductIsNotAProductBundleException;
8
use Sylius\Component\Core\Model\ProductInterface;
9
use Sylius\Component\Resource\Repository\RepositoryInterface;
10
11
/**
12
 * Created by solutionDrive GmbH.
13
 *
14
 * @copyright 2018 solutionDrive GmbH
15
 */
16
class ProductBundleRegistry implements ProductBundleRegistryInterface
17
{
18
    /** @var RepositoryInterface */
19
    private $productBundleRepository;
20
21
    public function __construct(RepositoryInterface $productBundleRepository)
22
    {
23
        $this->productBundleRepository = $productBundleRepository;
24
    }
25
26
    public function isProductBundle(ProductInterface $product): bool
27
    {
28
        $productBundle = $this->productBundleRepository->findOneBy(['product' => $product]);
29
        return (null !== $productBundle);
30
    }
31
32
    public function getProductBundleForProduct(ProductInterface $product): ProductBundleInterface
33
    {
34
        $productBundle = $this->productBundleRepository->findOneBy(['product' => $product]);
35
        if (null === $productBundle) {
36
            throw new ProductIsNotAProductBundleException($product);
37
        }
38
        return $productBundle;
39
    }
40
}
41