Completed
Push — master ( 971d31...2154ff )
by Fabian
10:09
created

ProductFixtureRollback::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace TddWizard\Fixtures\Catalog;
4
5
use Magento\Catalog\Api\ProductRepositoryInterface;
6
use Magento\Framework\ObjectManagerInterface;
7
use Magento\Framework\Registry;
8
9 View Code Duplication
class ProductFixtureRollback
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /**
12
     * @var Registry
13
     */
14
    private $registry;
15
    /**
16
     * @var ProductRepositoryInterface
17
     */
18
    private $productRepository;
19
20
    public function __construct(Registry $registry, ProductRepositoryInterface $productRepository)
21
    {
22
        $this->registry = $registry;
23
        $this->productRepository = $productRepository;
24
    }
25
26
    public static function create(ObjectManagerInterface $objectManager = null)
27
    {
28
        if ($objectManager === null) {
29
            $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
0 ignored issues
show
Bug introduced by
The type Magento\TestFramework\Helper\Bootstrap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
        }
31
        return new self(
32
            $objectManager->get(Registry::class),
33
            $objectManager->get(ProductRepositoryInterface::class)
34
        );
35
    }
36
37
    public function execute(ProductFixture ...$productFixtures)
38
    {
39
        $this->registry->unregister('isSecureArea');
40
        $this->registry->register('isSecureArea', true);
41
42
        foreach ($productFixtures as $productFixture) {
43
            $this->productRepository->deleteById($productFixture->getSku());
44
        }
45
46
        $this->registry->unregister('isSecureArea');
47
    }
48
}
49