davidepastore / codice-fiscale
意大利税号计算器与验证器
v0.9.1
2023-01-30 00:38 UTC
Requires
- php: ^7.1|^8.0
- ext-intl: *
Requires (Dev)
- phpunit/phpunit: ^7.5 || ^8.5
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: 3.*
README
一个用于计算和验证意大利税号(codice fiscale)的PHP库。
用意大利语阅读。
安装
您可以使用composer安装此库
$ composer require davidepastore/codice-fiscale
如何使用
计算codice fiscale
使用计算器计算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"
您还可以为Calculator
添加一个数组以进行额外的配置。可用的数组键有
- "omocodiaLevel": 指定
Calculator
应考虑的omocodia级别。
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"
您还可以计算某人可能拥有的所有codice fiscali(使用所有128个可用的级别)。
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 ) */
验证是否有效
使用验证器检查给定的codice fiscale是否对于给定的Subject
和附加配置是有效的。附加配置数组为Checker
提供以下可用键
- "codiceFiscaleToCheck": 要检查的codice fiscale;
- "omocodiaLevel": 用于检查的omocodia级别。
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
您还可以提供作为omocodiaLevel
键的Checker::ALL_OMOCODIA_LEVELS
值,这将检查给定Subject
的所有可能性。在以下示例中,该Subject
对于给定的codice fiscale是不有效的,但它是有效的,因为检查将遍历所有可能的omocodia级别。
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
正式验证
使用验证器来验证给定的codice fiscale是否形式上有效。附加配置数组为Validator
提供以下可用键
- "omocodiaAllowed": 是否允许omocodia,默认为true;
- "century": 对于100岁以上的人,无法明确推导出生年份,因此您可以指定世纪(例如,'18'表示1899年出生的人)。它允许检查出生日期的存在。默认为null(自动计算世纪)。
use CodiceFiscale\Validator; $codiceFiscale = "RSSMRA85T10A562S"; $validator = new Validator($codiceFiscale); $response = $validator->isFormallyValid(); echo $response; // true
逆向计算
使用InverseCalculator从给定的codice fiscale中提取出生日期、性别和bellifore代码。附加配置数组为InverseCalculator
提供与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)
测试
$ composer test
问题
如果您有问题,请在这里打开一个问题。