SetupCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 15
dl 0
loc 48
rs 10
c 1
b 1
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 20 3
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2023
6
 */
7
8
9
namespace Aimeos\Shop\Command;
10
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Input\InputArgument;
13
14
15
/**
16
 * Command for initializing or updating the Aimeos database tables
17
 */
18
class SetupCommand extends AbstractCommand
19
{
20
	/**
21
	 * The name and signature of the console command.
22
	 *
23
	 * @var string
24
	 */
25
	protected $signature = 'aimeos:setup
26
		{site? : Site for updating database entries}
27
		{tplsite=default : Site used as template for creating the new one}
28
		{--q : Quiet}
29
		{--v=v : Verbosity level}
30
		{--option=* : Setup configuration, name and value are separated by colon like "setup/default/demo:1"}
31
	';
32
33
	/**
34
	 * The console command description.
35
	 *
36
	 * @var string
37
	 */
38
	protected $description = 'Initialize or update the Aimeos database tables';
39
40
41
	/**
42
	 * Execute the console command.
43
	 *
44
	 * @return mixed
45
	 */
46
	public function handle()
47
	{
48
		\Aimeos\MShop::cache( false );
49
		\Aimeos\MAdmin::cache( false );
50
51
		$template = $this->argument( 'tplsite' );
52
53
		if( ( $site = $this->argument( 'site' ) ) === null ) {
54
			$site = config( 'shop.mshop.locale.site', 'default' );
0 ignored issues
show
Bug introduced by
'shop.mshop.locale.site' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

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

54
			$site = config( /** @scrutinizer ignore-type */ 'shop.mshop.locale.site', 'default' );
Loading history...
Unused Code introduced by
The call to config() has too many arguments starting with 'default'. ( Ignorable by Annotation )

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

54
			$site = /** @scrutinizer ignore-call */ config( 'shop.mshop.locale.site', 'default' );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
55
		}
56
57
		$boostrap = $this->getLaravel()->make( 'aimeos' )->get();
58
		$ctx = $this->getLaravel()->make( 'aimeos.context' )->get( false, 'command' );
59
60
		$this->info( sprintf( 'Initializing or updating the Aimeos database tables for site "%1$s"', $site ) );
61
62
		\Aimeos\Setup::use( $boostrap )
63
			->verbose( $this->option( 'q' ) ? '' : $this->option( 'v' ) )
64
			->context( $this->addConfig( $ctx->setEditor( 'aimeos:setup' ) ) )
65
			->up( $site, $template );
66
	}
67
}
68