ExportSites   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B execute() 0 22 4
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 15 and the first side effect is on line 3.

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
$basePath = getenv( 'MW_INSTALL_PATH' ) !== false ? getenv( 'MW_INSTALL_PATH' ) : __DIR__ . '/..';
4
5
require_once $basePath . '/maintenance/Maintenance.php';
6
7
/**
8
 * Maintenance script for exporting site definitions from XML into the sites table.
9
 *
10
 * @since 1.25
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Daniel Kinzler
14
 */
15
class ExportSites extends Maintenance {
16
17
	public function __construct() {
18
		$this->addDescription( 'Exports site definitions the sites table to XML file' );
19
20
		$this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.txt). ' .
21
			'Use "php://stdout" to write to stdout.', true
22
		);
23
24
		parent::__construct();
25
	}
26
27
	/**
28
	 * Do the actual work. All child classes will need to implement this
29
	 */
30
	public function execute() {
31
		$file = $this->getArg( 0 );
32
33
		if ( $file === 'php://output' || $file === 'php://stdout' ) {
34
			$this->mQuiet = true;
35
		}
36
37
		$handle = fopen( $file, 'w' );
38
39
		if ( !$handle ) {
40
			$this->error( "Failed to open $file for writing.\n", 1 );
41
		}
42
43
		$exporter = new SiteExporter( $handle );
44
45
		$siteLookup = \MediaWiki\MediaWikiServices::getInstance()->getSiteLookup();
46
		$exporter->exportSites( $siteLookup->getSites() );
47
48
		fclose( $handle );
49
50
		$this->output( "Exported sites to " . realpath( $file ) . ".\n" );
51
	}
52
53
}
54
55
$maintClass = 'ExportSites';
56
require_once RUN_MAINTENANCE_IF_MAIN;
57