Passed
Push — master ( eade66...a4d1b5 )
by Aimeos
03:55
created

CustomerAddFosUserTestData   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 4
b 0
f 0
dl 0
loc 58
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPostDependencies() 0 3 1
A getManager() 0 7 2
A migrate() 0 15 1
A getPreDependencies() 0 3 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014-2020
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Adds FOS user customer test data.
14
 */
15
class CustomerAddFosUserTestData extends \Aimeos\MW\Setup\Task\CustomerAddTestData
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'];
25
	}
26
27
28
	/**
29
	 * Returns the list of task names which depends on this task.
30
	 *
31
	 * @return string[] List of task names
32
	 */
33
	public function getPostDependencies() : array
34
	{
35
		return ['CustomerAddTestData'];
36
	}
37
38
39
	/**
40
	 * Adds customer test data
41
	 */
42
	public function migrate()
43
	{
44
		\Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Context\Item\Iface::class, $this->additional );
45
46
		$this->msg( 'Adding FosUser customer test data', 0 );
47
48
		$dbm = $this->additional->getDatabaseManager();
0 ignored issues
show
Bug introduced by
The method getDatabaseManager() does not exist on null. ( Ignorable by Annotation )

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

48
		/** @scrutinizer ignore-call */ 
49
  $dbm = $this->additional->getDatabaseManager();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
		$conn = $dbm->acquire( 'db-customer' );
50
		$conn->create( 'DELETE FROM "fos_user" WHERE "email" LIKE \'test%@example.com\'' )->execute()->finish();
51
		$dbm->release( $conn, 'db-customer' );
52
53
		$this->additional->setEditor( 'ai-fosuser:lib/custom' );
54
		$this->process( __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'customer.php' );
55
56
		$this->status( 'done' );
57
	}
58
59
60
	/**
61
	 * Returns the manager for the current setup task
62
	 *
63
	 * @param string $domain Domain name of the manager
64
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object
65
	 */
66
	protected function getManager( $domain )
67
	{
68
		if( $domain === 'customer' ) {
69
			return \Aimeos\MShop\Customer\Manager\Factory::create( $this->additional, 'FosUser' );
0 ignored issues
show
Bug introduced by
It seems like $this->additional can also be of type null; however, parameter $context of Aimeos\MShop\Customer\Manager\Factory::create() does only seem to accept Aimeos\MShop\Context\Item\Iface, maybe add an additional type check? ( Ignorable by Annotation )

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

69
			return \Aimeos\MShop\Customer\Manager\Factory::create( /** @scrutinizer ignore-type */ $this->additional, 'FosUser' );
Loading history...
70
		}
71
72
		return parent::getManager( $domain );
73
	}
74
}
75