Passed
Branch develop (415154)
by Andreas
04:10 queued 01:34
created

CatalogFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 32
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getCatalog() 0 4 1
1
<?php
2
3
namespace Wambo\Catalog;
4
5
use League\Flysystem\FilesystemInterface;
6
use Wambo\Catalog\Error\CatalogException;
7
use Wambo\Catalog\Mapper\CatalogMapper;
8
use Wambo\Catalog\Mapper\ContentMapper;
9
use Wambo\Catalog\Mapper\ProductMapper;
10
use Wambo\Catalog\Model\Catalog;
11
12
/**
13
 * Class CatalogFactory creates Catalog models
14
 *
15
 * @package Wambo\Catalog
16
 */
17
class CatalogFactory
18
{
19
    /** @var CatalogProviderInterface $catalogProvider */
20
    private $catalogProvider;
21
22
    /**
23
     * CatalogFactory constructor.
24
     *
25
     * @param FilesystemInterface $filesystem
26
     * @param string              $jsonCatalogFilePath The path to the JSON catalog
27
     */
28 2
    public function __construct(FilesystemInterface $filesystem, string $jsonCatalogFilePath)
29
    {
30 2
        $contentMapper = new ContentMapper();
31 2
        $productMapper = new ProductMapper($contentMapper);
32 2
        $catalogMapper = new CatalogMapper($productMapper);
33
34 2
        $this->catalogProvider = new JSONCatalogProvider($filesystem, $jsonCatalogFilePath, $catalogMapper);
35 2
    }
36
37
    /**
38
     * Get the product catalog
39
     *
40
     * @return Catalog
41
     *
42
     * @throws CatalogException
43
     */
44 2
    public function getCatalog()
45
    {
46 2
        return $this->catalogProvider->getCatalog();
47
    }
48
}