Passed
Push — master ( eac6cc...dea5f2 )
by Aimeos
23:16 queued 12:08
created

SetupCommand::setOptions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 * @subpackage Command
8
 */
9
10
11
namespace Aimeos\Shop\Command;
12
13
use Symfony\Component\Console\Input\InputOption;
14
use Symfony\Component\Console\Input\InputArgument;
15
16
17
/**
18
 * Command for initializing or updating the Aimeos database tables
19
 * @package laravel
20
 * @subpackage Command
21
 */
22
class SetupCommand extends AbstractCommand
23
{
24
	/**
25
	 * The name and signature of the console command.
26
	 *
27
	 * @var string
28
	 */
29
	protected $signature = 'aimeos:setup
30
		{site=default : Site for updating database entries}
31
		{tplsite=default : Site used as template for creating the new one}
32
		{--q : Quiet}
33
		{--v=vv : Verbosity level}
34
		{--option= : Setup configuration, name and value are separated by colon like "setup/default/demo:1"}
35
	';
36
37
	/**
38
	 * The console command description.
39
	 *
40
	 * @var string
41
	 */
42
	protected $description = 'Initialize or update the Aimeos database tables';
43
44
45
	/**
46
	 * Execute the console command.
47
	 *
48
	 * @return mixed
49
	 */
50
	public function handle()
51
	{
52
		\Aimeos\MShop::cache( false );
53
		\Aimeos\MAdmin::cache( false );
54
55
		$site = $this->argument( 'site' );
56
		$template = $this->argument( 'tplsite' );
57
58
		$boostrap = $this->getLaravel()->make( 'aimeos' )->get();
59
		$ctx = $this->getLaravel()->make( 'aimeos.context' )->get( false, 'command' )->setEditor( 'aimeos:setup' );
0 ignored issues
show
Unused Code introduced by
The assignment to $ctx is dead and can be removed.
Loading history...
60
61
		$this->info( sprintf( 'Initializing or updating the Aimeos database tables for site "%1$s"', $site ) );
0 ignored issues
show
Bug introduced by
It seems like $site can also be of type array; however, parameter $values of sprintf() does only seem to accept double|integer|string, 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

61
		$this->info( sprintf( 'Initializing or updating the Aimeos database tables for site "%1$s"', /** @scrutinizer ignore-type */ $site ) );
Loading history...
62
63
		\Aimeos\Setup::use( $boostrap, $this->getOptions() )
64
			->verbose( $this->option( 'q' ) ? '' : $this->option( 'v' ) )
65
			->up( $site, $template );
0 ignored issues
show
Bug introduced by
It seems like $site can also be of type array and null; however, parameter $site of Aimeos\Setup::up() does only seem to accept string, 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

65
			->up( /** @scrutinizer ignore-type */ $site, $template );
Loading history...
Bug introduced by
It seems like $template can also be of type array and null; however, parameter $template of Aimeos\Setup::up() does only seem to accept string, 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

65
			->up( $site, /** @scrutinizer ignore-type */ $template );
Loading history...
66
	}
67
68
69
	/**
70
	 * Returns the configuration options from the input object
71
	 *
72
	 * @return array Associative list of key/value pairs of configuration options
73
	 */
74
	protected function getOptions() : array
75
	{
76
		$map = [];
77
78
		foreach( (array) $this->option( 'option' ) as $option )
79
		{
80
			list( $name, $value ) = explode( ':', $option );
81
			$map[str_replace( '\\', '/', $name )] = $value;
82
		}
83
84
		return $map;
85
	}
86
}
87