Passed
Push — master ( 63bc59...352b21 )
by Aimeos
148:01 queued 75:12
created

AttributeAddTestData   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPreDependencies() 0 3 1
A getData() 0 9 2
A process() 0 20 2
A migrate() 0 10 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2020
7
 */
8
9
10
namespace Aimeos\MW\Setup\Task;
11
12
13
/**
14
 * Adds attribute test data and all items from other domains.
15
 */
16
class AttributeAddTestData extends \Aimeos\MW\Setup\Task\BaseAddTestData
17
{
18
	/**
19
	 * Returns the list of task names which this task depends on.
20
	 *
21
	 * @return string[] List of task names
22
	 */
23
	public function getPreDependencies() : array
24
	{
25
		return ['MShopSetLocale'];
26
	}
27
28
29
	/**
30
	 * Adds attribute test data.
31
	 */
32
	public function migrate()
33
	{
34
		\Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Context\Item\Iface::class, $this->additional );
35
36
		$this->msg( 'Adding attribute test data', 0 );
37
38
		$this->additional->setEditor( 'core:lib/mshoplib' );
39
		$this->process( $this->getData() );
40
41
		$this->status( 'done' );
42
	}
43
44
45
	/**
46
	 * Returns the test data array
47
	 *
48
	 * @return array Multi-dimensional array of test data
49
	 */
50
	protected function getData()
51
	{
52
		$path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'attribute.php';
53
54
		if( ( $testdata = include( $path ) ) == false ) {
55
			throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for attribute domain', $path ) );
56
		}
57
58
		return $testdata;
59
	}
60
61
62
	/**
63
	 * Adds the product data from the given array
64
	 *
65
	 * @param array Multi-dimensional array of test data
0 ignored issues
show
Documentation Bug introduced by
The doc comment Multi-dimensional at position 0 could not be parsed: Unknown type name 'Multi-dimensional' at position 0 in Multi-dimensional.
Loading history...
66
	 */
67
	protected function process( array $testdata )
68
	{
69
		$manager = $this->getManager( 'attribute' );
70
		$listManager = $manager->getSubManager( 'lists' );
71
		$propManager = $manager->getSubManager( 'property' );
72
73
		$manager->begin();
74
75
		$this->storeTypes( $testdata, ['attribute/type', 'attribute/lists/type', 'attribute/property/type'] );
76
77
		foreach( $testdata['attribute'] as $entry )
78
		{
79
			$item = $manager->create()->fromArray( $entry );
80
			$item = $this->addListData( $listManager, $item, $entry );
81
			$item = $this->addPropertyData( $propManager, $item, $entry );
0 ignored issues
show
Bug introduced by
$item of type Aimeos\MShop\Common\Item\ListRef\Iface is incompatible with the type Aimeos\MShop\Common\Item\PropertyRef\Iface expected by parameter $item of Aimeos\MW\Setup\Task\Bas...Data::addPropertyData(). ( Ignorable by Annotation )

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

81
			$item = $this->addPropertyData( $propManager, /** @scrutinizer ignore-type */ $item, $entry );
Loading history...
82
83
			$manager->save( $item );
84
		}
85
86
		$manager->commit();
87
	}
88
}
89