Skip to content

Constants

Choose a tag to compare

@spaze spaze released this 05 Dec 03:06
6f83bad

Can now disallow constant usages, both class constants (e.g. \DateTime::FOO) and regular constants (DATE_FOO) (#41)

Because sometimes you want to avoid formatting dates with \DateTimeInterface::ISO8601 because "This format is not compatible with ISO-8601", or avoid filtering IP addresses with filter flags like FILTER_FLAG_NO_PRIV_RANGE because it doesn't recognize "IPv4-in-IPv6" addresses (called IPv4-mapped addresses) like ::ffff:192.0.2.33.

This is how you configure it in yourphpstan.neon:

    disallowedConstants:
        -
            constant: 'DATE_ISO8601'
            message: 'use DATE_ATOM instead'
        -
            constant: 'DateTimeInterface::ISO8601'
            message: 'use DateTimeInterface::ATOM instead'