PHPackages                             davidepastore/codice-fiscale - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. davidepastore/codice-fiscale

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

davidepastore/codice-fiscale
============================

An italian tax code calculator and checker

v0.10.0(9mo ago)104815.0k↓17.3%19[11 issues](https://github.com/DavidePastore/codice-fiscale/issues)4GPL-2.0-or-laterPHPPHP ^7.1|^8.0CI passing

Since Nov 22Pushed 9mo ago3 watchersCompare

[ Source](https://github.com/DavidePastore/codice-fiscale)[ Packagist](https://packagist.org/packages/davidepastore/codice-fiscale)[ RSS](/packages/davidepastore-codice-fiscale/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (21)Used By (4)

codice-fiscale
==============

[](#codice-fiscale)

[![Latest version](https://camo.githubusercontent.com/2d1858ce99ddcec4d09e7d81140a4085ae54e472b48c8649640f57e2dd5558ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f446176696465506173746f72652f636f646963652d66697363616c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/DavidePastore/codice-fiscale)[![Build Status](https://github.com/DavidePastore/codice-fiscale/workflows/Continuous%20Integration/badge.svg?branch=master)](https://github.com/DavidePastore/codice-fiscale/actions?query=workflow%3A%22Continuous+Integration%22)[![Coverage Status](https://camo.githubusercontent.com/7a30dccaff9895665a93e27395e31991d179c9751ff8233b9e40e6b8548e6660/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f446176696465506173746f72652f636f646963652d66697363616c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidePastore/codice-fiscale/code-structure)[![Quality Score](https://camo.githubusercontent.com/1c9eb89835ad96c76c99337e55f50fd72eca7f3a6bc06c61db83cf258acd1046/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f646176696465706173746f72652f636f646963652d66697363616c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidePastore/codice-fiscale)[![Total Downloads](https://camo.githubusercontent.com/0d7b94bf37d3f4fd3b34d11fb66a054b5a855810a1f98d81d11fa0e558eb7ec6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f446176696465506173746f72652f636f646963652d66697363616c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/DavidePastore/codice-fiscale)

[![PSR2 Conformance](https://camo.githubusercontent.com/80e4e48a107dddc5ab9d421537dbd750b85da1541a81a444bcdf9c8188bbbd66/68747470733a2f2f7374796c6563692e696f2f7265706f732f34363636353936302f736869656c64)](https://styleci.io/repos/46665960/)

A PHP library to calculate and check the italian tax code (codice fiscale).

*Read this in [Italian](README-it.md).*

Install
-------

[](#install)

You can install the library using [composer](https://getcomposer.org/):

```
$ composer require davidepastore/codice-fiscale
```

How to use
----------

[](#how-to-use)

### Calculate a codice fiscale

[](#calculate-a-codice-fiscale)

Use the calculator to calculate the codice fiscale.

```
use CodiceFiscale\Calculator;
use CodiceFiscale\Subject;

$subject = new Subject(
  array(
    "name" => "Mario",
    "surname" => "Rossi",
    "birthDate" => "1985-12-10",
    "gender" => "M",
    "belfioreCode" => "A562"
  )
);

$calculator = new Calculator($subject);
$codiceFiscale = $calculator->calculate();
echo $codiceFiscale; //"RSSMRA85T10A562S"
```

You can also add an array for additional configuration for the `Calculator`. Available array keys are:

- "omocodiaLevel": specifies the level of omocodia that the `Calculator` should consider.

```
use CodiceFiscale\Calculator;
use CodiceFiscale\Subject;

$subject = new Subject(
  array(
    "name" => "Mario",
    "surname" => "Rossi",
    "birthDate" => "1985-12-10",
    "gender" => "M",
    "belfioreCode" => "A562"
  )
);

$calculator = new Calculator($subject, array(
  "omocodiaLevel" => $omocodiaLevel
));
$codiceFiscale = $calculator->calculate();
echo $codiceFiscale; //"RSSMRA85T10A56NH"
```

You can also calculate all codici fiscali that a subject could have (using all 128 available levels).

```
use CodiceFiscale\Calculator;
use CodiceFiscale\Subject;

$subject = new Subject(
  array(
    "name" => "Mario",
    "surname" => "Rossi",
    "birthDate" => "1985-12-10",
    "gender" => "M",
    "belfioreCode" => "A562"
  )
);

$calculator = new Calculator($subject);
$codiciFiscali = $calculator->calculateAllPossibilities();
print_r($codiciFiscali);
/*
Array
(
    [0] => RSSMRA85T10A562S
    [1] => RSSMRA85T10A56NH
    [2] => RSSMRA85T10A5S2E
    [3] => RSSMRA85T10A5SNT
    [4] => RSSMRA85T10AR62N
    [5] => RSSMRA85T10AR6NC
    [6] => RSSMRA85T10ARS2Z
    [7] => RSSMRA85T10ARSNO
    [8] => RSSMRA85T1LA562V
    [9] => RSSMRA85T1LA56NK
    [10] => RSSMRA85T1LA5S2H
    [11] => RSSMRA85T1LA5SNW
    [12] => RSSMRA85T1LAR62Q
    [13] => RSSMRA85T1LAR6NF
    [14] => RSSMRA85T1LARS2C
    [15] => RSSMRA85T1LARSNR
    [16] => RSSMRA85TM0A562D
    [17] => RSSMRA85TM0A56NS
    [18] => RSSMRA85TM0A5S2P
    [19] => RSSMRA85TM0A5SNE
    [20] => RSSMRA85TM0AR62Y
    [21] => RSSMRA85TM0AR6NN
    [22] => RSSMRA85TM0ARS2K
    [23] => RSSMRA85TM0ARSNZ
    [24] => RSSMRA85TMLA562G
    [25] => RSSMRA85TMLA56NV
    [26] => RSSMRA85TMLA5S2S
    [27] => RSSMRA85TMLA5SNH
    [28] => RSSMRA85TMLAR62B
    [29] => RSSMRA85TMLAR6NQ
    [30] => RSSMRA85TMLARS2N
    [31] => RSSMRA85TMLARSNC
    [32] => RSSMRA8RT10A562E
    [33] => RSSMRA8RT10A56NT
    [34] => RSSMRA8RT10A5S2Q
    [35] => RSSMRA8RT10A5SNF
    [36] => RSSMRA8RT10AR62Z
    [37] => RSSMRA8RT10AR6NO
    [38] => RSSMRA8RT10ARS2L
    [39] => RSSMRA8RT10ARSNA
    [40] => RSSMRA8RT1LA562H
    [41] => RSSMRA8RT1LA56NW
    [42] => RSSMRA8RT1LA5S2T
    [43] => RSSMRA8RT1LA5SNI
    [44] => RSSMRA8RT1LAR62C
    [45] => RSSMRA8RT1LAR6NR
    [46] => RSSMRA8RT1LARS2O
    [47] => RSSMRA8RT1LARSND
    [48] => RSSMRA8RTM0A562P
    [49] => RSSMRA8RTM0A56NE
    [50] => RSSMRA8RTM0A5S2B
    [51] => RSSMRA8RTM0A5SNQ
    [52] => RSSMRA8RTM0AR62K
    [53] => RSSMRA8RTM0AR6NZ
    [54] => RSSMRA8RTM0ARS2W
    [55] => RSSMRA8RTM0ARSNL
    [56] => RSSMRA8RTMLA562S
    [57] => RSSMRA8RTMLA56NH
    [58] => RSSMRA8RTMLA5S2E
    [59] => RSSMRA8RTMLA5SNT
    [60] => RSSMRA8RTMLAR62N
    [61] => RSSMRA8RTMLAR6NC
    [62] => RSSMRA8RTMLARS2Z
    [63] => RSSMRA8RTMLARSNO
    [64] => RSSMRAU5T10A562P
    [65] => RSSMRAU5T10A56NE
    [66] => RSSMRAU5T10A5S2B
    [67] => RSSMRAU5T10A5SNQ
    [68] => RSSMRAU5T10AR62K
    [69] => RSSMRAU5T10AR6NZ
    [70] => RSSMRAU5T10ARS2W
    [71] => RSSMRAU5T10ARSNL
    [72] => RSSMRAU5T1LA562S
    [73] => RSSMRAU5T1LA56NH
    [74] => RSSMRAU5T1LA5S2E
    [75] => RSSMRAU5T1LA5SNT
    [76] => RSSMRAU5T1LAR62N
    [77] => RSSMRAU5T1LAR6NC
    [78] => RSSMRAU5T1LARS2Z
    [79] => RSSMRAU5T1LARSNO
    [80] => RSSMRAU5TM0A562A
    [81] => RSSMRAU5TM0A56NP
    [82] => RSSMRAU5TM0A5S2M
    [83] => RSSMRAU5TM0A5SNB
    [84] => RSSMRAU5TM0AR62V
    [85] => RSSMRAU5TM0AR6NK
    [86] => RSSMRAU5TM0ARS2H
    [87] => RSSMRAU5TM0ARSNW
    [88] => RSSMRAU5TMLA562D
    [89] => RSSMRAU5TMLA56NS
    [90] => RSSMRAU5TMLA5S2P
    [91] => RSSMRAU5TMLA5SNE
    [92] => RSSMRAU5TMLAR62Y
    [93] => RSSMRAU5TMLAR6NN
    [94] => RSSMRAU5TMLARS2K
    [95] => RSSMRAU5TMLARSNZ
    [96] => RSSMRAURT10A562B
    [97] => RSSMRAURT10A56NQ
    [98] => RSSMRAURT10A5S2N
    [99] => RSSMRAURT10A5SNC
    [100] => RSSMRAURT10AR62W
    [101] => RSSMRAURT10AR6NL
    [102] => RSSMRAURT10ARS2I
    [103] => RSSMRAURT10ARSNX
    [104] => RSSMRAURT1LA562E
    [105] => RSSMRAURT1LA56NT
    [106] => RSSMRAURT1LA5S2Q
    [107] => RSSMRAURT1LA5SNF
    [108] => RSSMRAURT1LAR62Z
    [109] => RSSMRAURT1LAR6NO
    [110] => RSSMRAURT1LARS2L
    [111] => RSSMRAURT1LARSNA
    [112] => RSSMRAURTM0A562M
    [113] => RSSMRAURTM0A56NB
    [114] => RSSMRAURTM0A5S2Y
    [115] => RSSMRAURTM0A5SNN
    [116] => RSSMRAURTM0AR62H
    [117] => RSSMRAURTM0AR6NW
    [118] => RSSMRAURTM0ARS2T
    [119] => RSSMRAURTM0ARSNI
    [120] => RSSMRAURTMLA562P
    [121] => RSSMRAURTMLA56NE
    [122] => RSSMRAURTMLA5S2B
    [123] => RSSMRAURTMLA5SNQ
    [124] => RSSMRAURTMLAR62K
    [125] => RSSMRAURTMLAR6NZ
    [126] => RSSMRAURTMLARS2W
    [127] => RSSMRAURTMLARSNL
)
*/
```

### Check if it is valid

[](#check-if-it-is-valid)

Use the checker to check if the given codice fiscale is ok for the given `Subject` and additional configuration. The additional configuration array for the `Checker` has the given available keys:

- "codiceFiscaleToCheck": the codice fiscale to check;
- "omocodiaLevel": the omocodia level to use to check.

```
use CodiceFiscale\Checker;
use CodiceFiscale\Subject;

$subject = new Subject(
  array(
    "name" => "Mario",
    "surname" => "Rossi",
    "birthDate" => "1985-12-10",
    "gender" => "M",
    "belfioreCode" => "A562"
  )
);

$checker = new Checker($subject, array(
  "codiceFiscaleToCheck" => "RSSMRA85T10A562S",
  "omocodiaLevel" => 0
));

$response = $checker->check();
echo $response; // true
```

You can also provide as `omocodiaLevel` key, the value of `Checker::ALL_OMOCODIA_LEVELS` that will check for all the possibilities for the given `Subject`. In the following example, the `Subject` would not be valid for the given codice fiscale, but it will be so, cause the check will iterate over all the possibilities for the different omocodia levels.

```
use CodiceFiscale\Checker;
use CodiceFiscale\Subject;

$subject = new Subject(
  array(
    "name" => "Roberto",
    "surname" => "Santi",
    "birthDate" => "1963-05-08",
    "gender" => "M",
    "belfioreCode" => "H501"
  )
);

$checker = new Checker($subject, array(
  "codiceFiscaleToCheck" => "SNTRRT63E08H50ML",
  "omocodiaLevel" => Checker::ALL_OMOCODIA_LEVELS
));

$response = $checker->check();
echo $response; // true
```

### Formal validation

[](#formal-validation)

Use the Validator to verify if the given codice fiscale is formally valid. The additional configuration array for the `Validator` has the given available keys:

- "omocodiaAllowed": whether to allow or not omocodia, defaults to true;
- "century": for people over 100 years old, it is not possibile to derive unambiguously birth year, so you can specify the century (for example '18' for a person birth in 1899). It allows to check birth date existence. Defaults to null (auto calculation of the century).

```
use CodiceFiscale\Validator;

$codiceFiscale = "RSSMRA85T10A562S";

$validator = new Validator($codiceFiscale);

$response = $validator->isFormallyValid();
echo $response; // true
```

### Inverse calculation

[](#inverse-calculation)

Use the InverseCalculator to extract birth date, gender and the belfiore code from the given codice fiscale. The additional configuration array for the `InverseCalculator` has the keys already described for the `Validator`.

```
use CodiceFiscale\InverseCalculator;

$codiceFiscale = "RSSMRA85T10A562S";

$inverseCalculator = new InverseCalculator($codiceFiscale);

$subject = $inverseCalculator->getSubject();
var_dump($subject);
// object(CodiceFiscale\Subject)[449]
//   private 'name' => null
//   private 'surname' => null
//   private 'birthDate' =>
//     object(DateTime)[452]
//       public 'date' => string '1985-12-10 00:00:00.000000' (length=26)
//       public 'timezone_type' => int 3
//       public 'timezone' => string 'Europe/Berlin' (length=13)
//   private 'gender' => string 'M' (length=1)
//   private 'belfioreCode' => string 'A562' (length=4)
```

Test
----

[](#test)

```
$ composer test
```

Issues
------

[](#issues)

If you have issues, just open one [here](https://github.com/DavidePastore/codice-fiscale/issues).

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance55

Moderate activity, may be stable

Popularity54

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 67.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~186 days

Recently: every ~479 days

Total

20

Last Release

286d ago

PHP version history (2 changes)v0.7.0PHP ^7.1

v0.8.0PHP ^7.1|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/11a9e9c18e06a1827a69e0b5e7c4644e1f937f70463ff88b25b76b172be5e769?d=identicon)[DavidePastore](/maintainers/DavidePastore)

---

Top Contributors

[![DavidePastore](https://avatars.githubusercontent.com/u/1949364?v=4)](https://github.com/DavidePastore "DavidePastore (90 commits)")[![antonioturdo](https://avatars.githubusercontent.com/u/1651072?v=4)](https://github.com/antonioturdo "antonioturdo (27 commits)")[![giorgioma](https://avatars.githubusercontent.com/u/7810053?v=4)](https://github.com/giorgioma "giorgioma (6 commits)")[![garak](https://avatars.githubusercontent.com/u/179866?v=4)](https://github.com/garak "garak (5 commits)")[![tvinterlogica](https://avatars.githubusercontent.com/u/132082820?v=4)](https://github.com/tvinterlogica "tvinterlogica (2 commits)")[![gadiener](https://avatars.githubusercontent.com/u/8479033?v=4)](https://github.com/gadiener "gadiener (1 commits)")[![loviuz](https://avatars.githubusercontent.com/u/1647128?v=4)](https://github.com/loviuz "loviuz (1 commits)")[![massimilianobraglia](https://avatars.githubusercontent.com/u/17158942?v=4)](https://github.com/massimilianobraglia "massimilianobraglia (1 commits)")[![angelods](https://avatars.githubusercontent.com/u/19353647?v=4)](https://github.com/angelods "angelods (1 commits)")

---

Tags

checkercodice-fiscalecomposergeneratorphpreverse-calculationvalidationvalidatorcodice fiscaletax codeitalianitaly

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/davidepastore-codice-fiscale/health.svg)

```
[![Health](https://phpackages.com/badges/davidepastore-codice-fiscale/health.svg)](https://phpackages.com/packages/davidepastore-codice-fiscale)
```

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[seld/jsonlint

JSON Linter

1.3k217.8M205](/packages/seld-jsonlint)[composer/spdx-licenses

SPDX licenses list and validation library.

1.4k184.2M25](/packages/composer-spdx-licenses)[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[laminas/laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria

15644.9M188](/packages/laminas-laminas-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
