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

CatalogFactory::getCatalog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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
}