定制 davidepastore/codice-fiscale 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

davidepastore/codice-fiscale

Composer 安装命令:

composer require davidepastore/codice-fiscale

包简介

An italian tax code calculator and checker

README 文档

README

Latest version Build Status Coverage Status Quality Score Total Downloads

PSR2 Conformance

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

Read this in Italian.

Install

You can install the library using composer:

$ composer require davidepastore/codice-fiscale

How to use

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

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

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

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

$ composer test

Issues

If you have issues, just open one here.

davidepastore/codice-fiscale 适用场景与选型建议

davidepastore/codice-fiscale 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 890.59k 次下载、GitHub Stars 达 105, 最近一次更新时间为 2015 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「validator」 「codice fiscale」 「tax code」 「italian」 「italy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 davidepastore/codice-fiscale 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 davidepastore/codice-fiscale 我们能提供哪些服务?
定制开发 / 二次开发

基于 davidepastore/codice-fiscale 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 890.59k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 105
  • 点击次数: 39
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 105
  • Watchers: 3
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2015-11-22