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

CatalogFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

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 0
cts 8
cp 0
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\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
}