diff --git a/.github/workflows/clang-analyzer.yml b/.github/workflows/clang-analyzer.yml
index 030096b6..576b5d88 100644
--- a/.github/workflows/clang-analyzer.yml
+++ b/.github/workflows/clang-analyzer.yml
@@ -14,7 +14,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: 8.1
+ php-version: 8.4
tools: composer, phpize
- name: Checkout
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 10118677..aacd8c40 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -14,7 +14,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: 8.1
+ php-version: 8.3
- name: Checkout
uses: actions/checkout@v4
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 54638949..811c2530 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -14,15 +14,20 @@ jobs:
matrix:
arch: ["amd64", "i386"]
operating-system: [ubuntu-latest]
- php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
- php-extensions: ['bcmath', 'gmp']
- name: "PHP ${{ matrix.php-versions }} (with ${{ matrix.php-extensions }}) test on ${{ matrix.operating-system }}/${{ matrix.arch }}"
+ php-version: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
+ php-extension: ['bcmath', 'gmp']
+ exclude:
+ # We are getting weird libxml2 failures on this combo
+ - arch: "i386"
+ php-version: 8.4
+
+ name: "PHP ${{ matrix.php-version }} (with ${{ matrix.php-extension }}) test on ${{ matrix.operating-system }}/${{ matrix.arch }}"
steps:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
- php-version: ${{ matrix.php-versions }}
- extensions: "mbstring, intl, ${{ matrix.php-extensions }}"
+ php-version: ${{ matrix.php-version }}
+ extensions: "mbstring, intl, ${{ matrix.php-extension }}"
tools: "composer, phpize"
- name: Checkout
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 41331064..40d89d42 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,11 +1,12 @@
CHANGELOG
=========
-1.12.0
+1.12.0 (2024-11-14)
-------------------
* Improve the error handling when the user tries to open a directory
with the pure PHP reader.
+* Improve the typehints on arrays in the PHPDocs.
1.11.1 (2023-12-01)
-------------------
diff --git a/README.md b/README.md
index fa5693a2..afefc3fd 100644
--- a/README.md
+++ b/README.md
@@ -180,6 +180,6 @@ The MaxMind DB Reader PHP API uses [Semantic Versioning](https://semver.org/).
## Copyright and License ##
-This software is Copyright (c) 2014-2023 by MaxMind, Inc.
+This software is Copyright (c) 2014-2024 by MaxMind, Inc.
This is free software, licensed under the Apache License, Version 2.0.
diff --git a/ext/php_maxminddb.h b/ext/php_maxminddb.h
index 8acb282f..b5261b8d 100644
--- a/ext/php_maxminddb.h
+++ b/ext/php_maxminddb.h
@@ -15,7 +15,7 @@
#ifndef PHP_MAXMINDDB_H
#define PHP_MAXMINDDB_H 1
-#define PHP_MAXMINDDB_VERSION "1.11.1"
+#define PHP_MAXMINDDB_VERSION "1.12.0"
#define PHP_MAXMINDDB_EXTNAME "maxminddb"
extern zend_module_entry maxminddb_module_entry;
diff --git a/package.xml b/package.xml
index e7b32773..5fe5cb84 100644
--- a/package.xml
+++ b/package.xml
@@ -14,19 +14,19 @@
goschwald@maxmind.com
yes
- 2023-12-01
+ 2024-11-14
- 1.11.1
- 1.11.1
+ 1.12.0
+ 1.12.0
stable
stable
Apache License 2.0
- * Resolve warnings when compiling the C extension.
-* Fix various type issues detected by PHPStan level. Pull request by
- LauraTaylorUK. GitHub #160.
+ * Improve the error handling when the user tries to open a directory
+ with the pure PHP reader.
+* Improve the typehints on arrays in the PHPDocs.
diff --git a/phpstan.neon b/phpstan.neon
index ee1616db..63aadbac 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -3,5 +3,3 @@ parameters:
paths:
- src
- tests
- checkMissingIterableValueType: false
-
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index dbab7d98..f099f374 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,15 +1,13 @@
-
-
-
-
- ./tests/MaxMind/Db/Test/
-
-
-
-
-
- ./src/MaxMind/Db/
-
-
+
+
+
+ ./src/MaxMind/Db/
+
+
+
+
+ ./tests/MaxMind/Db/Test/
+
+
diff --git a/src/MaxMind/Db/Reader.php b/src/MaxMind/Db/Reader.php
index c7a6a226..12c6b095 100644
--- a/src/MaxMind/Db/Reader.php
+++ b/src/MaxMind/Db/Reader.php
@@ -149,8 +149,8 @@ public function get(string $ipAddress)
* if the database is invalid or there is an error reading
* from it
*
- * @return array an array where the first element is the record and the
- * second the network prefix length for the record
+ * @return array{0:mixed, 1:int} an array where the first element is the record and the
+ * second the network prefix length for the record
*/
public function getWithPrefixLen(string $ipAddress): array
{
@@ -174,6 +174,9 @@ public function getWithPrefixLen(string $ipAddress): array
return [$this->resolveDataPointer($pointer), $prefixLen];
}
+ /**
+ * @return array{0:int, 1:int}
+ */
private function findAddressInTree(string $ipAddress): array
{
$packedAddr = @inet_pton($ipAddress);
diff --git a/src/MaxMind/Db/Reader/Decoder.php b/src/MaxMind/Db/Reader/Decoder.php
index 44eee622..1bb67316 100644
--- a/src/MaxMind/Db/Reader/Decoder.php
+++ b/src/MaxMind/Db/Reader/Decoder.php
@@ -63,6 +63,9 @@ public function __construct(
$this->switchByteOrder = $this->isPlatformLittleEndian();
}
+ /**
+ * @return array
+ */
public function decode(int $offset): array
{
$ctrlByte = \ord(Util::read($this->fileStream, $offset, 1));
@@ -110,6 +113,8 @@ public function decode(int $offset): array
/**
* @param int<0, max> $size
+ *
+ * @return array{0:mixed, 1:int}
*/
private function decodeByType(int $type, int $offset, int $size): array
{
@@ -167,6 +172,9 @@ private function verifySize(int $expected, int $actual): void
}
}
+ /**
+ * @return array{0:array, 1:int}
+ */
private function decodeArray(int $size, int $offset): array
{
$array = [];
@@ -247,6 +255,9 @@ private function decodeInt32(string $bytes, int $size): int
return $int;
}
+ /**
+ * @return array{0:array, 1:int}
+ */
private function decodeMap(int $size, int $offset): array
{
$map = [];
@@ -260,6 +271,9 @@ private function decodeMap(int $size, int $offset): array
return [$map, $offset];
}
+ /**
+ * @return array{0:int, 1:int}
+ */
private function decodePointer(int $ctrlByte, int $offset): array
{
$pointerSize = (($ctrlByte >> 3) & 0x3) + 1;
@@ -378,6 +392,9 @@ private function decodeUint(string $bytes, int $byteLength)
return $integerAsString;
}
+ /**
+ * @return array{0:int, 1:int}
+ */
private function sizeFromCtrlByte(int $ctrlByte, int $offset): array
{
$size = $ctrlByte & 0x1F;
diff --git a/src/MaxMind/Db/Reader/Metadata.php b/src/MaxMind/Db/Reader/Metadata.php
index 40fa9f61..9cade222 100644
--- a/src/MaxMind/Db/Reader/Metadata.php
+++ b/src/MaxMind/Db/Reader/Metadata.php
@@ -48,7 +48,7 @@ class Metadata
* in that language as a UTF-8 string. May be undefined for some
* databases.
*
- * @var array
+ * @var array
*/
public $description;
@@ -65,7 +65,7 @@ class Metadata
* may contain data items that have been localized to some or all of
* these languages. This may be undefined.
*
- * @var array
+ * @var array
*/
public $languages;
@@ -95,6 +95,9 @@ class Metadata
*/
public $searchTreeSize;
+ /**
+ * @param array $metadata
+ */
public function __construct(array $metadata)
{
if (\func_num_args() !== 1) {
diff --git a/tests/MaxMind/Db/Test/Reader/DecoderTest.php b/tests/MaxMind/Db/Test/Reader/DecoderTest.php
index 7f2fd333..e9354526 100644
--- a/tests/MaxMind/Db/Test/Reader/DecoderTest.php
+++ b/tests/MaxMind/Db/Test/Reader/DecoderTest.php
@@ -291,6 +291,9 @@ private function bytes(): array
return $bytes;
}
+ /**
+ * @return array>
+ */
public function generateLargeUint(int $bits): array
{
$ctrlByte = $bits === 64 ? 0x2 : 0x3;
@@ -303,7 +306,14 @@ public function generateLargeUint(int $bits): array
for ($power = 1; $power <= $bits / 8; ++$power) {
if (\extension_loaded('gmp')) {
- $expected = gmp_strval(gmp_sub(gmp_pow('2', 8 * $power), '1'));
+ // This is to work around the limit added to gmp_pow here:
+ // https://github.com/php/php-src/commit/e0a0e216a909dc4ee4ea7c113a5f41d49525f02e
+ $v = 1;
+ for ($i = 0; $i < $power; $i++) {
+ $v = gmp_mul($v, 256);
+ }
+
+ $expected = gmp_strval(gmp_sub($v, '1'));
} elseif (\extension_loaded('bcmath')) {
$expected = bcsub(bcpow('2', (string) (8 * $power)), '1');
} else {
@@ -384,6 +394,9 @@ public function testUint128(): void
$this->validateTypeDecoding('uint128', $this->generateLargeUint(128));
}
+ /**
+ * @param array $tests
+ */
private function validateTypeDecoding(string $type, array $tests): void
{
foreach ($tests as $expected => $input) {
@@ -391,6 +404,9 @@ private function validateTypeDecoding(string $type, array $tests): void
}
}
+ /**
+ * @param array $tests
+ */
private function validateTypeDecodingList(string $type, array $tests): void
{
foreach ($tests as $test) {
diff --git a/tests/MaxMind/Db/Test/ReaderTest.php b/tests/MaxMind/Db/Test/ReaderTest.php
index 5c05fc02..47cf419d 100644
--- a/tests/MaxMind/Db/Test/ReaderTest.php
+++ b/tests/MaxMind/Db/Test/ReaderTest.php
@@ -364,12 +364,12 @@ public function testMetadataArgs(): void
public function testClose(): void
{
+ $this->expectNotToPerformAssertions();
+
$reader = new Reader(
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
);
$reader->close();
-
- $this->assertTrue(true);
}
public function testCloseArgs(): void