Skip to content

Commit 0405c2b

Browse files
feat: drop support of php < 7, modernise code and tests, replace travis with github actions (#47)
* feat: drop support of php < 8, modernise code and tests, replace travis with github actions * feat: drop support of php < 8, modernise code and tests, replace travis with github actions * feat: drop support of php < 8, modernise code and tests, replace travis with github actions * feat: drop support of php < 8, modernise code and tests, replace travis with github actions --------- Co-authored-by: Christopher Georg <christopher.georg@sr-travel.de>
1 parent 758b829 commit 0405c2b

19 files changed

Lines changed: 258 additions & 312 deletions

.github/workflows/ci.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# .github/workflows/ci.yaml
2+
name: Code_Checks
3+
4+
on: ["push", "pull_request"]
5+
6+
jobs:
7+
tests:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
php: ['8.0']
13+
stability: [ prefer-stable ]
14+
include:
15+
- php: '8.0'
16+
stability: prefer-lowest
17+
symfony-version: 4.4
18+
- php: '8.0'
19+
symfony-version: 5.4
20+
- php: '8.1'
21+
symfony-version: 5.4
22+
- php: '8.2'
23+
symfony-version: 5.4
24+
- php: '8.2'
25+
symfony-version: 6.2
26+
27+
name: PHP ${{ matrix.php }} - ${{ matrix.stability }} tests
28+
steps:
29+
# basically git clone
30+
- uses: actions/checkout@v3
31+
32+
- name: Cache dependencies
33+
uses: actions/cache@v3
34+
with:
35+
path: ~/.composer/cache/files
36+
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
37+
38+
# use PHP of specific version
39+
- uses: shivammathur/setup-php@v2
40+
with:
41+
php-version: ${{ matrix.php }}
42+
extensions: pcov
43+
coverage: pcov
44+
45+
- name: Install dependencies
46+
env:
47+
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
48+
run: |
49+
composer global config --no-plugins allow-plugins.symfony/flex true
50+
composer global require --no-progress --no-scripts --no-plugins symfony/flex
51+
composer update --no-interaction --prefer-dist --optimize-autoloader
52+
53+
- name: Execute tests
54+
run: vendor/bin/phpunit -c ./phpunit.xml.dist ./tests --verbose

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ Thumbs.db
1414
#composer related
1515
composer.phar
1616
composer.lock
17-
vendor/
17+
vendor/
18+
19+
.phpunit.result.cache
20+
code-coverage

.travis.yml

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

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Constraint Class for international Zipcode Validation
22

3-
[![Build Status](https://img.shields.io/travis/barbieswimcrew/zip-code-validator/master.svg?style=flat-square)](https://travis-ci.org/barbieswimcrew/zip-code-validator)
3+
[![Build Status](https://github.com/barbieswimcrew/zip-code-validator/actions/workflows/ci.yaml/badge.svg)](https://github.com/barbieswimcrew/zip-code-validator/actions/workflows/ci.yaml)
44
[![Downloads](https://img.shields.io/packagist/dt/barbieswimcrew/zip-code-validator.svg?style=flat-square)](https://packagist.org/packages/barbieswimcrew/zip-code-validator)
55
[![Latest stable version](https://img.shields.io/packagist/v/barbieswimcrew/zip-code-validator.svg?style=flat-square)](https://packagist.org/packages/barbieswimcrew/zip-code-validator)
66
[![PHP from Packagist](https://img.shields.io/packagist/php-v/barbieswimcrew/zip-code-validator.svg?style=flat-square)](./composer.json)
@@ -26,14 +26,14 @@ For validating a zip code you need to instantiate a new ZipCode class provided b
2626
<?php
2727
//...
2828
$form = $this->createFormBuilder($address)
29-
->add('zipcode', TextType::class, array(
29+
->add('zipcode', TextType::class, [
3030
'constraints' => array(
31-
new ZipCodeValidator\Constraints\ZipCode(array(
31+
new ZipCodeValidator\Constraints\ZipCode([
3232
'iso' => 'DE'
33-
))
34-
)
33+
])
34+
]
3535
))
36-
->add('save', SubmitType::class, array('label' => 'Create Task'))
36+
->add('save', SubmitType::class, ['label' => 'Create Task'])
3737
->getForm();
3838
```
3939

composer.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "barbieswimcrew/zip-code-validator",
33
"description": "Constraint class for international zipcode validation",
4-
"keywords": ["symfony", "symfony4", "symfony3", "symfony2", "form", "constraints", "constraint", "validator", "zip code", "zipcode", "postal code", "postalcode", "validation"],
4+
"keywords": ["symfony", "form", "constraints", "constraint", "validator", "zip code", "zipcode", "postal code", "postalcode", "validation"],
55
"license": "MIT",
66
"authors": [
77
{
@@ -11,16 +11,20 @@
1111
"minimum-stability": "dev",
1212
"prefer-stable": true,
1313
"require": {
14-
"php": ">=5.6.0",
15-
"symfony/validator": ">=2.1"
14+
"php": ">=8.0",
15+
"symfony/validator": ">=4.4.40"
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "^5"
18+
"phpunit/phpunit": "^9.5"
1919
},
2020
"autoload": {
2121
"psr-4": {
22-
"ZipCodeValidator\\": "src/ZipCodeValidator",
23-
"Tests\\Fixtures\\": "tests/Fixtures"
22+
"ZipCodeValidator\\": "src/ZipCodeValidator"
23+
}
24+
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"ZipCodeValidator\\Tests\\": "tests/"
2428
}
2529
}
2630
}

phpunit.xml

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
2+
<!-- https://phpunit.readthedocs.io/en/9.6/configuration.html -->
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
bootstrap="vendor/autoload.php"
55
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false">
11-
<testsuites>
12-
<testsuite name="unit">
13-
<directory suffix=".php">./tests</directory>
14-
</testsuite>
15-
</testsuites>
16-
17-
<filter>
18-
<whitelist processUncoveredFilesFromWhitelist="true">
19-
<directory suffix=".php">./tests</directory>
20-
</whitelist>
21-
</filter>
6+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">
7+
<coverage processUncoveredFiles="true">
8+
<include>
9+
<directory suffix=".php">./tests</directory>
10+
</include>
11+
</coverage>
12+
<testsuites>
13+
<testsuite name="unit">
14+
<directory suffix=".php">./tests</directory>
15+
</testsuite>
16+
</testsuites>
2217
</phpunit>

phpunit.xml.dist

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
2+
<!-- https://phpunit.readthedocs.io/en/9.6/configuration.html -->
43
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.7/phpunit.xsd"
6-
backupGlobals="false"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
75
colors="true"
8-
bootstrap="vendor/autoload.php"
9-
>
10-
<php>
11-
<ini name="error_reporting" value="-1" />
12-
</php>
6+
bootstrap="vendor/autoload.php">
7+
8+
<coverage processUncoveredFiles="true">
9+
<include>
10+
<directory suffix=".php">./src/</directory>
11+
</include>
12+
<exclude>
13+
<directory>./tests</directory>
14+
</exclude>
15+
<report>
16+
<html outputDirectory="code-coverage" lowUpperBound="35" highLowerBound="70"/>
17+
</report>
18+
</coverage>
19+
20+
<php>
21+
<ini name="error_reporting" value="-1"/>
22+
</php>
1323

14-
<testsuites>
15-
<testsuite name="Project Test Suite">
16-
<directory>Tests</directory>
17-
</testsuite>
18-
</testsuites>
24+
<testsuites>
25+
<testsuite name="Project Test Suite">
26+
<directory>Tests</directory>
27+
</testsuite>
28+
</testsuites>
1929

20-
<filter>
21-
<whitelist processUncoveredFilesFromWhitelist="true">
22-
<directory suffix=".php">./tests/</directory>
23-
</whitelist>
24-
</filter>
30+
<logging/>
2531

26-
<logging>
27-
<log type="coverage-html" target="code-coverage" lowUpperBound="35" highLowerBound="70"/>
28-
</logging>
2932
</phpunit>

src/ZipCodeValidator/Constraints/ZipCode.php

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,19 @@
66
use Symfony\Component\Validator\Exception\MissingOptionsException;
77

88
/**
9-
* Class ZipCode
109
* @Annotation
1110
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1211
* @author Martin Schindler
13-
* @package ZipCodeValidator\Constraints
1412
*/
1513
class ZipCode extends Constraint
1614
{
17-
/**
18-
* @var string
19-
*/
20-
public $message = 'This value is not a valid ZIP code.';
15+
public string $message = 'This value is not a valid ZIP code.';
16+
public ?string $iso = null;
17+
public ?string $getter = null;
18+
public bool $strict = true;
19+
public bool $caseSensitiveCheck = true;
2120

22-
/**
23-
* @var string
24-
*/
25-
public $iso;
26-
27-
/**
28-
* @var string
29-
*/
30-
public $getter;
31-
32-
/**
33-
* @var bool
34-
*/
35-
public $strict = true;
36-
37-
/**
38-
* @var bool
39-
*/
40-
public $caseSensitiveCheck = true;
41-
42-
/**
43-
* ZipCode constructor.
44-
* @param mixed $options
45-
*/
46-
public function __construct($options = null)
21+
public function __construct(mixed $options = null)
4722
{
4823
if (null !== $options && !is_array($options)) {
4924
$options = array(
@@ -54,7 +29,7 @@ public function __construct($options = null)
5429
parent::__construct($options);
5530

5631
if (null === $this->iso && null === $this->getter) {
57-
throw new MissingOptionsException(sprintf('Either the option "iso" or "getter" must be given for constraint %s', __CLASS__), array('iso', 'getter'));
32+
throw new MissingOptionsException(sprintf('Either the option "iso" or "getter" must be given for constraint %s', __CLASS__), ['iso', 'getter']);
5833
}
5934
}
6035

src/ZipCodeValidator/Constraints/ZipCodeValidator.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
88

99
/**
10-
* Class ZipCodeValidator
1110
* @author Martin Schindler
12-
* @package ZipCodeValidator\Constraints
1311
*/
1412
class ZipCodeValidator extends ConstraintValidator
1513
{
16-
1714
/**
1815
* ZipCode patterns from http://i18napis.appspot.com (updated: 2015-05-08)
1916
*
@@ -30,7 +27,7 @@ class ZipCodeValidator extends ConstraintValidator
3027
* var_export($patterns);
3128
* </code>
3229
*/
33-
private $patterns = array(
30+
private array $patterns = [
3431
'AC' => 'ASCN 1ZZ',
3532
'AD' => 'AD[1-7]0\\d',
3633
'AF' => '\\d{4}',
@@ -213,15 +210,15 @@ class ZipCodeValidator extends ConstraintValidator
213210
'YT' => '976\\d{2}',
214211
'ZA' => '\\d{4}',
215212
'ZM' => '\\d{5}',
216-
);
213+
];
217214

218215
/**
219216
* {@inheritdoc}
220217
*/
221-
public function validate($value, Constraint $constraint)
218+
public function validate($value, Constraint $constraint): void
222219
{
223220
if (!$constraint instanceof ZipCode) {
224-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\ZipCode');
221+
throw new UnexpectedTypeException($constraint, ZipCode::class);
225222
}
226223

227224
if (null === $value || '' === $value) {
@@ -249,9 +246,9 @@ public function validate($value, Constraint $constraint)
249246
if (!isset($this->patterns[$iso])) {
250247
if ($constraint->strict) {
251248
throw new ConstraintDefinitionException(sprintf('Invalid iso code "%s" for validation', $iso));
252-
} else {
253-
return;
254249
}
250+
251+
return;
255252
}
256253

257254
$pattern = $this->patterns[$iso];

0 commit comments

Comments
 (0)