66
77use GeoIp2 \Exception \AddressNotFoundException ;
88use GeoIp2 \Model \AnonymousIp ;
9+ use GeoIp2 \Model \AnonymousPlus ;
910use GeoIp2 \Model \Asn ;
1011use GeoIp2 \Model \City ;
1112use GeoIp2 \Model \ConnectionType ;
4445 */
4546class Reader implements ProviderInterface
4647{
47- private DbReader $ dbReader ;
48-
49- private string $ dbType ;
50-
51- /**
52- * @var array<string>
53- */
54- private array $ locales ;
48+ private readonly DbReader $ dbReader ;
49+ private readonly string $ dbType ;
5550
5651 /**
5752 * Constructor.
@@ -64,11 +59,11 @@ class Reader implements ProviderInterface
6459 */
6560 public function __construct (
6661 string $ filename ,
67- array $ locales = ['en ' ]
62+ /** @var array<string> */
63+ public readonly array $ locales = ['en ' ]
6864 ) {
6965 $ this ->dbReader = new DbReader ($ filename );
7066 $ this ->dbType = $ this ->dbReader ->metadata ()->databaseType ;
71- $ this ->locales = $ locales ;
7267 }
7368
7469 /**
@@ -78,6 +73,7 @@ public function __construct(
7873 *
7974 * @throws AddressNotFoundException if the address is not in the database
8075 * @throws InvalidDatabaseException if the database is corrupt or invalid
76+ * @throws \BadMethodCallException if this database type is not supported
8177 */
8278 public function city (string $ ipAddress ): City
8379 {
@@ -91,6 +87,7 @@ public function city(string $ipAddress): City
9187 *
9288 * @throws AddressNotFoundException if the address is not in the database
9389 * @throws InvalidDatabaseException if the database is corrupt or invalid
90+ * @throws \BadMethodCallException if this database type is not supported
9491 */
9592 public function country (string $ ipAddress ): Country
9693 {
@@ -104,6 +101,7 @@ public function country(string $ipAddress): Country
104101 *
105102 * @throws AddressNotFoundException if the address is not in the database
106103 * @throws InvalidDatabaseException if the database is corrupt or invalid
104+ * @throws \BadMethodCallException if this database type is not supported
107105 */
108106 public function anonymousIp (string $ ipAddress ): AnonymousIp
109107 {
@@ -114,13 +112,32 @@ public function anonymousIp(string $ipAddress): AnonymousIp
114112 );
115113 }
116114
115+ /**
116+ * This method returns a GeoIP Anonymous Plus model.
117+ *
118+ * @param string $ipAddress an IPv4 or IPv6 address as a string
119+ *
120+ * @throws AddressNotFoundException if the address is not in the database
121+ * @throws InvalidDatabaseException if the database is corrupt or invalid
122+ * @throws \BadMethodCallException if this database type is not supported
123+ */
124+ public function anonymousPlus (string $ ipAddress ): AnonymousPlus
125+ {
126+ return $ this ->flatModelFor (
127+ AnonymousPlus::class,
128+ 'GeoIP-Anonymous-Plus ' ,
129+ $ ipAddress
130+ );
131+ }
132+
117133 /**
118134 * This method returns a GeoLite2 ASN model.
119135 *
120136 * @param string $ipAddress an IPv4 or IPv6 address as a string
121137 *
122138 * @throws AddressNotFoundException if the address is not in the database
123139 * @throws InvalidDatabaseException if the database is corrupt or invalid
140+ * @throws \BadMethodCallException if this database type is not supported
124141 */
125142 public function asn (string $ ipAddress ): Asn
126143 {
@@ -138,6 +155,7 @@ public function asn(string $ipAddress): Asn
138155 *
139156 * @throws AddressNotFoundException if the address is not in the database
140157 * @throws InvalidDatabaseException if the database is corrupt or invalid
158+ * @throws \BadMethodCallException if this database type is not supported
141159 */
142160 public function connectionType (string $ ipAddress ): ConnectionType
143161 {
@@ -155,6 +173,7 @@ public function connectionType(string $ipAddress): ConnectionType
155173 *
156174 * @throws AddressNotFoundException if the address is not in the database
157175 * @throws InvalidDatabaseException if the database is corrupt or invalid
176+ * @throws \BadMethodCallException if this database type is not supported
158177 */
159178 public function domain (string $ ipAddress ): Domain
160179 {
@@ -172,6 +191,7 @@ public function domain(string $ipAddress): Domain
172191 *
173192 * @throws AddressNotFoundException if the address is not in the database
174193 * @throws InvalidDatabaseException if the database is corrupt or invalid
194+ * @throws \BadMethodCallException if this database type is not supported
175195 */
176196 public function enterprise (string $ ipAddress ): Enterprise
177197 {
@@ -185,6 +205,7 @@ public function enterprise(string $ipAddress): Enterprise
185205 *
186206 * @throws AddressNotFoundException if the address is not in the database
187207 * @throws InvalidDatabaseException if the database is corrupt or invalid
208+ * @throws \BadMethodCallException if this database type is not supported
188209 */
189210 public function isp (string $ ipAddress ): Isp
190211 {
0 commit comments