ProductFixtureRollback::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace TddWizard\Fixtures\Catalog;
5
6
use Magento\Catalog\Api\ProductRepositoryInterface;
7
use Magento\Framework\Exception\LocalizedException;
8
use Magento\Framework\Registry;
9
use Magento\TestFramework\Helper\Bootstrap;
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...
10
11
/**
12
 * @internal Use ProductFixture::rollback() or ProductFixturePool::rollback() instead
13
 */
14
class ProductFixtureRollback
15
{
16
    /**
17
     * @var Registry
18
     */
19
    private $registry;
20
21
    /**
22
     * @var ProductRepositoryInterface
23
     */
24
    private $productRepository;
25
26 14
    public function __construct(Registry $registry, ProductRepositoryInterface $productRepository)
27
    {
28 14
        $this->registry = $registry;
29 14
        $this->productRepository = $productRepository;
30 14
    }
31
32 14
    public static function create(): ProductFixtureRollback
33
    {
34 14
        $objectManager = Bootstrap::getObjectManager();
35 14
        return new self(
36 14
            $objectManager->get(Registry::class),
37 14
            $objectManager->get(ProductRepositoryInterface::class)
38
        );
39
    }
40
41
    /**
42
     * @param ProductFixture ...$productFixtures
43
     * @throws LocalizedException
44
     */
45 14
    public function execute(ProductFixture ...$productFixtures): void
46
    {
47 14
        $this->registry->unregister('isSecureArea');
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Registry::unregister() has been deprecated: 102.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

47
        /** @scrutinizer ignore-deprecated */ $this->registry->unregister('isSecureArea');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
48 14
        $this->registry->register('isSecureArea', true);
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Registry::register() has been deprecated: 102.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

48
        /** @scrutinizer ignore-deprecated */ $this->registry->register('isSecureArea', true);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
49
50 14
        foreach ($productFixtures as $productFixture) {
51 14
            $this->productRepository->deleteById($productFixture->getSku());
52
        }
53
54 14
        $this->registry->unregister('isSecureArea');
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Registry::unregister() has been deprecated: 102.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

54
        /** @scrutinizer ignore-deprecated */ $this->registry->unregister('isSecureArea');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
55 14
    }
56
}
57