Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
8 / 8
InfoManager
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
8 / 8
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 retrieveFromIP
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
<?php
namespace MediaWiki\IPInfo;
use MediaWiki\IPInfo\InfoRetriever\InfoRetriever;
use Wikimedia\IPUtils;
class InfoManager {
    /** @var InfoRetriever[] */
    private $retrievers;
    /**
     * @param InfoRetriever[] $retrievers
     */
    public function __construct(
        array $retrievers
    ) {
        $this->retrievers = $retrievers;
    }
    /**
     * Retrieve info about an IP address.
     *
     * TODO: Make this return a domain object, e.g. InfoManagerResponse.
     *
     * @param string $ip
     * @return array
     */
    public function retrieveFromIP( string $ip ): array {
        $data = [];
        foreach ( $this->retrievers as $retriever ) {
            $data[$retriever->getName()] = $retriever->retrieveFromIP( $ip );
        }
        $ip = IPUtils::prettifyIP( $ip );
        return [
            'subject' => $ip,
            'data' => $data,
        ];
    }
}