Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
56.25% |
9 / 16 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
InfoManager | |
90.00% |
9 / 10 |
|
50.00% |
1 / 2 |
3.01 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
2.02 |
1 | <?php |
2 | |
3 | namespace MediaWiki\IPInfo\Maintenance; |
4 | |
5 | use MediaWiki\Json\FormatJson; |
6 | use MediaWiki\Maintenance\Maintenance; |
7 | use Wikimedia\IPUtils; |
8 | |
9 | $IP = getenv( 'MW_INSTALL_PATH' ); |
10 | if ( $IP === false ) { |
11 | $IP = __DIR__ . '/../../..'; |
12 | } |
13 | require_once "$IP/maintenance/Maintenance.php"; |
14 | |
15 | class 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->retrieveFor( $ip, $ip ); |
32 | $this->output( FormatJson::encode( $result ) ); |
33 | } |
34 | } |
35 | |
36 | $maintClass = InfoManager::class; |
37 | require_once RUN_MAINTENANCE_IF_MAIN; |