OptionFixtureRollback   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 61
ccs 18
cts 18
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 6 1
A execute() 0 14 2
1
<?php
2
declare(strict_types=1);
3
4
namespace TddWizard\Fixtures\Catalog;
5
6
use Magento\Catalog\Model\Product;
7
use Magento\Eav\Api\AttributeOptionManagementInterface;
8
use Magento\Framework\Exception\InputException;
9
use Magento\Framework\Exception\NoSuchEntityException;
10
use Magento\Framework\Exception\StateException;
11
use Magento\Framework\Registry;
12
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...
13
14
/**
15
 * Roll back one or more options.
16
 *
17
 * @internal Use OptionFixture::rollback() instead.
18
 */
19
class OptionFixtureRollback
20
{
21
22
    /**
23
     * @var Registry
24
     */
25
    private $registry;
26
27
    /**
28
     * @var AttributeOptionManagementInterface
29
     */
30
    private $optionManagement;
31
32
    /**
33
     * OptionFixtureRollback constructor.
34
     *
35
     * @param Registry $registry
36
     * @param AttributeOptionManagementInterface $optionManagement
37
     */
38 6
    public function __construct(Registry $registry, AttributeOptionManagementInterface $optionManagement)
39
    {
40 6
        $this->registry = $registry;
41 6
        $this->optionManagement = $optionManagement;
42 6
    }
43
44
    /**
45
     * Create the object.
46
     *
47
     * @return OptionFixtureRollback
48
     */
49 6
    public static function create(): OptionFixtureRollback
50
    {
51 6
        $objectManager = Bootstrap::getObjectManager();
52 6
        return new self(
53 6
            $objectManager->get(Registry::class),
54 6
            $objectManager->get(AttributeOptionManagementInterface::class)
55
        );
56
    }
57
58
    /**
59
     * Remove the given option(s).
60
     *
61
     * @param OptionFixture ...$optionFixtures
62
     * @throws InputException
63
     * @throws NoSuchEntityException
64
     * @throws StateException
65
     */
66 6
    public function execute(OptionFixture ...$optionFixtures): void
67
    {
68 6
        $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

68
        /** @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...
69 6
        $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

69
        /** @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...
70
71 6
        foreach ($optionFixtures as $optionFixture) {
72 6
            $this->optionManagement->delete(
73 6
                Product::ENTITY,
0 ignored issues
show
Bug introduced by
Magento\Catalog\Model\Product::ENTITY of type string is incompatible with the type integer expected by parameter $entityType of Magento\Eav\Api\Attribut...mentInterface::delete(). ( Ignorable by Annotation )

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

73
                /** @scrutinizer ignore-type */ Product::ENTITY,
Loading history...
74 6
                $optionFixture->getAttributeCode(),
75 6
                $optionFixture->getOption()->getId()
76
            );
77
        }
78
79 6
        $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

79
        /** @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...
80 6
    }
81
}
82