Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
IPVersionInfoRetriever | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
5.07 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
retrieveFor | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | namespace MediaWiki\IPInfo\InfoRetriever; |
3 | |
4 | use MediaWiki\IPInfo\Info\IPVersionInfo; |
5 | use MediaWiki\User\UserIdentity; |
6 | use Wikimedia\IPUtils; |
7 | |
8 | class IPVersionInfoRetriever extends BaseInfoRetriever { |
9 | public const NAME = 'ipinfo-source-ipversion'; |
10 | |
11 | public function getName(): string { |
12 | return self::NAME; |
13 | } |
14 | |
15 | public function retrieveFor( UserIdentity $user, ?string $ip ): IPVersionInfo { |
16 | if ( $ip !== null ) { |
17 | if ( IPUtils::isIPv4( $ip ) ) { |
18 | return new IPVersionInfo( 'ipv4' ); |
19 | } |
20 | |
21 | if ( IPUtils::isIPv6( $ip ) ) { |
22 | return new IPVersionInfo( 'ipv6' ); |
23 | } |
24 | } |
25 | |
26 | return new IPVersionInfo( null ); |
27 | } |
28 | } |