Passed
Push — develop ( b02061...820347 )
by Andreas
03:07
created

CatalogFactory::getCatalog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Wambo\Catalog;
4
5
use League\Flysystem\FilesystemInterface;
6
use Wambo\Catalog\Exception\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
    public function __construct(FilesystemInterface $filesystem, string $jsonCatalogFilePath)
29
    {
30
        $contentMapper = new ContentMapper();
31
        $productMapper = new ProductMapper($contentMapper);
32
        $catalogMapper = new CatalogMapper($productMapper);
33
34
        $this->catalogProvider = new JSONCatalogProvider($filesystem, $jsonCatalogFilePath, $catalogMapper);
0 ignored issues
show
Bug introduced by
The call to JSONCatalogProvider::__construct() misses a required argument $catalogMapper.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
$catalogMapper is of type object<Wambo\Catalog\Mapper\CatalogMapper>, but the function expects a object<Wambo\Core\Storage\JSONDecoder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
    }
36
37
    /**
38
     * Get the product catalog
39
     *
40
     * @return Catalog
41
     *
42
     * @throws CatalogException
43
     */
44
    public function getCatalog()
45
    {
46
        return $this->catalogProvider->getCatalog();
47
    }
48
}