germania-kg/vatidno

Interfaces and traits for VAT ID numbers.

1.3.0 2023-01-03 14:25 UTC

This package is auto-updated.

Last update: 2024-11-30 01:39:32 UTC


README

Interfaces, traits, and filters for dealing with VAT ID numbers

Packagist PHP version Tests

Installation

$ composer require germania-kg/vatidno

Interfaces

VatIdNoProviderInterface

Provides a method VatIdNo to retrieve the VATIN as string.

use Germania\VatIdNo\VatIdNoProviderInterface;

/**	
 * @return string
 */
public function getVatIdNo();

VatIdNoAwareInterface

Extends VatIdNoProviderInterface and provides a method setVatIdNo, allowing you to set the VATIN.

use Germania\VatIdNo\VatIdNoProviderInterface;

/**	
 * @param  string $vatin
 * @return self
 */
public function setVatIdNo( $vatin );
public function getVatIdNo();

Traits

VatIdNoProviderTrait

Implements the VatIdNoProviderInterface and provides a public property vatin:

use Germania\VatIdNo\VatIdNoProviderInterface;
use Germania\VatIdNo\VatIdNoProviderTrait;

class MyClass implements VatIdNoProviderInterface {

	use VatIdNoProviderTrait;
	
	public function __construct( $vatin ) {
		$this->vatin = $vatin;
	}
}

VatIdNoAwareTrait

Implements the VatIdNoAwareInterface. Utilizes the VatIdNoProviderTrait.

use Germania\VatIdNo\VatIdNoAwareInterface;
use Germania\VatIdNo\VatIdNoAwareTrait;

class MyClass implements VatIdNoAwareInterface {
	use VatIdNoAwareTrait;
}

// Simple example
$object1 = new MyClass;
$object1->setVatIdNo( "XY000000" );

// Fluent interface
echo $object1->setVatIdNo( "XY000000" )->vatin;

// Setting using VatIdNoProviderInterface
$object2 = new MyClass;
$object2->setVatIdNo( $object1 );

Filters

WithVatIdNoFilterIterator

Filter for records that do provide a VATIN. These may be:

  • Arrays with vatin key, and non-empty value
  • Objects with vatin property, and non-empty value
  • Instances of VatIdNoProviderInterface where getVatIdNo results not empty
<?php
use Germania\VatIdNo\Filters\WithVatIdNoFilterIterator;

$records = new \ArrayIterator( ask_database() );

// Allow custom field names in arrays or objects
$records_with_vatin = new WithoutVatIdNoFilterIterator( $records );
$records_with_vatin = new WithoutVatIdNoFilterIterator( $records, "ust_id" );

foreach( $records_with_vatin as $item):
 // Do things like validating
endforeach;

WithoutVatIdNoFilterIterator

Filter for records that do not provide a VATIN. These may be:

  • Arrays lacking vatin key, or empty vatin element
  • Objects lacking vatin property, or empty vatin property
  • Instances of VatIdNoProviderInterface where getVatIdNo results empty
<?php
use Germania\VatIdNo\Filters\WithoutVatIdNoFilterIterator;

$records = new \ArrayIterator( ask_database() );

// Allow custom field names in arrays or objects
$records_lacking = new WithoutVatIdNoFilterIterator( $records );
$records_lacking = new WithoutVatIdNoFilterIterator( $records, "ust_id" );

foreach( $records_lacking as item):
 //...
endforeach;

Validation

To validate the VAT ID numbers, use a dedicated package like David de Boer's ddeboer/vatin package.

Development

$ git clone https://github.com/GermaniaKG/VatIdNo.git
$ cd VatIdNo
$ composer install

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:

$ composer test
# or
$ vendor/bin/phpunit