Passed
Push — master ( ae8cc8...b4d665 )
by Aimeos
04:50
created

GroupAddTestData   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 1
b 0
f 0
dl 0
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 22 4
A up() 0 6 1
A after() 0 3 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2023
6
 */
7
8
9
namespace Aimeos\Upscheme\Task;
10
11
12
/**
13
 * Adds customer test data.
14
 */
15
class GroupAddTestData extends 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 after() : array
23
	{
24
		return ['Group', 'MShopSetLocale'];
25
	}
26
27
28
	/**
29
	 * Adds customer test data.
30
	 */
31
	public function up()
32
	{
33
		$this->info( 'Adding group test data', 'vv' );
34
		$this->context()->setEditor( 'core' );
0 ignored issues
show
Bug introduced by
The method context() does not exist on Aimeos\Upscheme\Task\GroupAddTestData. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

34
		$this->/** @scrutinizer ignore-call */ 
35
         context()->setEditor( 'core' );
Loading history...
35
36
		$this->process();
37
	}
38
39
40
	/**
41
	 * Adds the customer data
42
	 *
43
	 * @throws \RuntimeException
44
	 */
45
	protected function process()
46
	{
47
		$path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'group.php';
48
49
		if( ( $testdata = include( $path ) ) == false ) {
50
			throw new \RuntimeException( sprintf( 'No file "%1$s" found for group domain', $path ) );
51
		}
52
53
		$manager = $this->getManager( 'group' );
54
		$manager->begin();
55
56
		$items = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $items is dead and can be removed.
Loading history...
57
		foreach( $testdata['group'] as $entry )
58
		{
59
			try {
60
				$manager->save( $manager->find( $entry['group.code'] )->fromArray( $entry ) );
61
			} catch( \Exception $e ) {
62
				$manager->save( $manager->create()->fromArray( $entry ), false );
63
			}
64
		}
65
66
		$manager->commit();
67
	}
68
}
69