Passed
Push — master ( cb118d...17427a )
by Aimeos
05:39
created

SupplierAddTestData   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 9 2
A migrate() 0 10 1
A getPreDependencies() 0 3 1
A process() 0 17 2
A getManager() 0 7 2
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2020
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Adds supplier test data and all items from other domains.
14
 */
15
class SupplierAddTestData extends \Aimeos\MW\Setup\Task\BaseAddTestData
16
{
17
	/**
18
	 * Returns the list of task names which this task depends on.
19
	 *
20
	 * @return string[] List of task names
21
	 */
22
	public function getPreDependencies() : array
23
	{
24
		return ['MShopSetLocale', 'ProductAddTestData'];
25
	}
26
27
28
	/**
29
	 * Adds supplier test data.
30
	 */
31
	public function migrate()
32
	{
33
		\Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Context\Item\Iface::class, $this->additional );
34
35
		$this->msg( 'Adding supplier test data', 0 );
36
37
		$this->additional->setEditor( 'core:lib/mshoplib' );
38
		$this->process( $this->getData() );
39
40
		$this->status( 'done' );
41
	}
42
43
44
	/**
45
	 * Returns the test data array
46
	 *
47
	 * @return array Multi-dimensional array of test data
48
	 */
49
	protected function getData()
50
	{
51
		$path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'supplier.php';
52
53
		if( ( $testdata = include( $path ) ) == false ) {
54
			throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for supplier domain', $path ) );
55
		}
56
57
		return $testdata;
58
	}
59
60
61
	/**
62
	 * Returns the manager for the current setup task
63
	 *
64
	 * @param string $domain Domain name of the manager
65
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object
66
	 */
67
	protected function getManager( $domain )
68
	{
69
		if( $domain === 'supplier' ) {
70
			return \Aimeos\MShop\Supplier\Manager\Factory::create( $this->additional, 'Standard' );
71
		}
72
73
		return parent::getManager( $domain );
74
	}
75
76
77
	/**
78
	 * Adds the supplier data from the given array
79
	 *
80
	 * @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...
81
	 */
82
	protected function process( array $testdata )
83
	{
84
		$manager = $this->getManager( 'supplier' );
85
		$listManager = $manager->getSubManager( 'lists' );
86
		$addrManager = $manager->getSubManager( 'address' );
87
88
		$manager->begin();
89
		$this->storeTypes( $testdata, ['supplier/lists/type'] );
90
		$manager->commit();
91
92
		foreach( $testdata['supplier'] ?? [] as $entry )
93
		{
94
			$item = $manager->create()->fromArray( $entry );
95
			$item = $this->addListData( $listManager, $item, $entry );
96
			$item = $this->addAddressData( $addrManager, $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\AddressRef\Iface expected by parameter $item of Aimeos\MW\Setup\Task\Bas...tData::addAddressData(). ( Ignorable by Annotation )

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

96
			$item = $this->addAddressData( $addrManager, /** @scrutinizer ignore-type */ $item, $entry );
Loading history...
97
98
			$manager->save( $item );
99
		}
100
	}
101
}
102