PHPackages                             rocketfellows/specific-country-vat-number-format-validators-config - 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. rocketfellows/specific-country-vat-number-format-validators-config

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

rocketfellows/specific-country-vat-number-format-validators-config
==================================================================

v1.0.0(3y ago)047220MITPHPPHP &gt;=7.4

Since Apr 26Pushed 3y agoCompare

[ Source](https://github.com/rocketfellows/specific-country-vat-number-format-validators-config)[ Packagist](https://packagist.org/packages/rocketfellows/specific-country-vat-number-format-validators-config)[ RSS](/packages/rocketfellows-specific-country-vat-number-format-validators-config/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (20)

Specific country vat number format validator config
===================================================

[](#specific-country-vat-number-format-validator-config)

[![Code Coverage Badge](./badge.svg)](./badge.svg)

This package provides an abstract class for configuring a list of validators for a specific country. It is one of the implementations of the ***CountryVatNumberFormatValidatorsConfigInterface*** interface.

Installation
------------

[](#installation)

```
composer require rocketfellows/specific-country-vat-number-format-validators-config
```

Dependencies
------------

[](#dependencies)

-  v1.0.2;
-  v1.1.0;
-  v1.0.0;

List of package components
--------------------------

[](#list-of-package-components)

- ***SpecificCountryVatNumberFormatValidatorsConfig*** - an abstract class that implements ***CountryVatNumberFormatValidatorsConfigInterface*** interface for configuring a tuple of validators for a specific country;

SpecificCountryVatNumberFormatValidatorsConfig description
----------------------------------------------------------

[](#specificcountryvatnumberformatvalidatorsconfig-description)

***SpecificCountryVatNumberFormatValidatorsConfig*** properties:

- ***$validators*** - attribute to store a tuple of validators for specific country;

***SpecificCountryVatNumberFormatValidatorsConfig*** functions:

- ***abstract public function getCountry(): Country*** - abstract public function which must be implemented in the child class, it defines specific country for concrete config;
- ***abstract protected function getDefaultValidator(): CountryVatFormatValidatorInterface*** - abstract protected function which must be implemented in the child class, it defines default vat number format validator for country, returns instance of ***CountryVatFormatValidatorInterface***;

Class constructor takes two optional parameters:

- ***$defaultValidator*** - instance of ***CountryVatFormatValidatorInterface*** or null, if this parameter is passed, then it replaces the validator returned by the ***getDefaultValidator*** function from the child class;
- ***$additionalValidators*** - instance of ***CountryVatFormatValidators*** or null, additional validators tuple for specific country;

A child class extending ***SpecificCountryVatNumberFormatValidatorsConfig*** must implement the following functions:

- ***public function getCountry(): Country*** - implementation of the interface function ***CountryVatNumberFormatValidatorsConfigInterface***, returns instance of ***arslanimamutdinov\\ISOStandard3166\\Country***, thus the child class defines the country for which the vat number format validators are configured;
- ***protected function getDefaultValidator(): CountryVatFormatValidatorInterface*** - implementation of the abstract function of the class ***SpecificCountryVatNumberFormatValidatorsConfig***, returns an object of type ***CountryVatFormatValidatorInterface*** - default vat number format validator for specific country;

Depending on the parameters passed to the constructor of the child class, the ***$validators*** tuple is formed in the ***CountryVatFormatValidators*** tuple, the validators in which are typed according to the following rules:

- if ***$defaultValidator*** parameter is null and ***$additionalValidators*** parameter is null then ***$validators*** property stores only one validator which returns from implemented ***getDefaultValidator*** function;
- if ***$defaultValidator*** parameter is null and ***$additionalValidators*** parameter not null then ***$validators*** property stores validator which returns from implemented ***getDefaultValidator*** function and passed ***$additionalValidators*** into constructor;
- if ***$defaultValidator*** parameter not null and ***$additionalValidators*** parameter is null then ***$validators*** property stores passed ***$defaultValidator*** into constructor;
- if ***$defaultValidator*** parameter not null and ***$additionalValidators*** parameter not null then ***$validators*** property stores passed ***$defaultValidator*** and ***$additionalValidators*** into constructor;

Usage example
-------------

[](#usage-example)

Let's say we need to implement the configuration of vat number format validators for Germany. To do this, you need to create a class (for example, ***DEVatNumberFormatValidatorsConfig***) and inherit it from ***SpecificCountryVatNumberFormatValidatorsConfig***. The default vat number format validator for Germany can be used from the package  - there is already a validator class for Germany that implements the ***CountryVatFormatValidatorInterface*** interface. For default vat number format validator for Germany we will use DEVatFormatValidator. For ***getCountry*** function we can use arslanimamutdinov\\ISOStandard3166\\ISO3166 utility we already defined ***Country*** getter for Germany.

```
class DEVatNumberFormatValidatorsConfig extends SpecificCountryVatNumberFormatValidatorsConfig
{
    public function getCountry(): Country
    {
        return ISO3166::DE();
    }

    protected function getDefaultValidator(): CountryVatFormatValidatorInterface
    {
        return new DEVatFormatValidator();
    }
}
```

And that's it, we created default pre-configured vat number format validators for Germany.

```
$config = new DEVatNumberFormatValidatorsConfig();

// will return Country instance for Germany (according to standard ISO 3166)
$config->getCountry();

// will return CountryVatFormatValidators tuple with one item, which is DEVatFormatValidator instance
$config->getValidators();
```

Let's say we want to replace the implementation of the vat number format validator for Germany in the current config. To do this, you need to create a new validator class that must implement the ***CountryVatFormatValidatorInterface*** interface.

```
class AnotherDEVatFormatValidator implements CountryVatFormatValidatorInterface
{
    public function isValid(string $vatNumber): bool
    {
        // add some implementation
    }
}
```

Further, when instantiating ***DEVatNumberFormatValidatorsConfig*** to the constructor, as the first parameter, you need to pass the instance of the new validator, which will replace the default validator from the config.

```
$config = new DEVatNumberFormatValidatorsConfig(new AnotherDEVatFormatValidator());

// will return Country instance for Germany (according to standard ISO 3166)
$config->getCountry();

// will return CountryVatFormatValidators tuple with one item, which is AnotherDEVatFormatValidator instance
$config->getValidators();
```

Suppose we do not want to replace the default validator in the config, but want to add ***AnotherDEVatFormatValidator*** as an additional one. For example, the default validator checks the vat number format only for individuals, and we want the config to have a validator that checks the vat number format for legal entities. To do this, when instantiating ***DEVatNumberFormatValidatorsConfig***, pass null as the first parameter, and pass the ***CountryVatFormatValidators*** tuple consisting of one element as the second parameter.

```
$config = new DEVatNumberFormatValidatorsConfig(
    null,
    (
        new CountryVatFormatValidators(
            new AnotherDEVatFormatValidator()
        )
    )
);

// will return Country instance for Germany (according to standard ISO 3166)
$config->getCountry();

// will return CountryVatFormatValidators tuple with two items:
// object instance of DEVatFormatValidator
// and object instance of AnotherDEVatFormatValidator
$config->getValidators();
```

If you want to completely change the ***DEVatNumberFormatValidatorsConfig*** configuration, then you need to pass your own as the default validator and as additional validators when instantiating the config.

More use case examples can be found in the package's unit tests: ***rocketfellows\\SpecificCountryVatNumberFormatValidatorsConfig\\tests\\unit\\SpecificCountryVatNumberFormatValidatorsConfigTest***.

Contributing
------------

[](#contributing)

Welcome to pull requests. If there is a major changes, first please open an issue for discussion.

Please make sure to update tests as appropriate.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.4% 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

Unknown

Total

1

Last Release

1112d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/81402dcd0a07ad550b7f80f5871e7c302770b29d4c73a52fc35ba697f702d56e?d=identicon)[arslanim](/maintainers/arslanim)

---

Top Contributors

[![arslanim](https://avatars.githubusercontent.com/u/22678154?v=4)](https://github.com/arslanim "arslanim (35 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")

---

Tags

country-vat-number-format-validatorcountry-vat-number-format-validator-config

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rocketfellows-specific-country-vat-number-format-validators-config/health.svg)

```
[![Health](https://phpackages.com/badges/rocketfellows-specific-country-vat-number-format-validators-config/health.svg)](https://phpackages.com/packages/rocketfellows-specific-country-vat-number-format-validators-config)
```

PHPackages © 2026

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