eboreum/phpstan-types

Custom PHPStan (https://phpstan.org/) types, e.g. `uuid-string`, `datetime-string`, and `email-string`.

Maintainers

Package info

gitlab.com/eboreum/phpstan-types

Issues

pkg:composer/eboreum/phpstan-types

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

dev-main 2026-05-17 12:47 UTC

This package is auto-updated.

Last update: 2026-05-17 10:59:51 UTC


README

license pipeline status coverage report PHPStan Level

eboreum-phpstan-types-logo

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

DefinitionDescriptionExamplesCategories
absolute-uri-stringAbsolute 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-stringAbsolute 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-stringString containing only ASCII letters and digits. Optional length parameter supported.abc123, A1B2C3, hello42πŸ”€ Simple string format
ascii-letters-stringOnly ASCII letters are allowed, both lowercase and uppercase.hello, Lorem, ASCIIπŸ”€ Simple string format
ascii-lowercase-stringNon-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-stringString containing only 7-bit ASCII characters.hello, ABC123, foo-bar, test@example.comπŸ”€ Simple string format
ascii-uppercase-stringNon-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-stringString containing syntactically valid standard Base64 data. Define separately whether URL-safe Base64 and missing padding are accepted.SGVsbG8=, YWJjMTIz, TWFuπŸ”€ Encoding
base64url-stringString containing syntactically valid Base64URL data using - and _ instead of + and /. Padding may optionally be omitted.SGVsbG8, SGVsbG8=, eyJhbGciOiJIUzI1NiJ9, YWJjMTIzπŸ”— URI
πŸ”€ Encoding
bic-stringValid 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-stringLower camelCase identifier beginning with a lowercase ASCII letter.fooBar, myVariable1, apiClientπŸ”€ Simple string format
composer-version-stringValid Composer version constraint string.^1.2, ~2.0, >=1.0 <2.0, dev-mainπŸ”€ Simple string format
country-calling-code-stringInternational country calling code as a numeric string without leading + or 00.1, 44, 45, 49☎️ Telephony
css-color-stringCSS 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-stringCSS hexadecimal color literal.#fff, #ff00aa, #1234, #11223344🎨 Appearance (GUI)
css-hsl-color-stringCSS 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-stringCSS 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-stringCSS 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-stringCSS 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-stringCSS 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-stringISO 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-stringStrict 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-stringStrict 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-stringFlexible 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-stringFlexible 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-stringCanonical 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-stringNon-empty ASCII digit sequence.1, 42, 000123πŸ”’ Numbers
disallow-scientific-notationDisallow 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-stringISO 8601 duration string.P1D, PT30M, P2Y6M5DT12H35M30SπŸ“… Date πŸ•’ Time
e164-stringE.164 formatted phone number: + followed by up to 15 digits, no spaces or separators.+4512345678, +14155552671, +4412345678☎️ Telephony
ean-stringValid EAN-8 or EAN-13 barcode string with correct check digit.73513537, 4006381333931, 5901234123457πŸ†” Identification
eid-stringeUICC Identifier for embedded SIM (eSIM) hardware; globally unique 32-digit numeric string identifying the eSIM chip.89049032426600000000000000001234, 89033024000000000000000000010001☎️ Telephony
email-stringSyntactically 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-intInteger divisible by 2.0, 2, -4, 42πŸ”’ Numbers
file-extension-stringFile extension without leading dot, path separators, NUL, or whitespace; dot-separated multi-part extensions are allowed.txt, pdf, docx, tar, tar.gz
file-name-stringPortable 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-stringValid 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-stringNon-empty lowercase hexadecimal string. Optional length parameter supported.deadbeef, ff00aa, 123abcπŸ”€ Simple string format
hex-stringNon-empty hexadecimal string. Optional length parameter supported.deadBEEF, ff00aa, ABC123πŸ”€ Simple string format
🧩 Content type
hex-uppercase-stringNon-empty uppercase hexadecimal string. Optional length parameter supported.DEADBEEF, FF00AA, ABC123πŸ”€ Simple string format
hostname-stringValid DNS hostname without scheme, port, path, query, or fragment. Define IDN/punycode behavior.example.com, localhost, api.internalπŸ”— URI
http-header-nameValid HTTP header field-name token (RFC 7230 token syntax).Content-Type, X-Request-ID, ETag🌐 Web/HTTP
http-header-valueValid HTTP header field-value without CR/LF control characters.application/json, Bearer abc.def.ghi, text/plain; charset=utf-8🌐 Web/HTTP
http-method-stringValid uppercase HTTP request method token.GET, POST, PATCH, DELETEπŸ”— URI
🌐 Web/HTTP
http-url-stringAbsolute 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-stringValid International Bank Account Number. Prefer validating both structure and checksum.DK5000400440116243, GB82WEST12345698765432πŸ†” Identification
πŸ’° Money
iccid-stringSIM card Integrated Circuit Card Identifier; typically 19–20 digits, may include a trailing Luhn check digit.8945026102100024374F, 89314404000025113290☎️ Telephony
idd-prefixed-phone-number-stringInternational phone number written with the IDD exit prefix 00 instead of +.004512345678, 00447911123456, 001415555...☎️ Telephony
imei-stringInternational Mobile Equipment Identity; 15-digit numeric string identifying mobile equipment, with a Luhn check digit.356938035643809, 490154203237518☎️ Telephony
imeisv-stringInternational Mobile Equipment Identity and Software Version; 16-digit variant of IMEI including a 2-digit software version.3569380356438090, 4901542032375180☎️ Telephony
imsi-stringInternational 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-stringCanonical 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-stringInternationally 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-stringValid IPv4 or IPv6 address string.127.0.0.1, ::1, 2001:db8::1πŸ–§ Network
ipv4-cidr-stringIPv4 CIDR block with required prefix length.192.168.0.0/24, 10.0.0.1/32πŸ–§ Network
ipv4-stringValid 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-stringIPv6 CIDR block with required prefix length.2001:db8::/32, ::1/128, fe80::/64πŸ–§ Network
ipv6-stringValid IPv6 address, including compressed forms. Define whether IPv4-mapped IPv6 is accepted.::1, 2001:db8::1, fe80::1πŸ–§ Network
isbn-stringValid 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-stringISO 3166-1 alpha-2 country code.DK, US, DE🌍 Country
iso-3166-1-alpha-3-stringISO 3166-1 alpha-3 country code.DNK, USA, DEU🌍 Country
iso-3166-1-numeric-stringISO 3166-1 numeric country code as exactly three digits.208, 840, 276🌍 Country
iso-3166-2-stringStructurally 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-stringISO 639-1 language code.en, da, frπŸ’¬ Language
iso-639-2-stringISO 639-2 language code.eng, dan, fraπŸ’¬ Language
iso-639-3-stringISO 639-3 language code.eng, dan, fraπŸ’¬ Language
iso-639-6-stringISO 639-6 language code.engl, daniπŸ’¬ Language
iso4217-currency-code-stringISO 4217 currency code.USD, EUR, DKK, JPYπŸ’° Money
json-stringString 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-stringJSON Web Token in compact serialization form. This should validate syntax only unless signature verification is explicitly included.eyJhbGciOi...eyJzdWIiOi...SflKxwRJS...πŸ” Authentication
πŸ”€ Encoding
kebab-case-stringLowercase kebab-case identifier using hyphens as separators.hello-world, api-client, my-variable-1πŸ”€ Simple string format
letters-stringA string containing only letters, including Unicode letters.abc, æøΓ₯, Γ‰Γ”Γ‘πŸ”€ Simple string format
locale-stringLocale identifier matching the configured locale regex.en, en_US, da-DK🌍 Country
πŸ’¬ Language
✍️ Writing
mac-address-stringValid MAC address string. Define accepted notation variants.00:1A:2B:3C:4D:5E, AA-BB-CC-DD-EE-FFπŸ†” Identification
πŸ–§ Network
mb-lowercase-stringA 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-stringA 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-stringMobile Country Code; a 3-digit numeric string identifying the country of a mobile network operator.238, 310, 262☎️ Telephony
mccmnc-stringCombined Mobile Country Code and Mobile Network Code identifying a unique PLMN/operator; typically 5 or 6 digits.23801, 310260, 26201☎️ Telephony
md5-stringExactly 32 lowercase hexadecimal characters.d41d8cd98f00b204e9800998ecf8427eπŸ”€ Encoding
meid-stringMobile Equipment Identifier used in CDMA networks; 14 hexadecimal digits or 18 decimal digits.A0000000049E68, 354403064522046☎️ Telephony
mime-type-stringMIME media type with valid type/subtype tokens. Define whether parameters are allowed.text/plain, application/json, image/pngπŸ“„ File system
🧩 Content type
mnc-stringMobile Network Code; a 2- or 3-digit numeric string identifying the operator within a country (used together with MCC).01, 26, 001☎️ Telephony
msin-stringMobile Subscription Identification Number; the subscriber-specific suffix of an IMSI, represented here as 9 or 10 digits.012345678, 1234567890☎️ Telephony
msisdn-stringMobile 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-stringMobile 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-stringNational Significant Number; the subscriber number portion of a phone number excluding the country calling code.512345678, 7911123456, 30123456☎️ Telephony
negative-decimal-stringNegative 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-floatFloat 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-stringCanonical 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-stringString containing none of PHP trim()'s default whitespace characters.hello, abc123, foo-barπŸ”€ Simple string format
non-empty-when-trimmed-stringString whose value is non-empty after applying PHP trim() with default characters.hello, x, 123πŸ”€ Simple string format
non-negative-decimal-stringDecimal 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-floatFloat 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-stringInteger 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-stringDecimal 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-floatFloat 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-stringInteger 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-intInteger not divisible by 2.1, -1, 3, 41πŸ”’ Numbers
pascal-case-stringPascalCase identifier beginning with an uppercase ASCII letter.FooBar, ApiClient, MyVariable1πŸ”€ Simple string format
port-stringTCP/UDP port number represented as a string in the range 0–65535.80, 443, 8080, 65535πŸ–§ Network
positive-decimal-stringPositive 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-floatFloat strictly greater than 0.0.0.1, 1.5, 42.0πŸ”’ Numbers
positive-int-as-stringPositive 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-intPositive integer that is an exact power of two.1, 2, 4, 8, 1024πŸ”’ Numbers
private-ip-stringPrivate 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-stringPublic 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-stringValid semantic version string.1.0.0, 2.1.3-beta, 1.2.3+build5πŸ”€ Simple string format
sha1-stringExactly 40 lowercase hexadecimal characters.da39a3ee5e6b4b0d3255bfef95601890afd80709πŸ”€ Encoding
sha256-stringExactly 64 lowercase hexadecimal characters.e3b0c44298fc1c149afbf4c8996fb924...πŸ”€ Encoding
sha512-stringExactly 128 lowercase hexadecimal characters.cf83e1357eefb8bdf1542850d66d8007...πŸ”€ Encoding
shouted-snake-case-stringUppercase snake-case identifier.FOO, FOO_BAR, API_V2_KEYπŸ”€ Simple string format
slug-stringURL/path-friendly lowercase slug.hello-world, my-blog-post, abc123πŸ”— URI
snake-case-stringLowercase 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-maskValid 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-stringRFC 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-stringValid IANA timezone identifier.UTC, Europe/Copenhagen, America/New_YorkπŸ“… Date πŸ•’ Time
trimmed-non-empty-stringNon-empty string with no leading or trailing PHP trim() default whitespace.hello, abc123, foo barπŸ”€ Simple string format
ulid-stringValid ULID string as accepted by Symfony\Component\Uid\Ulid::isValid(...).01ARZ3NDEKTSV4RRFFQ69G5FAVπŸ†” Identification
upc-stringValid 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-stringSyntactically 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-stringAbsolute 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-stringRFC 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-stringValid UUID string as accepted by Ramsey\Uuid\Uuid::isValid(...).550e8400-e29b-41d4-a716-446655440000πŸ†” Identification
uuid1-stringValid UUID string with version 1 specifically.6ba7b810-9dad-11d1-80b4-00c04fd430c8πŸ†” Identification
uuid3-stringValid UUID string with version 3 specifically.6fa459ea-ee8a-3ca4-894e-db77e160355eπŸ†” Identification
uuid4-stringValid UUID string with version 4 specifically.550e8400-e29b-41d4-a716-446655440000πŸ†” Identification
uuid5-stringValid UUID string with version 5 specifically.21f7f8de-8051-5b89-8680-0195ef798b6aπŸ†” Identification
uuid6-stringValid UUID string with version 6 specifically.1ec9414c-232a-6b00-b3c8-9e6bdeced846πŸ†” Identification
uuid7-stringValid UUID string with version 7 specifically.01890f47-6c4c-7b3d-bc44-5b6d1e4f8c92πŸ†” Identification
uuid8-stringValid UUID string with version 8 specifically.2489e9ad-2ee2-8e00-8ec9-32d5f69181c0πŸ†” Identification
webhook-urlAbsolute 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-stringString 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-stringString 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

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.