PHPackages                             smartemailing/types - 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. smartemailing/types

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

smartemailing/types
===================

Lightweight collection of handy PHP value objects

v5.0.0(6mo ago)9368.7k↓37.5%13[2 issues](https://github.com/smartemailing/types/issues)[2 PRs](https://github.com/smartemailing/types/pulls)1MITPHPPHP ^8.1CI passing

Since Jun 18Pushed 1mo ago8 watchersCompare

[ Source](https://github.com/smartemailing/types)[ Packagist](https://packagist.org/packages/smartemailing/types)[ RSS](/packages/smartemailing-types/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (35)Used By (1)

SmartEmailing \\ Types
======================

[](#smartemailing--types)

### Missing data types for PHP 8.1 and greater. Highly extendable, production tested.

[](#missing-data-types-for-php-81-and-greater-highly-extendable-production-tested)

[![MIT license](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://lbesson.mit-license.org/)[![Latest release](https://camo.githubusercontent.com/8d85a89dbcc75c08f13209b1e61462283e45f698ed140836b8dbe69aaac69b0e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f736d617274656d61696c696e672f74797065732e737667)](https://github.com/smartemailing/types/releases/)[![Downloads](https://camo.githubusercontent.com/c22631390150435e60db462bd97dc976fb9acb967fdb1239f4c21211122b8db9/68747470733a2f2f706f7365722e707567782e6f72672f736d617274656d61696c696e672f74797065732f642f746f74616c)](https://packagist.org/packages/smartemailing/types)

[![Build Status](https://github.com/smartemailing/types/workflows/build/badge.svg)](https://github.com/smartemailing/types/actions?query=workflow%3Abuild)[![Code coverage](https://camo.githubusercontent.com/d020bd310aad1dc428253983d1e8732e0491dd8a07830a26dc672315f758533c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f736d617274656d61696c696e672f74797065732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/smartemailing/types?branch=master)[![CodeClimate](https://camo.githubusercontent.com/e0c0aa995caf76b78b9bc1aa1f2aa9dc82202d0e97513c1713c3f7416e5c208f/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35333866636262656164623130633736666531342f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/smartemailing/types/maintainability)

Neverending data validation can be exhausting. Either you have to validate your data over and over again in every function you use it, or you have to rely it has already been validated somewhere else and risk potential problems.

Smelly, right?

Replacing validation hell with **Types** will make your code much more readable and less vulnerable to bugs.

**Types** wrap your data in value objects that are guaranteed to be **valid and normalized; or not to exist at all**. It allows you to use specific type hints instead of primitive types or arrays. Your code will be unbreakable and your IDE will love it.

[![](./docs/img/ide-love-2.png)](./docs/img/ide-love-2.png)

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [How does it work](#how-does-it-work)
    - [Wrapping raw value](#wrapping-raw-value)
    - [Extraction from array](#extraction-from-array)
- [String-extractable types](#string-extractable-types)
    - [E-mail address](#e-mail-address)
    - [Non-empty string](#non-empty-string)
    - [Domain](#domain)
    - [Hex 32](#hex-32)
    - [Hex Color](#hex-color)
    - [Hex Color Alpha](#hex-color-alpha)
    - [GUID](#guid)
    - [IP address](#ip-address)
    - [URL](#url)
    - [Company registration number](#company-registration-number)
    - [Phone number](#phone-number)
    - [ZIP code](#zip-code)
    - [JSON](#json)
    - [Base 64](#base-64)
    - [Iban](#iban)
    - [SwiftBic](#swiftbic)
    - [VatId](#vatid)
    - [CurrencyCode](#currencycode)
    - [CountryCode](#countrycode)
- [Int-extractable types](#int-extractable-types)
    - [Port](#port)
    - [Quantity](#quantity)
    - [Unsigned Integer](#unsigned-integer)
- [Float-extractable types](#float-extractable-types)
    - [Part](#part)
    - [Sigmoid function value](#sigmoid-function-value)
    - [Rectified Linear Unit function value](#rectified-linear-unit-function-value)
    - [Unsigned Float](#unsigned-float)
- [Array-extractable types](#array-extractable-types)
    - [DateTimeRange](#datetimerange)
    - [Duration](#duration)
    - [Address](#address)
    - [Price](#price)
    - [Login credentials](#login-credentials)
    - [Key-Value pair](#key-value-pair)
- [Array-types](#array-types)
    - [UniqueIntArray](#uniqueintarray)
    - [UniqueStringArray](#uniquestringarray)
- [Enum-extractable types](#enum-extractable-types)
    - [Lawful Basis For Processing](#lawful-basis-for-processing)
    - [Country code](#country-code)
    - [Currency code](#currency-code)
    - [Field of Application](#field-of-application)
    - [Time unit](#time-unit)
    - [Relation](#relation)
- [Primitive types](#primitive-types-and-arrays)
- [DateTimes](#datetimes)
- [Writing your own types](#writing-your-own-types)
- [How to contribute](#how-to-contribute)

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

[](#installation)

The recommended way to install is via Composer:

```
composer require smartemailing/types

```

How does it work
----------------

[](#how-does-it-work)

It is easy. You just initialize desired value object by simple one-liner. From this point, you have sanitized, normalized and valid data; or `SmartEmailing\Types\InvalidTypeException` to handle.

**Types** consist from:

- String-extractable types - validated strings (E-mail address, Domains, Hexadecimal strings, ...)
- Int-extractable types - validated integers (Port)
- Float-extractable types - validated floats (SigmoidValue, Part, ...)
- Enum-extractable types - enumerables (CountryCode, CurrencyCode, GDPR's Lawful purpose, ...)
- Composite (Array-extractable) types - structures containing multiple another types (Address, ...)
- DateTimes - extraction of DateTime and DateTimeImmutable
- Primitive types extractors and unique arrays

Different types provide different methods related to them, but all types share this extraction API:

### Wrapping raw value

[](#wrapping-raw-value)

```
