Test Failed
Branch develop (6f7954)
by Andreas
05:13 queued 02:18
created

CatalogFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

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
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;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Wambo\Catalog\Catalog.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
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);
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
}