Skip to content

Commit

Permalink
Merge pull request #26 from rasmusbe/v3
Browse files Browse the repository at this point in the history
v3
  • Loading branch information
rasmusbe authored Feb 18, 2020
2 parents e89d58d + 06e4529 commit 29ce0d4
Show file tree
Hide file tree
Showing 13 changed files with 1,451 additions and 646 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ trim_trailing_whitespace = true
insert_final_newline = true

[*.php]
indent_style = space
indent_size = 4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
vendor
/.phpunit.result.cache
/coverage
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

install:
- travis_retry composer install --no-interaction --prefer-source

script:
- vendor/bin/phpcs --standard=PSR2 src
- vendor/bin/phpunit
- composer test
72 changes: 56 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,95 @@
# personnummer [![Build Status](https://travis-ci.org/personnummer/php.svg?branch=master)](https://travis-ci.org/personnummer/php) ![Packagist Version](https://img.shields.io/packagist/v/frozzare/personnummer) ![PHP from Packagist](https://img.shields.io/packagist/php-v/frozzare/personnummer)
# personnummer [![Build Status](https://travis-ci.org/personnummer/php.svg?branch=master)](https://travis-ci.org/personnummer/php) ![Packagist Version](https://img.shields.io/packagist/v/personnummer/personnummer) ![PHP from Packagist](https://img.shields.io/packagist/php-v/personnummer/personnummer)

Validate Swedish social security numbers.

## Installation

```
composer require frozzare/personnummer
composer require personnummer/personnummer
```

## Methods
#### Static
| Method | Arguments | Returns |
| -------|:---------------------------------------------------------------|---------:|
| parse | string personnummer, [ array options<sup>[*](#options)</sup> ] | Instance |
| valid | string personnummer, [ array options<sup>[*](#options)</sup> ] | bool |

#### Instance
| Method | Arguments | Returns |
| ---------------------|:----------------|--------:|
| format | bool longFormat | string |
| getAge | none | int |
| isMale | none | bool |
| isFemale | none | bool |
| isCoordinationNumber | none | bool |

| Property | Type | Description |
| ---------|:-------|----------------------------:|
| age | int | Current age |
| century | string | Century, two digits |
| year | string | Year, two digits |
| fullYear | string | Year, four digits |
| month | string | Month, two digits |
| day | string | Day, two digits |
| sep | string | Separator (-/+) |
| num | string | Suffix number, three digits |
| check | string | Luhn check digit, one digit |

## Errors
When a personnummer is invalid a PersonnummerException is thrown.

## Options
| Option | Type | Default | Description |
| ------------------------|:-----|:--------|:---------------------------:|
| allowCoordinationNumber | bool | true | Accept coordination numbers |

## Examples

### Validation

```php
use Frozzare\Personnummer\Personnummer;
use Personnummer\Personnummer;

Personnummer::valid(6403273813);
Personnummer::valid(1212121212);
//=> true

Personnummer::valid('19130401+2931');
Personnummer::valid('20121212-1212');
//=> true
```

### Format
```php
use Frozzare\Personnummer\Personnummer;
use Personnummer\Personnummer;

// Short format (YYMMDD-XXXX)
Personnummer::format(6403273813);
//=> 640327-3813
(new Personnummer(1212121212))->format();
//=> 121212-1212

// Short format for 100+ years old
(new Personnummer('191212121212'))->format();
//=> 121212+1212

// Long format (YYYYMMDDXXXX)
Personnummer::format('6403273813', true);
//=> 196403273813
(new Personnummer('1212121212'))->format(true);
//=> 201212121212
```

### Get Age
```php
use Frozzare\Personnummer\Personnummer;
use Personnummer\Personnummer;

Personnummer::getAge(6403273813);
//=> 55
(new Personnummer('1212121212'))->age;
//=> 7
```

### Get Sex
```php
use Frozzare\Personnummer\Personnummer;
use Personnummer\Personnummer;

Personnummer::isMale(6403273813);
(new Personnummer('1212121212'))->isMale();
//=> true
Personnummer::isFemale(6403273813);
(new Personnummer('1212121212'))->isFemale();
//=> false
```

Expand Down
32 changes: 21 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "frozzare/personnummer",
"name": "personnummer/personnummer",
"type": "utility",
"license": "MIT",
"description": "Validate Swedish social security numbers",
"authors": [
{
"name": "Fredrik Forsmo",
"email": "[email protected]",
"homepage": "https://github.com/frozzare"
},
{
"name": "Rasmus Bengtsson",
"homepage": "https://github.com/rasmusbe"
}
],
"keywords": [
Expand All @@ -24,33 +27,40 @@
"coordination"
],
"support": {
"issues": "https://github.com/frozzare/php-personnummer/issues"
"issues": "https://github.com/personnummer/php/issues"
},
"require": {
"php": ">=5.6"
"php": ">=7.2"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"ext-json": "*",
"squizlabs/php_codesniffer": "^3.4",
"vladahejda/phpunit-assert-exception": "^1.0"
"jchook/phpunit-assert-throws": "^1.0",
"phpunit/phpunit": "^9.0",
"phpcompatibility/php-compatibility": "^9.3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2"
},
"autoload": {
"psr-4": {
"Frozzare\\Personnummer\\": "src/"
"Personnummer\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Frozzare\\Tests\\Personnummer\\": "tests/"
"Personnummer\\Tests\\": "tests/"
}
},
"scripts": {
"lint": "vendor/bin/phpcs --standard=PSR2 src",
"test": "vendor/bin/phpunit"
"lint": "vendor/bin/phpcs --standard=ruleset.xml",
"unittest": "vendor/bin/phpunit",
"test": [
"@lint",
"@unittest"
]
},
"config": {
"platform": {
"php": "5.6"
"php": "7.3"
}
}
}
Loading

0 comments on commit 29ce0d4

Please sign in to comment.