Skip to content
Open
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
132 changes: 36 additions & 96 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -1,130 +1,70 @@
env:
COMPOSE_USER: runner

on: pull_request
name: Review
jobs:
test-composer-install:
runs-on: ubuntu-latest
strategy:
strategy: &strategy
fail-fast: false
matrix:
php: [ '7.4', '8.0' ]
name: Validate composer (${{ matrix.php}})
php:
- '7.4'
- '8.2'
- '8.3'
- '8.4'
- '8.5'
env: &env
PHP_VERSION: ${{ matrix.php }}
name: Validate composer (${{ matrix.php }})
steps:
- uses: actions/checkout@master

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php}}
tools: composer:v1
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ matrix.php }}-composer-
- uses: actions/checkout@v7

- name: Validate composer files
run: composer validate composer.json
run: docker compose run --rm phpfpm composer validate

- name: Composer install
run: composer install
run: docker compose run --rm phpfpm composer install

unit_tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0' ]
name: Unit tests (${{ matrix.php}})
strategy: *strategy
env: *env
name: Unit tests (${{ matrix.php }})
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v7

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php}}
tools: composer:v1
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ matrix.php }}-composer-

- name: Install Dependencies
run: composer install
- name: Composer install
run: docker compose run --rm phpfpm composer install

- name: Unit tests
run: phpdbg -qrr ./vendor/bin/phpunit --coverage-clover=coverage/unit.xml
run: docker compose run --rm phpfpm php vendor/bin/phpunit --coverage-clover=coverage/unit.xml

phpcsfixer:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0' ]
strategy: *strategy
env: *env
name: Coding style fixer (${{ matrix.php }})
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v7

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v1
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ matrix.php }}-composer-

- name: Install Dependencies
run: composer install
- name: Composer install
run: docker compose run --rm phpfpm composer install

- name: phpcsfixerr
run: composer run check-coding-standards
- name: Unit tests
run: docker compose run --rm phpfpm composer check-coding-standards

psalm:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0' ]
strategy: *strategy
env: *env
name: Static analysis (${{ matrix.php }})
steps:
- uses: actions/checkout@master

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v1
coverage: none
- uses: actions/checkout@v7

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ matrix.php }}-composer-

- name: Install Dependencies
run: composer install
- name: Composer install
run: docker compose run --rm phpfpm composer install

- name: Running analysis
run: composer run psalm
run: docker compose run --rm phpfpm composer psalm
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
composer.lock
/vendor
.php_cs.cache
.phpunit.result.cache
.php-cs-fixer.cache
.phpunit.result.cache
2 changes: 1 addition & 1 deletion .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
->in(__DIR__.'/{src,tests}')
;

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'@Symfony' => true,
Expand Down
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
# CPR Validator.
Validate a string resembles a CPR Number.
# CPR Validator

Validates and scans text for valid Danish CPR numbers.

## Usage

```sh
composer require itk-dev/cpr-validator
```

```php
<?php

require_once 'vendor/autoload.php';

use ItkDev\CprValidator\CprValidator;

$cprValidator = new CprValidator();
$result = $cprValidator->containsCpr('My id is 0101601234');
```

## Check code style

```sh
docker-compose run phpfpm composer run check-coding-standards/php-cs-fixer
docker compose run --rm phpfpm composer install
docker compose run --rm phpfpm composer run check-coding-standards/php-cs-fixer
```

## Run unit tests

```sh
docker-compose run phpfpm composer run phpunit
docker compose run --rm phpfpm composer run phpunit
```
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"php": ">=7.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.15",
"friendsofphp/php-cs-fixer": "^3.95",
"phpunit/phpunit": "^9.4",
"vimeo/psalm": "^4.1"
"vimeo/psalm": "^5.26 || ^6.16"
},
"scripts": {
"phpunit": [
Expand All @@ -34,13 +34,13 @@
"./vendor/bin/psalm --show-info=true"
],
"check-coding-standards/php-cs-fixer": [
"php-cs-fixer --config=.php_cs.dist fix --dry-run --format=checkstyle"
"php-cs-fixer fix --dry-run --format=checkstyle"
],
"check-coding-standards": [
"@check-coding-standards/php-cs-fixer"
],
"apply-coding-standards/php-cs-fixer": [
"php-cs-fixer --config=.php_cs.dist fix"
"php-cs-fixer fix"
],
"apply-coding-standards": [
"@apply-coding-standards/php-cs-fixer"
Expand Down
Loading
Loading