Completed
Push — master ( 72bb06...9fb7ca )
by mw
33:54
created

RebuildPropertyStatistics::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 10
nc 2
nop 0
crap 2
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 19 and the first side effect is on line 7.

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
namespace SMW\Maintenance;
4
5
use SMW\ApplicationFactory;
6
7
$basePath = getenv( 'MW_INSTALL_PATH' ) !== false ? getenv( 'MW_INSTALL_PATH' ) : __DIR__ . '/../../..';
8
9
require_once $basePath . '/maintenance/Maintenance.php';
10
11
/**
12
 * Maintenance script for rebuilding the property usage statistics.
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.9
16
 *
17
 * @author Jeroen De Dauw < [email protected] >
18
 */
19
class RebuildPropertyStatistics extends \Maintenance {
20
21 2
	public function __construct() {
22 2
		$this->mDescription = 'Rebuild the property usage statistics (only works with SQLStore3 for now)';
23
24 2
		parent::__construct();
25 2
	}
26
27
	/**
28
	 * @see Maintenance::execute
29
	 */
30 2
	public function execute() {
31
32 2
		if ( !defined( 'SMW_VERSION' ) ) {
33
			$this->output( "You need to have SMW enabled in order to use this maintenance script!\n\n" );
34
			exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method execute() 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...
35
		}
36
37 2
		$applicationFactory = ApplicationFactory::getInstance();
38 2
		$maintenanceFactory = $applicationFactory->newMaintenanceFactory();
39
40 2
		$statisticsRebuilder = $maintenanceFactory->newPropertyStatisticsRebuilder(
41 2
			$applicationFactory->getStore(),
42 2
			array( $this, 'reportMessage' )
43
		);
44
45 2
		$statisticsRebuilder->rebuild();
46 2
	}
47
48
	/**
49
	 * @see Maintenance::reportMessage
50
	 *
51
	 * @since 1.9
52
	 *
53
	 * @param string $message
54
	 */
55 2
	public function reportMessage( $message ) {
56 2
		$this->output( $message );
57 2
	}
58
59
}
60
61
$maintClass = 'SMW\Maintenance\RebuildPropertyStatistics';
62
require_once ( RUN_MAINTENANCE_IF_MAIN );
63