eboreum / phpstan-types
Custom PHPStan (https://phpstan.org/) types, e.g. `uuid-string`, `datetime-string`, and `email-string`.
Requires
- php: ^8.5
- ext-dom: *
- ext-iconv: *
- ext-intl: *
- beberlei/assert: ^3.3
- composer/semver: ^3.4
- egulias/email-validator: ^4.0
- globalcitizen/php-iban: ^4.2
- league/iso3166: ^4.4
- league/uri: ^7.8
- phpstan/phpstan: ^2.1
- ramsey/uuid: ^4.9
- respect/validation: ^2.2
- sabberworm/php-css-parser: ^9.3
- symfony/intl: ^8.0
- symfony/uid: ^8.0
- symfony/yaml: ^8.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.2
- overtrue/phplint: ^9.7
- phpunit/phpunit: ^13.1
- slevomat/coding-standard: ^8.28
- squizlabs/php_codesniffer: ^4.0
This package is auto-updated.
Last update: 2026-05-17 10:59:51 UTC
README

Custom PHPStan (https://phpstan.org/) types, e.g. uuid-string, datetime-string, and email-string.
Requirements
"php": "^8.5",
"ext-dom": "*",
"ext-iconv": "*",
"ext-intl": "*",
"beberlei/assert": "^3.3",
"composer/semver": "^3.4",
"egulias/email-validator": "^4.0",
"globalcitizen/php-iban": "^4.2",
"league/iso3166": "^4.4",
"league/uri": "^7.8",
"phpstan/phpstan": "^2.1",
"ramsey/uuid": "^4.9",
"respect/validation": "^2.2",
"sabberworm/php-css-parser": "^9.3",
"symfony/intl": "^8.0",
"symfony/uid": "^8.0",
"symfony/yaml": "^8.0"
For more information, see the composer.json file.
Installation
Via Composer (https://packagist.org/packages/eboreum/phpstan-types):
composer require --dev eboreum/phpstan-types
Via GitLab:
git clone git@gitlab.com:eboreum/phpstan-types.git
Load it into PHPStan
Include the extension in your phpstan.neon (or phpstan.neon.dist):
includes:
- vendor/eboreum/phpstan-types/extension.neon
Usage
Use the type names as PHPDoc type annotations in your PHP code:
/** @param uuid-string $id */
function findUser(string $id): void { ... }
/** @return datetime-string */
function getTimestamp(): string { ... }
/** @var email-string $address */
$address = 'user@example.com';
Generic types accept parameters directly in the annotation:
/** @param float-between<0,1> $ratio */
function scale(float $ratio): void { ... }
/** @param multiple-of-int<8> $alignment */
function alignTo(int $alignment): void { ... }
/** @param fixed-string<36> $uuid */
function parseUuid(string $uuid): void { ... }
Overview
| Definition | Description | Examples | Categories |
|---|---|---|---|
absolute-uri-string | Absolute RFC 3986 URI with a required scheme. Host name is optional. If host name is required, please use absolute-uri-with-host-string instead. | mailto:test@example.com, https://example.com, ftp://ftp.example.com/file.txt | π URI |
absolute-uri-with-host-string | Absolute RFC 3986 URI with a required scheme and required host name. | https://example.com, ftp://ftp.example.com/file.txt, http://localhost:8080/test | π URI |
alphanumeric-string | String containing only ASCII letters and digits. Optional length parameter supported. | abc123, A1B2C3, hello42 | π€ Simple string format |
ascii-letters-string | Only ASCII letters are allowed, both lowercase and uppercase. | hello, Lorem, ASCII | π€ Simple string format |
ascii-lowercase-string | Non-empty 7-bit ASCII string where all ASCII letters are lowercase; digits, symbols, and ASCII control characters are allowed. | hello, abc123, foo-bar, foo_bar | π€ Simple string format |
ascii-string | String containing only 7-bit ASCII characters. | hello, ABC123, foo-bar, test@example.com | π€ Simple string format |
ascii-uppercase-string | Non-empty 7-bit ASCII string where all ASCII letters are uppercase; digits, symbols, and ASCII control characters are allowed. | HELLO, ABC123, FOO-BAR, FOO_BAR | π€ Simple string format |
base64-string | String containing syntactically valid standard Base64 data. Define separately whether URL-safe Base64 and missing padding are accepted. | SGVsbG8=, YWJjMTIz, TWFu | π Encoding |
base64url-string | String containing syntactically valid Base64URL data using - and _ instead of + and /. Padding may optionally be omitted. | SGVsbG8, SGVsbG8=, eyJhbGciOiJIUzI1NiJ9, YWJjMTIz | π URI π Encoding |
bic-string | Valid ISO 9362 Business Identifier Code. | DEUTDEFF, NEDSZAJJ, DABADKKKXXX | π Identification π€ Business |
byte-length-between<M,N> | String whose byte length (strlen) is between M and N inclusive, where 0 <= M <= N. Sample formats: byte-length-between<1,255>, byte-length-between<8,8>, byte-length-between<Foo::MIN,Foo::MAX>. | π€ Simple string format | |
camel-case-string | Lower camelCase identifier beginning with a lowercase ASCII letter. | fooBar, myVariable1, apiClient | π€ Simple string format |
composer-version-string | Valid Composer version constraint string. | ^1.2, ~2.0, >=1.0 <2.0, dev-main | π€ Simple string format |
country-calling-code-string | International country calling code as a numeric string without leading + or 00. | 1, 44, 45, 49 | βοΈ Telephony |
css-color-string | CSS color string accepted by one of the supported color-specific types: hex, RGB/RGBA, HSL/HSLA, HWB, or named color. | #ff00aa, rgb(1, 2, 3), hsl(120 50% 50%), hwb(90 10% 20%), purple | π¨ Appearance (GUI) |
css-hex-color-string | CSS hexadecimal color literal. | #fff, #ff00aa, #1234, #11223344 | π¨ Appearance (GUI) |
css-hsl-color-string | CSS HSL color function in normalized form (no leading/trailing/repeated spaces inside parentheses, and no semicolons). Concrete grammar validation is delegated to sabberworm/php-css-parser. | hsl(0 100% 50%), hsla(120, 50%, 50%, 0.5), hsl(220 90% 55% / 0.5) | π¨ Appearance (GUI) |
css-hwb-color-string | CSS HWB color function in normalized form (no leading/trailing/repeated spaces inside parentheses, and no semicolons). Concrete grammar validation is delegated to sabberworm/php-css-parser. | hwb(0 0% 0%), hwb(220 10% 10% / 0.5), hwb(220 10% 85%) | π¨ Appearance (GUI) |
css-length-string | CSS length token using a known CSS length unit, or unitless zero. This intentionally excludes percentages, keywords, and calc(...); those can be modeled by future, broader CSS value types. | 0, 12px, -1.5rem, .5em, 100dvh | π¨ Appearance (GUI) |
css-named-color-string | CSS named color keyword. Should be validated against the CSS named color list rather than by regex alone. | red, purple, rebeccapurple, transparent, currentcolor | π¨ Appearance (GUI) |
css-rgb-color-string | CSS RGB color function in normalized form (no leading/trailing/repeated spaces inside parentheses, and no semicolons). Allows legacy comma syntax and modern space/slash syntax. | rgb(1, 2, 3), rgb(1, 2, 3, 0.5), rgba(1, 2, 3, 0.5), rgb(1 2 3 / 50%) | π¨ Appearance (GUI) |
date-string | ISO 8601 calendar date string with month constrained to 01-12 and day constrained to 01-31, then validated as a real Gregorian calendar date to reject magic/relative date strings. | 2025-01-31, 1999-12-24, 2024-02-29 | π Date |
datetime-iso8601-local-string | Strict ISO-like local date-time string without timezone offset, using T as separator, with month/day/hour/minute/second constrained to valid numeric ranges before full calendar validation. | 2025-01-31T13:45:00, 2024-12-24T08:00:00 | π Date π Time |
datetime-iso8601-string | Strict ISO-like date-time string using T as separator and timezone as either P offset or UTC Z. | 2025-01-31T13:45:00+00:00, 2024-12-24T08:00:00+01:00, 2025-01-31T13:45:00Z | π Date π Time |
datetime-local-string | Flexible local date-time string without timezone offset, allowing either T or space between date and time, with month/day/hour/minute/second constrained to valid numeric ranges before full calendar validation. | 2025-01-31T13:45:00, 2025-01-31 13:45:00 | π Date π Time |
datetime-string | Flexible date-time string with timezone, allowing either T or space separator, and timezone as P, O, or UTC Z. | 2025-01-31T13:45:00+00:00, 2025-01-31 13:45:00+0000, 2025-01-31T13:45:00Z | π Date π Time |
decimal-string | Canonical decimal number string using . as decimal separator. Scientific notation is allowed. Cannot be expected to be reliably converted to int because the value may exceed PHP_FLOAT_MAX. To disallow scientific notation, intersect with disallow-scientific-notation, i.e. disallow-scientific-notation&decimal-string. | 0, 12.34, 1e10, -1.5E-3 | π’ Numbers |
decimal-string<I,D,E> | Same as decimal-string, but restricts the string sizes of the numbers allowed.Use I (int<1,max>) to control the max string length the integer part.Use D (int<1,max>) to control the max string length of the decimal part.Use E (int<1,max>\|null) to control the max string length the exponent part (scientific notation).β οΈ This is advisible for user input values! If you use perform calculations on large number (e.g. using BCMath, user-submitted values that are very large may cause performance issues and errors). | π’ Numbers | |
digit-string | Non-empty ASCII digit sequence. | 1, 42, 000123 | π’ Numbers |
disallow-scientific-notation | Disallow scientific notation, e.g. 2e3, for numeric string valus. Must be used in intersection with one of: decimal-string, the *-decimal-string types, int-as-string, the *-int-as-string types. | π’ Numbers | |
duration-iso8601-string | ISO 8601 duration string. | P1D, PT30M, P2Y6M5DT12H35M30S | π Date π Time |
e164-string | E.164 formatted phone number: + followed by up to 15 digits, no spaces or separators. | +4512345678, +14155552671, +4412345678 | βοΈ Telephony |
ean-string | Valid EAN-8 or EAN-13 barcode string with correct check digit. | 73513537, 4006381333931, 5901234123457 | π Identification |
eid-string | eUICC Identifier for embedded SIM (eSIM) hardware; globally unique 32-digit numeric string identifying the eSIM chip. | 89049032426600000000000000001234, 89033024000000000000000000010001 | βοΈ Telephony |
email-string | Syntactically valid email address. Specify whether DNS/MX checks and internationalized addresses are included. | user@example.com, john.doe+test@gmail.com, a@b.dk | π§ Email |
even-int | Integer divisible by 2. | 0, 2, -4, 42 | π’ Numbers |
file-extension-string | File extension without leading dot, path separators, NUL, or whitespace; dot-separated multi-part extensions are allowed. | txt, pdf, docx, tar, tar.gz | |
file-name-string | Portable filename segment valid across Windows, macOS, and Linux, excluding dot-only segments (. and ..). | document.txt, invoice-2025.pdf, my_photo.png | π File system |
fixed-byte-string<N> | String whose byte length is exactly N; uses byte length, not character count. Sample formats: fixed-byte-string<4>, fixed-byte-string<Foo::MY_INT>. | abcd, 12345678 | π€ Simple string format |
fixed-string<N> | String whose character length is exactly N; multibyte-safe. Sample formats: fixed-string<4>, fixed-string<Foo::MY_INT>. | abcd, æøΓ₯1 | π€ Simple string format |
float-between<MIN,MAX> | Float constrained to the inclusive range from MIN to MAX, where both bounds are decimal literals and MIN <= MAX. Sample formats: float-between<0,1>, float-between<-1.5,2.5>, float-between<Foo::MIN,Foo::MAX>. | π’ Numbers | |
gtin-string | Valid Global Trade Item Number in GTIN-8, GTIN-12, GTIN-13, or GTIN-14 form with correct GS1 check digit. | 73513537, 036000291452, 4006381333931, 00012345600012 | π Identification π€ Business |
hex-lowercase-string | Non-empty lowercase hexadecimal string. Optional length parameter supported. | deadbeef, ff00aa, 123abc | π€ Simple string format |
hex-string | Non-empty hexadecimal string. Optional length parameter supported. | deadBEEF, ff00aa, ABC123 | π€ Simple string format π§© Content type |
hex-uppercase-string | Non-empty uppercase hexadecimal string. Optional length parameter supported. | DEADBEEF, FF00AA, ABC123 | π€ Simple string format |
hostname-string | Valid DNS hostname without scheme, port, path, query, or fragment. Define IDN/punycode behavior. | example.com, localhost, api.internal | π URI |
http-header-name | Valid HTTP header field-name token (RFC 7230 token syntax). | Content-Type, X-Request-ID, ETag | π Web/HTTP |
http-header-value | Valid HTTP header field-value without CR/LF control characters. | application/json, Bearer abc.def.ghi, text/plain; charset=utf-8 | π Web/HTTP |
http-method-string | Valid uppercase HTTP request method token. | GET, POST, PATCH, DELETE | π URI π Web/HTTP |
http-url-string | Absolute web URL with scheme http or https and a required host. | http://example.com, https://example.com, http://localhost:8080/test | π URI π Web/HTTP |
iban-string | Valid International Bank Account Number. Prefer validating both structure and checksum. | DK5000400440116243, GB82WEST12345698765432 | π Identification π° Money |
iccid-string | SIM card Integrated Circuit Card Identifier; typically 19β20 digits, may include a trailing Luhn check digit. | 8945026102100024374F, 89314404000025113290 | βοΈ Telephony |
idd-prefixed-phone-number-string | International phone number written with the IDD exit prefix 00 instead of +. | 004512345678, 00447911123456, 001415555... | βοΈ Telephony |
imei-string | International Mobile Equipment Identity; 15-digit numeric string identifying mobile equipment, with a Luhn check digit. | 356938035643809, 490154203237518 | βοΈ Telephony |
imeisv-string | International Mobile Equipment Identity and Software Version; 16-digit variant of IMEI including a 2-digit software version. | 3569380356438090, 4901542032375180 | βοΈ Telephony |
imsi-string | International Mobile Subscriber Identity; 14β15-digit numeric string identifying a subscriber on a mobile network, composed of MCC + MNC + MSIN. | 238010123456789, 310260000000000 | βοΈ Telephony |
int-as-string | Canonical integer string. Scientific notation is allowed. Cannot be expected to be reliably converted to int because the value may exceed PHP_INT_MIN or PHP_INT_MAX. To disallow scientific notation, intersect with disallow-scientific-notation, i.e. disallow-scientific-notation&int-as-string. | 0, 42, -99, 1e5, -1E5 | π’ Numbers |
int-as-string<I,E> | Same as int-as-string, but restricts the string size of the numbers allowed.Use I (int<1,max>) to control the max string length the integer part.Use E (int<1,max>\|null) to control the max string length the exponent part (scientific notation).β οΈ β οΈ This is advisible for user input values! If you use perform calculations on large number (e.g. using BCMath, user-submitted values that are very large may cause performance issues and errors). | π’ Numbers | |
international-phone-number-string | Internationally formatted phone number including country calling code, in any recognized notation (e.g. E.164, IDD-prefixed, or human-readable with separators). | +4512345678, 004512345678, +1 415 555 2671 | βοΈ Telephony |
ip-string | Valid IPv4 or IPv6 address string. | 127.0.0.1, ::1, 2001:db8::1 | π§ Network |
ipv4-cidr-string | IPv4 CIDR block with required prefix length. | 192.168.0.0/24, 10.0.0.1/32 | π§ Network |
ipv4-string | Valid IPv4 address in dotted-decimal notation. Prefer rejecting octal, hex, shorthand, and leading-zero forms. | 127.0.0.1, 192.168.1.1, 8.8.8.8 | π§ Network |
ipv6-cidr-string | IPv6 CIDR block with required prefix length. | 2001:db8::/32, ::1/128, fe80::/64 | π§ Network |
ipv6-string | Valid IPv6 address, including compressed forms. Define whether IPv4-mapped IPv6 is accepted. | ::1, 2001:db8::1, fe80::1 | π§ Network |
isbn-string | Valid ISBN-10 or ISBN-13 string (hyphens/spaces allowed) with correct checksum. | 0306406152, 0-306-40615-2, 978-0-306-40615-7 | π Identification |
iso-3166-1-alpha-2-string | ISO 3166-1 alpha-2 country code. | DK, US, DE | π Country |
iso-3166-1-alpha-3-string | ISO 3166-1 alpha-3 country code. | DNK, USA, DEU | π Country |
iso-3166-1-numeric-string | ISO 3166-1 numeric country code as exactly three digits. | 208, 840, 276 | π Country |
iso-3166-2-string | Structurally valid ISO 3166-2 subdivision code using a known ISO 3166-1 alpha-2 country prefix and a 1-3 character subdivision suffix. This validates structure and country prefix, not membership in a full subdivision database. | US-CA, DK-84, DE-BE, GB-BKM | π Country |
iso-639-1-string | ISO 639-1 language code. | en, da, fr | π¬ Language |
iso-639-2-string | ISO 639-2 language code. | eng, dan, fra | π¬ Language |
iso-639-3-string | ISO 639-3 language code. | eng, dan, fra | π¬ Language |
iso-639-6-string | ISO 639-6 language code. | engl, dani | π¬ Language |
iso4217-currency-code-string | ISO 4217 currency code. | USD, EUR, DKK, JPY | π° Money |
json-string | String that decodes as valid JSON. Define whether duplicate keys, top-level scalars, and invalid UTF-8 are accepted. | {"foo":"bar"}, [1,2,3], true, "hello" | π£ Programming |
jwt-string | JSON Web Token in compact serialization form. This should validate syntax only unless signature verification is explicitly included. | eyJhbGciOi...eyJzdWIiOi...SflKxwRJS... | π Authentication π Encoding |
kebab-case-string | Lowercase kebab-case identifier using hyphens as separators. | hello-world, api-client, my-variable-1 | π€ Simple string format |
letters-string | A string containing only letters, including Unicode letters. | abc, æøΓ₯, ΓΓΓ | π€ Simple string format |
locale-string | Locale identifier matching the configured locale regex. | en, en_US, da-DK | π Country π¬ Language βοΈ Writing |
mac-address-string | Valid MAC address string. Define accepted notation variants. | 00:1A:2B:3C:4D:5E, AA-BB-CC-DD-EE-FF | π Identification π§ Network |
mb-lowercase-string | A UTF-8 string, which may contain any digits, symbols, ASCII control characters, but all letters must be lowercase according to mb_strtolower(..., 'UTF-8'). | hello, foo_bar, ΓΈΓ¦Γ₯, hΓ©llo | π€ Simple string format |
mb-uppercase-string | A UTF-8 string, which may contain any digits, symbols, ASCII control characters, but all letters must be uppercase according to mb_strtoupper(..., 'UTF-8'). | HELLO, FOO_BAR, ΓΓΓ
, HΓLLO | π€ Simple string format |
mcc-string | Mobile Country Code; a 3-digit numeric string identifying the country of a mobile network operator. | 238, 310, 262 | βοΈ Telephony |
mccmnc-string | Combined Mobile Country Code and Mobile Network Code identifying a unique PLMN/operator; typically 5 or 6 digits. | 23801, 310260, 26201 | βοΈ Telephony |
md5-string | Exactly 32 lowercase hexadecimal characters. | d41d8cd98f00b204e9800998ecf8427e | π Encoding |
meid-string | Mobile Equipment Identifier used in CDMA networks; 14 hexadecimal digits or 18 decimal digits. | A0000000049E68, 354403064522046 | βοΈ Telephony |
mime-type-string | MIME media type with valid type/subtype tokens. Define whether parameters are allowed. | text/plain, application/json, image/png | π File system π§© Content type |
mnc-string | Mobile Network Code; a 2- or 3-digit numeric string identifying the operator within a country (used together with MCC). | 01, 26, 001 | βοΈ Telephony |
msin-string | Mobile Subscription Identification Number; the subscriber-specific suffix of an IMSI, represented here as 9 or 10 digits. | 012345678, 1234567890 | βοΈ Telephony |
msisdn-string | Mobile Station International Subscriber Directory Number; the full E.164 number used to route calls and SMS to a subscriber, without the leading +. | 4512345678, 14155552671 | βοΈ Telephony |
msrn-string | Mobile Station Roaming Number; a temporary MSISDN-like number assigned by a visited network to route calls to a roaming subscriber. | 4599887766, 14087654321 | βοΈ Telephony |
multiple-of-int<N> | Integer divisible by non-zero integer N. Sample formats: multiple-of-int<2>, multiple-of-int<3>, multiple-of-int<-5>, multiple-of-int<Foo::MY_INT>. | π’ Numbers | |
national-significant-number-string | National Significant Number; the subscriber number portion of a phone number excluding the country calling code. | 512345678, 7911123456, 30123456 | βοΈ Telephony |
negative-decimal-string | Negative decimal number string in decimal format or scientific notation. To disallow scientific notation, intersect with disallow-scientific-notation, i.e. disallow-scientific-notation&negative-decimal-string. | -0.1, -1, -42.5, -1e5, -1.5E-3 | π’ Numbers |
negative-float | Float strictly less than 0.0. Decide whether negative zero (-0.0) is included or rejected. | -1.5, -0.1, -42.0 | π’ Numbers |
negative-int-as-string | Canonical integer string. Scientific notation is allowed. Cannot be expected to be reliably converted to int because the value may exceed PHP_INT_MIN or PHP_INT_MAX. I is the max string length the integer part is allowed to be. E is the max string length the exponent is allowed to be (using scientific notation). To disallow scientific notation, intersect with disallow-scientific-notation, i.e. disallow-scientific-notation&negative-int-as-string. | -1, -42, -999999, -1e5 | π’ Numbers |
no-whitespace-string | String containing none of PHP trim()'s default whitespace characters. | hello, abc123, foo-bar | π€ Simple string format |
non-empty-when-trimmed-string | String whose value is non-empty after applying PHP trim() with default characters. | hello, x, 123 | π€ Simple string format |
non-negative-decimal-string | Decimal number string with a value >= 0 in decimal format or scientific notation. To disallow scientific notation, intersect with disallow-scientific-notation, i.e. disallow-scientific-notation&non-negative-decimal-string. | 0, 0.0, 42.5, 1e5, 1.5E-3 | π’ Numbers |
non-negative-float | Float greater than or equal to 0.0. Decide whether negative zero (-0.0) is accepted. | 0.0, 0.5, 42.1 | π’ Numbers |
non-negative-int-as-string | Integer string with a value >= 0 in decimal format or scientific notation. Cannot be expected to be reliably converted to int because the value may exceed PHP_INT_MAX. To disallow scientific notation, intersect with disallow-scientific-notation, i.e. disallow-scientific-notation&non-negative-int-as-string. | 0, 1, 42, 999999, 1e5 | π’ Numbers |
non-positive-decimal-string | Decimal number string with a value <= 0 in decimal format or scientific notation. To disallow scientific notation, intersect with disallow-scientific-notation, i.e. disallow-scientific-notation&non-positive-decimal-string. | 0, 0.0, -0.1, -42.5, -1e5 | π’ Numbers |
non-positive-float | Float less than or equal to 0.0. Decide whether negative zero (-0.0) is accepted. | 0.0, -0.5, -42.1 | π’ Numbers |
non-positive-int-as-string | Integer string with a value <= 0 in decimal format or scientific notation. Cannot be expected to be reliably converted to int because the value may exceed PHP_INT_MIN. To disallow scientific notation, intersect with disallow-scientific-notation, i.e. disallow-scientific-notation&non-positive-int-as-string. | 0, -1, -42, -999999, -1e5 | π’ Numbers |
odd-int | Integer not divisible by 2. | 1, -1, 3, 41 | π’ Numbers |
pascal-case-string | PascalCase identifier beginning with an uppercase ASCII letter. | FooBar, ApiClient, MyVariable1 | π€ Simple string format |
port-string | TCP/UDP port number represented as a string in the range 0β65535. | 80, 443, 8080, 65535 | π§ Network |
positive-decimal-string | Positive decimal number string excluding zero in decimal format or scientific notation. To disallow scientific notation, intersect with disallow-scientific-notation, i.e. disallow-scientific-notation&positive-decimal-string. | 0.1, 1, 42.5, 1e5, 1.5E-3 | π’ Numbers |
positive-float | Float strictly greater than 0.0. | 0.1, 1.5, 42.0 | π’ Numbers |
positive-int-as-string | Positive integer string excluding zero in decimal format or scientific notation. Cannot be expected to be reliably converted to int because the value may exceed PHP_INT_MAX. To disallow scientific notation, intersect with disallow-scientific-notation, i.e. disallow-scientific-notation&positive-int-as-string. | 1, 42, 999999, 1e5 | π’ Numbers |
power-of-two-int | Positive integer that is an exact power of two. | 1, 2, 4, 8, 1024 | π’ Numbers |
private-ip-string | Private IPv4 or IPv6 address (RFC 1918 IPv4 or RFC 4193 Unique Local IPv6). Intended for intersections like ip-string&private-ip-string, ipv4-string&private-ip-string, or ipv6-string&private-ip-string. | 10.0.0.1, 192.168.1.1, fd12:3456:789a::1 | π§ Network |
public-ip-string | Public IPv4 or IPv6 address (non-private and non-reserved). Intended for intersections like ip-string&public-ip-string, ipv4-string&public-ip-string, or ipv6-string&public-ip-string. | 8.8.8.8, 1.1.1.1, 2001:4860:4860::8888 | π§ Network |
regex-compliant-string<R> | String must match the provided regular expression, R. Sample formats: regex-compliant-string<'/^foo$/'>, regex-compliant-string<'[^e]'>, regex-compliant-string<Foo::MY_REGEX>. This type can be difficult to comprehend and use correctly. It is not dynamic and generally only works for string literals. | π§ Advanced string format | |
semver-string | Valid semantic version string. | 1.0.0, 2.1.3-beta, 1.2.3+build5 | π€ Simple string format |
sha1-string | Exactly 40 lowercase hexadecimal characters. | da39a3ee5e6b4b0d3255bfef95601890afd80709 | π Encoding |
sha256-string | Exactly 64 lowercase hexadecimal characters. | e3b0c44298fc1c149afbf4c8996fb924... | π Encoding |
sha512-string | Exactly 128 lowercase hexadecimal characters. | cf83e1357eefb8bdf1542850d66d8007... | π Encoding |
shouted-snake-case-string | Uppercase snake-case identifier. | FOO, FOO_BAR, API_V2_KEY | π€ Simple string format |
slug-string | URL/path-friendly lowercase slug. | hello-world, my-blog-post, abc123 | π URI |
snake-case-string | Lowercase snake-case identifier. | foo, foo_bar, api_v2_key | π€ Simple string format |
string-length-between<M,N> | String whose character length (multibyte-safe) is between M and N inclusive, where 0 <= M <= N. Sample formats: string-length-between<1,255>, string-length-between<8,8>, string-length-between<Foo::MIN_LENGTH,Foo::MAX_LENGTH>. | π€ Simple string format | |
subnet-mask | Valid IPv4 subnet mask with contiguous leading 1 bits and trailing 0 bits. | 255.255.255.0, 255.255.0.0, 255.255.255.255 | π§ Network |
tel-uri-string | RFC 3966 tel: URI identifying a telephone resource; supports both global numbers (E.164 with +) and local numbers. | tel:+4512345678, tel:+14155552671, tel:0800-12345 | βοΈ Telephony π URI |
timezone-string | Valid IANA timezone identifier. | UTC, Europe/Copenhagen, America/New_York | π Date π Time |
trimmed-non-empty-string | Non-empty string with no leading or trailing PHP trim() default whitespace. | hello, abc123, foo bar | π€ Simple string format |
ulid-string | Valid ULID string as accepted by Symfony\Component\Uid\Ulid::isValid(...). | 01ARZ3NDEKTSV4RRFFQ69G5FAV | π Identification |
upc-string | Valid 12-digit UPC-A barcode with correct GS1 check digit. This closes the common retail barcode gap between EAN-only validation and the broader gtin-string. | 036000291452, 012345678905 | π Identification π€ Business |
uri-string | Syntactically valid RFC 3986 URI (including relative references) as accepted by League\Uri\Uri::createFromString(...). | mailto:test@example.com, /relative/path, https://example.com, http://smΓΈrrebrΓΈd.dk | π URI |
url-string | Absolute HTTP or HTTPS URL with valid host and optional port/path/query/fragment, as accepted by League\Uri\Uri::createFromString(...). | https://example.com, http://localhost:8080, https://api.example.com/v1, http://smΓΈrrebrΓΈd.dk | π URI π Web/HTTP |
urn-string | RFC 8141 URN with the urn scheme, a namespace identifier, and a non-empty namespace-specific string. | urn:isbn:0451450523, urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8, urn:ietf:rfc:8141 | π URI π Identification |
uuid-string | Valid UUID string as accepted by Ramsey\Uuid\Uuid::isValid(...). | 550e8400-e29b-41d4-a716-446655440000 | π Identification |
uuid1-string | Valid UUID string with version 1 specifically. | 6ba7b810-9dad-11d1-80b4-00c04fd430c8 | π Identification |
uuid3-string | Valid UUID string with version 3 specifically. | 6fa459ea-ee8a-3ca4-894e-db77e160355e | π Identification |
uuid4-string | Valid UUID string with version 4 specifically. | 550e8400-e29b-41d4-a716-446655440000 | π Identification |
uuid5-string | Valid UUID string with version 5 specifically. | 21f7f8de-8051-5b89-8680-0195ef798b6a | π Identification |
uuid6-string | Valid UUID string with version 6 specifically. | 1ec9414c-232a-6b00-b3c8-9e6bdeced846 | π Identification |
uuid7-string | Valid UUID string with version 7 specifically. | 01890f47-6c4c-7b3d-bc44-5b6d1e4f8c92 | π Identification |
uuid8-string | Valid UUID string with version 8 specifically. | 2489e9ad-2ee2-8e00-8ec9-32d5f69181c0 | π Identification |
webhook-url | Absolute HTTP or HTTPS URL with a required host and no fragment (#...) part. | https://example.com/webhooks/inbound, http://localhost:8080/hook?token=abc123, https://api.example.com/hook | π URI π Web/HTTP |
xml-string | String that parses as a well-formed XML document. This closes the structured document gap next to json-string for projects that exchange XML payloads. | <root/>, <?xml version="1.0"?><root><item id="1"/></root> | π£ Programming π§© Content type |
yaml-string | String that parses as valid YAML using symfony/yaml. | foo: bar, items:\n - one\n - two, true | π£ Programming |
For parameterized types, e.g. fixed-string<N>, you may use class constant references instead of string literals. E.g. fixed-string<Foo::MY_INT>.
License & Disclaimer
Licensed under the MIT License. See LICENSE. Basically: Use this library at your own risk.
Contributing
We prefer that you create an issue and or a merge request at https://gitlab.com/eboreum/phpstan-types, and have a discussion about a feature or bug here.
Credits
Authors
- Kasper SΓΈfren (kafoso)
E-mail: soefritz@gmail.com
Homepage: https://gitlab.com/kafoso
Vibe-coded
DISCLAIMER: Parts of this code base has been made using AI, namely GPT-5.5! Although, there was an adult in the room during this process.