Skip to content

Commit 18f14d9

Browse files
authored
Merge pull request #677 from giggsey/v9-upgrades
- PHP 8.1 min - PHPStan level 7 - Strong types throughout - Enums instead of const classes
2 parents a83e58e + 000ff17 commit 18f14d9

File tree

1,219 files changed

+280995
-284366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,219 files changed

+280995
-284366
lines changed

.gitattributes

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ tests/ export-ignore
44
.editorconfig export-ignore
55
.gitattributes export-ignore
66
.gitignore export-ignore
7-
.styleci.yml export-ignore
8-
.travis.yml export-ignore
7+
.php-cs-fixer.dist.php export-ignore
98
build.xml export-ignore
10-
libphonenumber-for-php.spec export-ignore
119
phpunit.xml.dist export-ignore
12-
phpunit export-ignore
1310
.github/ export-ignore
1411
src/CountryCodeToRegionCodeMapForTesting.php export-ignore
15-
12+
phpstan.neon.dist export-ignore
13+
infection.json5 export-ignore
1614

1715
* text=auto

.github/workflows/ci.yml

Lines changed: 19 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Continuous Integration"
1+
name: "Tests"
22

33
on:
44
push:
@@ -8,76 +8,37 @@ on:
88
paths-ignore:
99
- 'docs/**'
1010

11-
env:
12-
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --no-suggest --prefer-dist"
13-
COVERAGE_FLAGS: "--coverage-text --coverage-clover build/logs/clover.xml"
14-
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: "1"
15-
1611
jobs:
1712
tests:
18-
name: PHP ${{ matrix.php-version }}
13+
name: PHP ${{ matrix.php-version }} - ${{ matrix.composer }}
1914
runs-on: ubuntu-latest
2015
strategy:
16+
fail-fast: false
2117
matrix:
22-
php-version:
23-
- "7.4"
24-
- "8.0"
25-
- "8.1"
26-
- "8.2"
27-
- "8.3"
28-
- "8.4"
29-
include:
30-
- php-version: 8.3
31-
coverage: coverage
18+
php-version: [8.1, 8.2, 8.3, 8.4]
19+
composer: [highest, lowest]
20+
3221
steps:
3322
- name: Checkout
34-
uses: actions/checkout@v2
35-
with:
36-
fetch-depth: 10
23+
uses: actions/checkout@v4
24+
3725
- name: Setup PHP, with composer and extensions
3826
uses: shivammathur/setup-php@v2
3927
with:
4028
php-version: ${{ matrix.php-version }}
4129
extensions: dom
4230
coverage: xdebug
43-
env:
44-
update: true
45-
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
- name: Setup Problem Matchers for PHPUnit
47-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
48-
- name: Get composer cache directory
49-
id: composer-cache
50-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
51-
- name: Cache composer dependencies
52-
uses: actions/cache@v1
53-
with:
54-
path: ${{ steps.composer-cache.outputs.dir }}
55-
key: ${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
56-
restore-keys: ${{ matrix.php-version }}-composer-
57-
- name: Install Composer
58-
uses: nick-invision/retry@v1
31+
tools: composer:v2
32+
33+
- uses: "ramsey/composer-install@v3"
5934
with:
60-
timeout_minutes: 10
61-
max_attempts: 3
62-
command: composer update ${{ env.COMPOSER_FLAGS }}
35+
dependency-versions: "${{ matrix.composer }}"
36+
6337
- name: composer validate
6438
run: composer validate --strict
65-
- name: Test with phpunit (with coverage)
66-
id: phpunit-coverage
67-
if: "matrix.coverage == 'coverage'"
68-
run: vendor/bin/phpunit --verbose ${{ env.COVERAGE_FLAGS }}
69-
- name: Test with phpunit (without coverage)
70-
if: "matrix.coverage != 'coverage'"
71-
run: vendor/bin/phpunit --verbose
72-
- name: Submit Coveralls
73-
if: steps.phpunit-coverage.outcome == 'success'
74-
uses: nick-invision/retry@v1
75-
with:
76-
timeout_minutes: 10
77-
max_attempts: 3
78-
command: |
79-
[[ -f vendor/bin/php-coveralls ]] && COVERALLS_PATH=vendor/bin/php-coveralls || COVERALLS_PATH=vendor/bin/coveralls
80-
[[ -n $COVERALLS_REPO_TOKEN ]] && php $COVERALLS_PATH -v --exclude-no-stmt || true
81-
env:
82-
COVERALLS_RUN_LOCALLY: 1
83-
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
39+
40+
- name: Run unit tests
41+
run: "./vendor/bin/phpunit --colors=always --coverage-clover build/logs/clover.xml --coverage-text"
42+
43+
- name: Publish coverage report to Codecov
44+
uses: "codecov/codecov-action@v5"

.github/workflows/mutation-tests.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: "Mutation tests"
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
paths-ignore:
8+
- 'docs/**'
9+
pull_request:
10+
paths-ignore:
11+
- 'docs/**'
12+
13+
jobs:
14+
mutation-tests:
15+
name: "Mutation tests"
16+
17+
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
php-version: [ 8.4 ]
22+
composer: [ highest ]
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Setup PHP, with composer and extensions
29+
uses: shivammathur/setup-php@v2
30+
with:
31+
php-version: ${{ matrix.php-version }}
32+
extensions: dom
33+
coverage: xdebug
34+
tools: composer:v2
35+
36+
- uses: "ramsey/composer-install@v3"
37+
with:
38+
dependency-versions: "${{ matrix.composer }}"
39+
40+
- name: "Infection"
41+
run: |
42+
vendor/bin/infection --threads=max

.github/workflows/sast.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "SAST"
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
paths-ignore:
8+
- 'docs/**'
9+
pull_request:
10+
paths-ignore:
11+
- 'docs/**'
12+
13+
jobs:
14+
phpstan:
15+
name: "PHPStan"
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Setup PHP, with composer and extensions
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: 8.3
25+
26+
- uses: "ramsey/composer-install@v3"
27+
with:
28+
dependency-versions: highest
29+
30+
- name: Run PHPStan
31+
run: "composer run-script phpstan"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ composer.lock
44
libphonenumber-data-dir/
55
build/logs/
66
/.php-cs-fixer.cache
7+
/infection.txt
8+
/.phpunit.cache

.php-cs-fixer.dist.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
return $config->setRules(
1010
[
1111
'@PER-CS2.0' => true,
12-
'@PHP74Migration' => true,
12+
'@PHP81Migration' => true,
1313
'single_quote' => true,
1414
'no_unused_imports' => true,
1515
'no_superfluous_phpdoc_tags' => [
@@ -18,7 +18,19 @@
1818
'remove_inheritdoc' => true,
1919
],
2020
'phpdoc_trim' => true,
21+
'declare_strict_types' => true,
22+
'php_unit_attributes' => true,
23+
'@PHPUnit100Migration:risky' => true,
24+
'global_namespace_import' => [
25+
'import_classes' => true,
26+
'import_constants' => true,
27+
'import_functions' => true,
28+
],
29+
'no_empty_phpdoc' => true,
30+
'phpdoc_align' => ['align' => 'left'],
31+
'phpdoc_types' => true,
2132
]
2233
)
23-
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
24-
->setFinder($finder);
34+
->setRiskyAllowed(true)
35+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
36+
->setFinder($finder);

METADATA-VERSION.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file specifies the revision of the metadata to build from.
7+
* It can be a commit, branch or tag of the https://github.com/google/libphonenumber project
8+
* For more information, look at the phing tasks in build.xml
9+
* @internal
10+
*/
11+
return 'v8.13.55';

METADATA-VERSION.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ A PHP library for parsing, formatting, storing and validating international phon
2626

2727
## Installation
2828

29-
PHP versions 7.4 to PHP 8.4 are currently supported.
29+
PHP versions 8.1 to 8.4 are currently supported.
3030

3131
The PECL [mbstring](http://php.net/mbstring) extension is required.
3232

@@ -44,6 +44,10 @@ If you do not use composer, ensure that you also load any dependencies that this
4444

4545
If you only want to make use of the core PhoneNumber Util functionality, you can use [giggsey/libphonenumber-for-php-lite](https://github.com/giggsey/libphonenumber-for-php-lite), which offers a much smaller package size.
4646

47+
### PHP Version Policy
48+
49+
This library will be updated to use [supported versions of PHP](https://www.php.net/supported-versions.php) without major version bumps.
50+
4751
## Documentation
4852

4953
- [PhoneNumber Util](docs/PhoneNumberUtil.md)
@@ -244,7 +248,7 @@ If you do need to generate the data, the commands are provided by [Phing](https:
244248
vendor/bin/phing compile
245249
```
246250

247-
This compile process clones the [libphonenumber](https://github.com/google/libphonenumber) project at the version specified in [METADATA-VERSION.txt](METADATA-VERSION.txt).
251+
This compile process clones the [libphonenumber](https://github.com/google/libphonenumber) project at the version specified in [METADATA-VERSION.php](METADATA-VERSION.php).
248252

249253
### Running tests
250254

build.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
<property name="git.url" value="https://github.com/google/libphonenumber.git"/>
77
<property name="git.path" value="libphonenumber-data-dir"/>
88

9-
<loadfile property="metadata.version" file="METADATA-VERSION.txt">
10-
<filterchain>
11-
<striplinecomments>
12-
<comment value="#" />
13-
</striplinecomments>
14-
<striplinebreaks />
15-
</filterchain>
16-
</loadfile>
9+
<php returnProperty="metadata.version" expression="require 'METADATA-VERSION.php';" />
1710

1811
<property name="data.testCoreData" value="tests/core/data/"/>
1912
<property name="data.testPrefixMapperData" value="tests/prefixmapper/data/"/>

0 commit comments

Comments
 (0)