Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
56.25% covered (warning)
56.25%
9 / 16
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
InfoManager
90.00% covered (success)
90.00%
9 / 10
50.00% covered (danger)
50.00%
1 / 2
3.01
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 execute
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
2.02
1<?php
2
3namespace MediaWiki\IPInfo\Maintenance;
4
5use Maintenance;
6use MediaWiki\Json\FormatJson;
7use Wikimedia\IPUtils;
8
9$IP = getenv( 'MW_INSTALL_PATH' );
10if ( $IP === false ) {
11    $IP = __DIR__ . '/../../..';
12}
13require_once "$IP/maintenance/Maintenance.php";
14
15class InfoManager extends Maintenance {
16
17    public function __construct() {
18        parent::__construct();
19        $this->addDescription( 'Retrieve data for an IP address.' );
20        $this->addOption( 'ip', 'The IP address to use in the lookup.', true );
21        $this->requireExtension( 'IPInfo' );
22    }
23
24    public function execute() {
25        $ip = $this->getOption( 'ip' );
26        if ( !IPUtils::isValid( $ip ) ) {
27            $this->fatalError( "$ip is not a valid IP address." );
28        }
29        /** @var \MediaWiki\IPInfo\InfoManager $ipInfoManager */
30        $ipInfoManager = $this->getServiceContainer()->getService( 'IPInfoInfoManager' );
31        $result = $ipInfoManager->retrieveFromIP( $ip );
32        $this->output( FormatJson::encode( $result ) );
33    }
34}
35
36$maintClass = InfoManager::class;
37require_once RUN_MAINTENANCE_IF_MAIN;