Search by

msstc4php / vo-organisations

maxim.shamaev@gmail.com

Value objects for company, tax and business registration numbers of Australia, Brazil, Switzerland, China, the EU VAT area, France, the United Kingdom, India, Italy, Japan, Mexico, Poland, Russia and the United States.

Package info

github.com/msstc4php/vo-organisations

pkg:composer/msstc4php/vo-organisations

Statistics

Installs: 1

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-27 12:40 UTC

This package is auto-updated.

Last update: 2026-11-28 15:05:15 UTC


README

Value objects for company, tax and business registration numbers of Australia, Brazil, Switzerland, China, the EU VAT area, France, the United Kingdom, India, Italy, Japan, Mexico, Poland, Russia and the United States. Built on msstc4php/vo-base; PHP >= 8.4.

A check digit or structural rule is enforced only when an official source (regulator, tax authority, statistics office, standards body, or an unmodified archive copy of one) states it; the notes, with quotes, are in docs/sources/ORGANISATIONS.md. What a class cannot check from a published source is checked for format only and listed under "Format only" below.

Status

0.1.0, pre-1.0: a minor may break, each break is listed in the CHANGELOG. The promise drafted for 1.0.0 is under Backward compatibility.

Install

Not on Packagist yet; register the GitHub repositories:

{
    "repositories": [
        { "type": "vcs", "url": "https://github.com/msstc4php/vo-base" },
        { "type": "vcs", "url": "https://github.com/msstc4php/vo-organisations" }
    ],
    "require": {
        "msstc4php/vo-organisations": "^0.1"
    }
}

Runtime requirements: msstc4php/vo-base ^1.4. No framework, no ext-bcmath.

Usage

use MSSTC4PHP\ValueObject\Organisations\AU\Abn;
use MSSTC4PHP\ValueObject\Organisations\BR\Cnpj;
use MSSTC4PHP\ValueObject\Organisations\EU\VatNumber;
use MSSTC4PHP\ValueObject\Organisations\RU\RegistrationNumberFactory;

$abn = Abn::from('51 824 753 556');
(string) $abn;                                   // 51824753556
$abn->formatted();                               // 51 824 753 556

$cnpj = Cnpj::from('12.abc.345/01de-35');        // alphanumeric CNPJ, stored uppercase
(string) $cnpj;                                  // 12ABC34501DE35
$cnpj->formatted();                              // 12.ABC.345/01DE-35

$vat = VatNumber::from('de 123 456 789');
$vat->countryPrefix();                           // DE
$vat->nationalNumber();                          // 123456789

$number = RegistrationNumberFactory::fromString('1027700132195');   // an Ogrn; a bad length gets one fixed message

Classes

All value objects are string value objects (AbstractStringValueObject, with from(), tryFrom(), isValid()): (string) $vo and jsonSerialize() give the full canonical value, and equals() compares it. Organisation numbers are public register data, so there is no masked(). A failure is Exception\InvalidOrganisationIdentifierException (final, extends vo-base InvalidValueObjectException). Messages read <type> <reason>. and contain no part of the input, not even its length.

Every class has a public MAX_LENGTH (the longest stored value, in characters), the frozen bound the Doctrine bridge sizes its columns by.

Branch: E the check is enforced (a wrong check is refused, fromParts() computes it); R report only (hasValidCheckDigit(): bool); F format only. Where a class is F but reports something, the cell says so; no class in 0.1.0 is purely R.

Class Source Branch Value and accessors
AU\Abn ABR, "Format of the ABN" E 11 digits, mod 89; fromParts() (9-digit body), formatted() 51 824 753 556
AU\Acn ASIC, ACN digit check (archive) E 9 digits, mod 10; leading zeros kept; fromParts() (8-digit body), formatted() 000 000 019
BR\Cnpj RFB, "CNPJ Alfanumérico"; ADE COFIS 41/2017 E 12 digits or upper-case letters and 2 check digits (ASCII - 48, mod 11); fromParts($root, $order), root(), order(), isAlphanumeric(), formatted(); no head-office marker, 0001 no longer identifies one
CH\Uid UIDV SR 431.031 Art. 5; eCH-0097 E CHE + 8 digits + check; a check of 10 is refused as never issued; fromParts(), formatted() CHE-109.322.551; ADM and the HR/MWST supplement are refused
CN\UnifiedSocialCreditCode 国发〔2015〕33号 F 18 characters, positions 3-8 digits; registrationAuthorityCode(), organisationTypeCode(), administrativeDivisionCode(), organisationCode()
EU\VatNumber VIES, "VAT identification number structure" F prefix + national body per Member State; countryPrefix(), country(), nationalNumber(), hasValidCheckDigit(): ?bool (Italian check reported, never refused; null for every other prefix)
FR\Siren INSEE c2047 F 9 digits; formatted() 732 829 320
FR\Siret INSEE c1841 F 14 digits; siren(), nic(), formatted() 732 829 320 00074
GB\CompanyNumber Companies House, URI Customer Guide F 8 characters [0-9A-Z], leading zeros kept; prefix(): ?string returns the first two characters when the number starts with a letter (R0 included), else null; never checked against the 2012 list
GB\VatNumber VIES (GB and XI rows) F 9 or 12 digits, GD/HA + 3 digits, stored without GB; isBranchTraderNumber(), isGovernmentDepartment(), isHealthAuthority()
IN\Gstin GST Council flyer F 15 characters; stateCode(), pan(), entityCode()
IT\PartitaIva DM 23.12.1976 art. 8-9 E 11 digits, leading zeros kept; fromParts($serialNumber, $officeCode), serialNumber(), officeCode()
JP\CorporateNumber NTA, 「法人番号の構成」 E 13 digits, the check first; fromParts(), baseNumber()
JP\QualifiedInvoiceIssuerNumber NTA invoice leaflet, Web-API specification F T + 13 digits, stored with the T; digits()
MX\LegalEntityRfc SAT tdCFDI.xsd t_RFC_PM (archive) F 12 characters, the SAT pattern exactly (& and Ñ allowed); incorporationDateDigits()
PL\Nip none reached F 10 digits
PL\Regon Rozporządzenie RM 30.11.2015, § 12 (archive) F 9 or 14 digits; isLocalUnit(), parentRegon()
RU\Ogrn Минфин 165н п. 7 E 13 digits, first 1 or 5, mod 11; fromParts(), registrationYearDigits(), regionCode()
RU\Ogrnip Минфин 165н п. 7 E 15 digits, first 3, mod 13; fromParts(), registrationYearDigits(), regionCode(); public register data, not masked
RU\LegalEntityInn ФНС ЕД-7-14/559@ п. 2-3 F 10 digits; taxAuthorityRegionCode()
RU\Kpp ФНС ЕД-7-14/559@ п. 3 F 9 characters \d{4}[0-9A-Z]{2}\d{3}; taxOfficeCode(), reasonCode()
US\Ein IRS, valid EIN prefixes F 9 digits; prefix(), isAssignedPrefix() (report only, against the IRS table), formatted() 12-3456789

The EU VAT prefix is the VIES one: EL for Greece and XI for Northern Ireland are kept; GR, GB and a missing prefix are refused. A United Kingdom number without XI is GB\VatNumber. IE is accepted wider than the two printed VIES formats (8 or 9 characters), so no issued number is refused.

Canonical forms and accepted separators

The canonical string is the unformatted identifier. Each class strips ASCII spaces and the separators of its printed form only, uppercases ASCII letters, and refuses anything else. A value of the wrong length is refused, never zero-padded.

Class Also stripped Canonical
AU\Abn, AU\Acn, FR\*, GB\*, IN\Gstin, IT\PartitaIva, PL\Regon, CN\UnifiedSocialCreditCode, RU\* spaces only (GB\VatNumber also a leading GB) digits / characters
BR\Cnpj ., /, - 12ABC34501DE35
CH\Uid -, . CHE109322551
EU\VatNumber ., - DE123456789
JP\*, MX\LegalEntityRfc - T + 13 digits; the RFC with Ñ
PL\Nip, US\Ein - 1234567890, 123456789

Leading zeros are kept (00743110157, 000000019, 00445790, 01-2345678); a 7-digit company number or a 10-digit partita IVA, where an integer cast lost a zero, is refused.

Factories

There is no global factory: nine digits alone fit an ACN, a KPP, an EIN, a SIREN, a REGON, a UK VAT number and more, and a factory never picks silently. Two area factories decide by length where the set is closed:

  • AU\BusinessIdentifierFactory: 11 digits give Abn, 9 give Acn (the ACN check is enforced, so a bad 9-digit value is refused with the ACN message); an ARBN or ARSN, which use the ACN formula, come out as Acn.
  • RU\RegistrationNumberFactory: 13 characters give Ogrn, 15 Ogrnip, 10 LegalEntityInn, 9 Kpp. Every other input gets one fixed message that names the classes and says a person's INN is vo-documents RU\Inn; it reveals nothing about the input.

EU\VatNumber::from() decides by the VIES prefix and refuses a bare number. Candidate sets are frozen per major.

Format only

Class Why
CN\UnifiedSocialCreditCode GB 32100-2015 full text unreachable (viewer needs a browser and a verification step)
EU\VatNumber (all prefixes but IT) VIES gives formats only; no national check read from an official text; the IT check is reported, never refused
FR\Siren, FR\Siret INSEE names a check digit, no algorithm; Luhn and the La Poste rule only in secondary sources
GB\CompanyNumber Companies House publishes no check digit; the prefix list is from 2012
GB\VatNumber HMRC publishes no algorithm
IN\Gstin the check-sum algorithm is in no official text found
JP\QualifiedInvoiceIssuerNumber NTA validates only T + 13 digits; its own samples fail the 法人番号 check
MX\LegalEntityRfc SAT publishes the pattern, not the homoclave algorithm
PL\Nip no official text with the algorithm reached
PL\Regon the regulation names a check digit without the algorithm
RU\LegalEntityInn check "по алгоритму, определенному ФНС", unpublished
RU\Kpp no check character
US\Ein no check digit; prefixes change over time

A check found in an official text later becomes a report-only hasValid...(): bool in a minor.

Left out

  • Already in a sibling package: LEI (vo-finance Security\Lei); company PAN (IN), RFC of a person (MX), INN of a person (RU), CPF (BR) (vo-documents).
  • CH ADM numbers and the UID supplement; a CH\VatNumber waits for a use case.
  • ARBN and ARSN (AU): same formula as the ACN, not modelled apart from the factory.
  • DUNS (proprietary), EORI (customs), NL KvK, PL KRS.
  • No official algorithm reached: DE USt-IdNr check, UK VAT check, GSTIN checksum, KR business number, ES CIF control, SG UEN, CA BN, FR TVA key, BE and NL VAT checks, GB 32100-2015 (unreachable text).
  • Online lookups (VIES, ABN Lookup, Receita, NTA API, ЕГРЮЛ): I/O, an adapter's job. Registry data products are not embedded.

Backward compatibility

0.x: a minor may break; each break is listed in the CHANGELOG.

Drafted for 1.0.0: from 1.0.0 on, a breaking change needs 2.0. Covered by 1.x:

  • public classes, methods and parameter names (named arguments), and return types;
  • the canonical (stored) string of every value object, which is also its __toString(), JSON value and the value key of its __serialize() payload;
  • the MAX_LENGTH bounds, and in vo-organisations-doctrine the type names and column lengths;
  • exception classes and their parents.

Rules for minor releases:

  • A minor never refuses a value that an earlier 1.x release accepted. Through the Doctrine bridge a refused stored value would throw on hydration, so a check that gets an official source later is reported only, by a new hasValid...(): bool method; refusing waits for 2.0. The format-only classes listed above are the ones concerned.
  • A minor may accept more (relax a rule), but only values within the frozen MAX_LENGTH.
  • Factory candidate sets are frozen per major.
  • The EIN prefix table and the VIES formats ship in minors and only widen: a new prefix or shape is accepted, none is withdrawn.

Not covered: the wording of exception messages; everything in Internal\.

With the bridges

Every class is a string value object, so ValueObjectMapper (vo-base) and every framework bridge (Symfony, Laravel, Yii 2, CodeIgniter 4, Cycle, Spiral) validates, binds and stores it with no codec: the stored value is the canonical string. Type a column, a property or a parameter with the concrete class; the two factories are for input whose kind is not known in advance.

msstc4php/vo-organisations-doctrine stores these value objects in Doctrine ORM and MongoDB ODM columns: one type per class, org_<cc>_<snake_name>.

License

MIT, see LICENSE.