Skip to content

Developing a library and expecting uncontrollable users #2431

@szepeviktor

Description

@szepeviktor

Let's say I expose a method of my library to general usage, and I'd like to check proper usage.

    /**
     * @param int|string $value
     *
     * @return static
     */
    public static function make($value): Enumerable
    {
        if (! is_int($value) && ! is_string($value)) {
            throw new TypeError(static::class.'::make() expects string|int as argument but '.gettype($value).' given');
        }

PHPStan will tell me Result of && is always false.

What do you suggest?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions