Completed
Push — master ( 4e3077...d2ec78 )
by Aimeos
15:45
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 24 and the first side effect is on line 10.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 */
7
8
9
if( php_sapi_name() != 'cli' ) {
10
	exit( 'Setup can only be started via command line for security reasons' );
11
}
12
13
ini_set( 'display_errors', 1 );
14
date_default_timezone_set( 'UTC' );
15
16
17
18
/**
19
 * Returns the command options given by the user
20
 *
21
 * @param array &$params List of parameters
22
 * @return array Associative list of option name and value(s)
23
 */
24 View Code Duplication
function getOptions( array &$params )
0 ignored issues
show
The function getOptions() has been defined more than once; this definition is ignored, only the first definition in cache.php (L24-59) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
{
26
	$options = array();
27
28
	foreach( $params as $key => $option )
29
	{
30
		if( $option === '--help' ) {
31
			usage();
32
		}
33
34
		if( strncmp( $option, '--', 2 ) === 0 && ( $pos = strpos( $option, '=', 2 ) ) !== false )
35
		{
36
			if( ( $name = substr( $option, 2, $pos - 2 ) ) !== false )
37
			{
38
				if( isset( $options[$name] ) )
39
				{
40
					$options[$name] = (array) $options[$name];
41
					$options[$name][] = substr( $option, $pos + 1 );
42
				}
43
				else
44
				{
45
					$options[$name] = substr( $option, $pos + 1 );
46
				}
47
48
				unset( $params[$key] );
49
			}
50
			else
51
			{
52
				printf( "Invalid option \"%1\$s\"\n", $option );
53
				usage();
54
			}
55
		}
56
	}
57
58
	return $options;
59
}
60
61
62
/**
63
 * Returns the configuration based on the given options
64
 *
65
 * @param array $options Associative list of given options
66
 * @return array Multi-dimensional array of configuration settings
67
 */
68
function getConfig( array $options )
69
{
70
	$config = array();
71
72 View Code Duplication
	if( isset( $options['config'] ) )
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
	{
74
		foreach( (array) $options['config'] as $path )
75
		{
76
			if( is_file( $path ) ) {
77
				$config = array_replace_recursive( $config, require $path );
78
			} else {
79
				$confPaths[] = $path;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$confPaths was never initialized. Although not strictly required by PHP, it is generally a good practice to add $confPaths = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
80
			}
81
		}
82
	}
83
84
	return $config;
85
}
86
87
88
/**
89
 * Returns a new context object
90
 *
91
 * @param \Interop\Container\ContainerInterface $container Dependency injection container
92
 * @return \Aimeos\MShop\Context\Item\Standard Context object
93
 */
94
function getContext( \Interop\Container\ContainerInterface $container )
0 ignored issues
show
The function getContext() has been defined more than once; this definition is ignored, only the first definition in cache.php (L69-97) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
95
{
96
	$aimeos = $container->get( 'aimeos' );
97
	$context = $container->get( 'aimeos_context' )->get( false );
98
99
	$env = \Slim\Http\Environment::mock();
100
	$request = \Slim\Http\Request::createFromEnvironment( $env );
101
	$response = new \Slim\Http\Response();
102
103
	$tmplPaths = $aimeos->getCustomPaths( 'controller/jobs/templates' );
104
	$view = $container->get( 'aimeos_view' )->create( $request, $response, array(), $tmplPaths );
105
106
	$langManager = \Aimeos\MShop\Factory::createManager( $context, 'locale/language' );
107
	$langids = array_keys( $langManager->searchItems( $langManager->createSearch( true ) ) );
108
	$i18n = $container->get( 'aimeos_i18n' )->get( $langids );
109
110
	$context->setEditor( 'aimeos:jobs' );
111
	$context->setView( $view );
112
	$context->setI18n( $i18n );
113
114
	return $context;
115
}
116
117
118
/**
119
 * Returns the locale site items for the given site code string
120
 *
121
 * @param \Aimeos\MShop\Context\Item\Iface $ctx Context object
122
 * @param string|null $sites List of site codes separated by a space
123
 */
124 View Code Duplication
function getSiteItems( \Aimeos\MShop\Context\Item\Iface $ctx, $sites )
0 ignored issues
show
The function getSiteItems() has been defined more than once; this definition is ignored, only the first definition in cache.php (L106-120) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
{
126
	$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $ctx );
127
	$manager = $localeManager->getSubManager( 'site' );
128
	$search = $manager->createSearch();
129
130
	if( is_scalar( $sites ) && $sites != '' ) {
131
		$sites = explode( ' ', $sites );
132
	}
133
134
	if( !empty( $sites ) ) {
135
		$search->setConditions( $search->compare( '==', 'locale.site.code', $sites ) );
136
	}
137
138
	return $manager->searchItems( $search );
139
}
140
141
142
/**
143
 * Removes the cached data for the given sites
144
 *
145
 * @param \Aimeos\Bootstrap $aimeos Aimeos bootstrap object
146
 * @param \Aimeos\MShop\Context\Item\Iface $ctx Context object
147
 * @param array $siteItems List of site items implementing \Aimeos\MShop\Locale\Site\Iface
148
 */
149
function execute( \Aimeos\Bootstrap $aimeos, \Aimeos\MShop\Context\Item\Iface $ctx, array $siteItems, $jobs )
150
{
151
	$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $ctx );
152
153
	foreach( $siteItems as $siteItem )
154
	{
155
		$localeItem = $localeManager->bootstrap( $siteItem->getCode(), 'en', '', false );
156
		$ctx->setLocale( $localeItem );
157
158
		printf( "Executing the Aimeos jobs for \"%s\"\n", $siteItem->getCode() );
159
160
		foreach( (array) explode( ' ', $jobs ) as $jobname ) {
161
			\Aimeos\Controller\Jobs\Factory::createController( $ctx, $aimeos, $jobname )->run();
162
		}
163
	}
164
}
165
166
167
/**
168
 * Prints the command usage and options, exits the program after printing
169
 */
170
function usage()
0 ignored issues
show
The function usage() has been defined more than once; this definition is ignored, only the first definition in cache.php (L153-157) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
171
{
172
	printf( "Usage: php job.php [--extdir=<path>]* [--config=<path>|<file>]* \"job1 [job2]*\" [\"sitecode1 [sitecode2]*\"]\n" );
173
	exit( 1 );
0 ignored issues
show
Coding Style Compatibility introduced by
The function usage() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
174
}
175
176
177
178
try
179
{
180
	$params = $_SERVER['argv'];
181
	array_shift( $params );
182
183
	$options = getOptions( $params );
184
185
	if( ( $jobs = array_shift( $params ) ) === null ) {
186
		usage();
187
	}
188
189
	$sites = array_shift( $params );
190
	$config = getConfig( $options );
191
192
	require 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
193
194
	$app = new \Slim\App( $config );
195
	$aimeos = new \Aimeos\Slim\Bootstrap( $app, $config );
196
	$aimeos->setup( ( isset( $options['extdir'] ) ? $options['extdir'] : './ext' ) );
0 ignored issues
show
The call to the method Aimeos\Slim\Bootstrap::setup() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
197
198
	$container = $app->getContainer();
199
	$context = getContext( $container );
0 ignored issues
show
The call to getContext() misses a required argument $options.

This check looks for function calls that miss required arguments.

Loading history...
$container is of type object<Interop\Container\ContainerInterface>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
200
201
	$siteItems = getSiteItems( $context, $sites );
202
	execute( $container->get( 'aimeos' ), $context, $siteItems, $jobs );
203
}
204
catch( \Throwable $t )
0 ignored issues
show
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
205
{
206
	echo "\n\nCaught PHP error while processing setup";
207
	echo "\n\nMessage:\n";
208
	echo $t->getMessage();
209
	echo "\n\nStack trace:\n";
210
	echo $t->getTraceAsString();
211
	echo "\n\n";
212
	exit( 1 );
213
}
214
catch( \Exception $e )
215
{
216
	echo "\n\nCaught exception while processing setup";
217
	echo "\n\nMessage:\n";
218
	echo $e->getMessage();
219
	echo "\n\nStack trace:\n";
220
	echo $e->getTraceAsString();
221
	echo "\n\n";
222
	exit( 1 );
223
}
224