Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/clang-analyzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion ext/php_maxminddb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
<email>[email protected]</email>
<active>yes</active>
</lead>
<date>2023-12-01</date>
<date>2024-11-14</date>
<version>
<release>1.11.1</release>
<api>1.11.1</api>
<release>1.12.0</release>
<api>1.12.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="https://github.com/maxmind/MaxMind-DB-Reader-php/blob/main/LICENSE">Apache License 2.0</license>
<notes>* Resolve warnings when compiling the C extension.
* Fix various type issues detected by PHPStan level. Pull request by
LauraTaylorUK. GitHub #160.</notes>
<notes>* 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.</notes>
<contents>
<dir name="/">
<file role="doc" name="LICENSE"/>
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ parameters:
paths:
- src
- tests
checkMissingIterableValueType: false

24 changes: 11 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="MaxMind DB Test Suite">
<directory suffix="Test.php">./tests/MaxMind/Db/Test/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./src/MaxMind/Db/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src/MaxMind/Db/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="MaxMind DB Test Suite">
<directory suffix="Test.php">./tests/MaxMind/Db/Test/</directory>
</testsuite>
</testsuites>
</phpunit>
7 changes: 5 additions & 2 deletions src/MaxMind/Db/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions src/MaxMind/Db/Reader/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public function __construct(
$this->switchByteOrder = $this->isPlatformLittleEndian();
}

/**
* @return array<mixed>
*/
public function decode(int $offset): array
{
$ctrlByte = \ord(Util::read($this->fileStream, $offset, 1));
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -167,6 +172,9 @@ private function verifySize(int $expected, int $actual): void
}
}

/**
* @return array{0:array<mixed>, 1:int}
*/
private function decodeArray(int $size, int $offset): array
{
$array = [];
Expand Down Expand Up @@ -247,6 +255,9 @@ private function decodeInt32(string $bytes, int $size): int
return $int;
}

/**
* @return array{0:array<string, mixed>, 1:int}
*/
private function decodeMap(int $size, int $offset): array
{
$map = [];
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/MaxMind/Db/Reader/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Metadata
* in that language as a UTF-8 string. May be undefined for some
* databases.
*
* @var array
* @var array<string, string>
*/
public $description;

Expand All @@ -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<string>
*/
public $languages;

Expand Down Expand Up @@ -95,6 +95,9 @@ class Metadata
*/
public $searchTreeSize;

/**
* @param array<string, mixed> $metadata
*/
public function __construct(array $metadata)
{
if (\func_num_args() !== 1) {
Expand Down
18 changes: 17 additions & 1 deletion tests/MaxMind/Db/Test/Reader/DecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ private function bytes(): array
return $bytes;
}

/**
* @return array<int, array<int>>
*/
public function generateLargeUint(int $bits): array
{
$ctrlByte = $bits === 64 ? 0x2 : 0x3;
Expand All @@ -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 {
Expand Down Expand Up @@ -384,13 +394,19 @@ public function testUint128(): void
$this->validateTypeDecoding('uint128', $this->generateLargeUint(128));
}

/**
* @param array<mixed> $tests
*/
private function validateTypeDecoding(string $type, array $tests): void
{
foreach ($tests as $expected => $input) {
$this->checkDecoding($type, $input, $expected);
}
}

/**
* @param array<mixed> $tests
*/
private function validateTypeDecodingList(string $type, array $tests): void
{
foreach ($tests as $test) {
Expand Down
4 changes: 2 additions & 2 deletions tests/MaxMind/Db/Test/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down