---
title: "lint/types"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

Type declarations, type checks and inferred types. Also in [format](/docs/rules/format/types) (6) and [analyse](/docs/rules/analyse/types) (118).

**[add-array-return-type](/docs/rules/lint/types/add-array-return-type)**

Add return type from return direct array

In the `types` set. Unsafe fix: it can change behaviour.

**[add-arrow-function-return-type](/docs/rules/lint/types/add-arrow-function-return-type)**

Add known return type to arrow function

In the `types` set. Unsafe fix: it can change behaviour.

**[add-bool-return-type](/docs/rules/lint/types/add-bool-return-type)**

Add bool return type based on strict bool returns type operations

In the `types` set. Unsafe fix: it can change behaviour.

**[add-bool-return-type-from-const](/docs/rules/lint/types/add-bool-return-type-from-const)**

Add return bool, based on direct true/false returns

In the `types` set. Unsafe fix: it can change behaviour.

**[add-bool-return-type-from-mixed-returns](/docs/rules/lint/types/add-bool-return-type-from-mixed-returns)**

Add bool return type when returns mix direct true/false consts with strict bool expressions

In the `types` set. Unsafe fix: it can change behaviour. **Planned: not in Pun yet.** Enabling it is a config error.

**[add-closure-never-return](/docs/rules/lint/types/add-closure-never-return)**

Add "never" return-type for closure that never return anything

In the `types` set. Unsafe fix: it can change behaviour.

**[add-closure-return-type](/docs/rules/lint/types/add-closure-return-type)**

Add return type to closures based on known return values

In the `types` set. Unsafe fix: it can change behaviour.

**[add-closure-void-return](/docs/rules/lint/types/add-closure-void-return)**

Add closure return type void if there is no return

In the `types` set. Unsafe fix: it can change behaviour.

**[add-datetime-property-type](/docs/rules/lint/types/add-datetime-property-type)**

Set DateTime to DateTimeInterface for DateTime property with DateTimeInterface docblock

In the `types` set. Unsafe fix: it can change behaviour.

**[add-fluent-return-type](/docs/rules/lint/types/add-fluent-return-type)**

Add return type from strict return $this

In the `types` set. Unsafe fix: it can change behaviour.

**[add-function-void-return](/docs/rules/lint/types/add-function-void-return)**

Add function return type void if there is no return

In the `types` set. Unsafe fix: it can change behaviour.

**[add-getter-return-phpdoc](/docs/rules/lint/types/add-getter-return-phpdoc)**

Add @return array docblock to a getter method based on @var of the property

In the `types` set. Unsafe fix: it can change behaviour.

**[add-magic-method-return-type](/docs/rules/lint/types/add-magic-method-return-type)**

Add known magic methods parameter and return type declarations

In the `types` set. Unsafe fix: it can change behaviour.

**[add-method-void-return](/docs/rules/lint/types/add-method-void-return)**

Add return type void to function like without any return

In the `types` set. Unsafe fix: it can change behaviour.

**[add-never-return-type](/docs/rules/lint/types/add-never-return-type)**

Add a `never` return type to functions, methods and closures that never return.

In the `types` set. Unsafe fix: it can change behaviour.

**[add-nullable-return-type](/docs/rules/lint/types/add-nullable-return-type)**

Add basic ? nullable type to class methods and functions, as of PHP 7.1

In the `types` set. Unsafe fix: it can change behaviour.

**[add-numeric-return-type](/docs/rules/lint/types/add-numeric-return-type)**

Add int/float return type based on strict typed returns

In the `types` set. Unsafe fix: it can change behaviour.

**[add-numeric-return-type-from-scalar](/docs/rules/lint/types/add-numeric-return-type-from-scalar)**

Add int/float return type based on strict scalar returns type

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-phpdoc-from-callable-call](/docs/rules/lint/types/add-param-phpdoc-from-callable-call)**

Add param array docblock based on callable native function call

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-phpdoc-from-dim-fetch](/docs/rules/lint/types/add-param-phpdoc-from-dim-fetch)**

Add @param docblock array type, based on array dim fetch access

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-phpdoc-from-local-calls](/docs/rules/lint/types/add-param-phpdoc-from-local-calls)**

Add @param array docblock to a class method based on local call types

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-phpdoc-from-reference-assign](/docs/rules/lint/types/add-param-phpdoc-from-reference-assign)**

Add @param docblock array type, based on type to assigned parameter reference

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-array-any-all](/docs/rules/lint/types/add-param-type-array-any-all)**

Add a type to an untyped array_any()/array_all() closure param, based on the array item type

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-array-dim-fetch](/docs/rules/lint/types/add-param-type-array-dim-fetch)**

Add array type based on array dim fetch use

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-array-function](/docs/rules/lint/types/add-param-type-array-function)**

Add array_filter()/array_map() function closure param type, based on passed iterable

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-array-map](/docs/rules/lint/types/add-param-type-array-map)**

Applies type hints to array_map closures

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-array-reduce](/docs/rules/lint/types/add-param-type-array-reduce)**

Applies type hints to array_reduce closures

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-arrow-dim-fetch](/docs/rules/lint/types/add-param-type-arrow-dim-fetch)**

Add closure and arrow function param array type, if dim fetch is used inside

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-data-provider](/docs/rules/lint/types/add-param-type-data-provider)**

Adds param type declaration based on PHPUnit provider return type declaration

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-dim-fetch-key](/docs/rules/lint/types/add-param-type-dim-fetch-key)**

Add method param type based on use in array dim fetch of known keys

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-iterable-method-call](/docs/rules/lint/types/add-param-type-iterable-method-call)**

Applies type hints to closures on Iterable method calls where key/value types are documented

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-method-call](/docs/rules/lint/types/add-param-type-method-call)**

Change private method param type to strict type, based on passed strict types

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-property](/docs/rules/lint/types/add-param-type-property)**

Add param type declaration based on property type

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-spl-fixed-array](/docs/rules/lint/types/add-param-type-spl-fixed-array)**

Add exact fixed array type in known cases

In the `types` set. Unsafe fix: it can change behaviour.

**[add-param-type-variable-call](/docs/rules/lint/types/add-param-type-variable-call)**

Add closure param object type based on the argument the assigned closure variable is called with

In the `types` set. Unsafe fix: it can change behaviour.

**[add-private-method-array-return-type](/docs/rules/lint/types/add-private-method-array-return-type)**

Add strict return array type to private methods based on created empty array and returned

In the `types` set. Unsafe fix: it can change behaviour.

**[add-property-type-assigns](/docs/rules/lint/types/add-property-type-assigns)**

Add typed property from assigned types

In the `types` set. Unsafe fix: it can change behaviour.

**[add-property-type-constructor](/docs/rules/lint/types/add-property-type-constructor)**

Add typed properties based only on strict constructor types

In the `types` set. Unsafe fix: it can change behaviour.

**[add-property-type-get-repository](/docs/rules/lint/types/add-property-type-get-repository)**

Add strict typed property to a private test case property based on its @var object type, when assigned via entity manager getRepository() fetch in setUp()

In the `types` set. Unsafe fix: it can change behaviour.

**[add-property-type-setter-getter](/docs/rules/lint/types/add-property-type-setter-getter)**

Add property type based on strict setter and getter method

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-phpdoc-common-object](/docs/rules/lint/types/add-return-phpdoc-common-object)**

Add @return docblock array of objects, that have common denominator interface/parent class

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-phpdoc-dim-assigned-object](/docs/rules/lint/types/add-return-phpdoc-dim-assigned-object)**

Add @return docblock array of objects, that are dim assigned to returned variable

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-phpdoc-direct-array](/docs/rules/lint/types/add-return-phpdoc-direct-array)**

Add simple @return array docblock based on direct single level direct return of []

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-phpdoc-json-array](/docs/rules/lint/types/add-return-phpdoc-json-array)**

Add @return docblock for array based on return of json_decode() return array

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-phpdoc-scalar-array](/docs/rules/lint/types/add-return-phpdoc-scalar-array)**

Add @return docblock for scalar array from strict array assignments

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-cast](/docs/rules/lint/types/add-return-type-from-cast)**

Add return type to function like with return cast

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-constant](/docs/rules/lint/types/add-return-type-from-constant)**

Add strict type declaration based on returned constants

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-get-repository](/docs/rules/lint/types/add-return-type-from-get-repository)**

Add repository return type declaration based on @return docblock, when a method returns entity manager getRepository() fetch

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-native-call](/docs/rules/lint/types/add-return-type-from-native-call)**

Add strict return type based native function or native method

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-new](/docs/rules/lint/types/add-return-type-from-new)**

Add return type to function like with return new

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-new-array](/docs/rules/lint/types/add-return-type-from-new-array)**

Add strict return array type based on created empty array and returned

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-param](/docs/rules/lint/types/add-return-type-from-param)**

Add return type based on strict parameter type

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-parent](/docs/rules/lint/types/add-return-type-from-parent)**

Add missing return type declaration based on parent class method

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-property](/docs/rules/lint/types/add-return-type-from-property)**

Add return method return type based on strict typed property

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-ternary](/docs/rules/lint/types/add-return-type-from-ternary)**

Add method return type based on strict ternary values

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-try-catch](/docs/rules/lint/types/add-return-type-from-try-catch)**

Add known type declarations based on first-level try/catch return values

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-typed-call](/docs/rules/lint/types/add-return-type-from-typed-call)**

Add return type from strict return type of call

In the `types` set. Unsafe fix: it can change behaviour.

**[add-return-type-from-yield](/docs/rules/lint/types/add-return-type-from-yield)**

Add return type declarations from yields

In the `types` set. Unsafe fix: it can change behaviour.

**[add-string-return-type](/docs/rules/lint/types/add-string-return-type)**

Add string return type based on returned strict string values

In the `types` set. Unsafe fix: it can change behaviour.

**[add-string-return-type-from-scalar](/docs/rules/lint/types/add-string-return-type-from-scalar)**

Add string return type based on returned string scalar values

In the `types` set. Unsafe fix: it can change behaviour.

**[add-union-return-type](/docs/rules/lint/types/add-union-return-type)**

Add union return type

In the `types` set. Unsafe fix: it can change behaviour.

**[add-var-phpdoc-from-constructor-param](/docs/rules/lint/types/add-var-phpdoc-from-constructor-param)**

Add @var array docblock to a property based on @param of constructor assign

In the `types` set. Unsafe fix: it can change behaviour.

**[add-var-phpdoc-from-default](/docs/rules/lint/types/add-var-phpdoc-from-default)**

Add @var array docblock to array property based on iterable default value

In the `types` set. Unsafe fix: it can change behaviour.

**[add-var-phpdoc-from-dim-fetch](/docs/rules/lint/types/add-var-phpdoc-from-dim-fetch)**

Add @var array property docblock from dim fetches on property fetch assignment

In the `types` set. Unsafe fix: it can change behaviour.

**[add-var-phpdoc-from-getter](/docs/rules/lint/types/add-var-phpdoc-from-getter)**

Add @var array property docblock from its getter @return

In the `types` set. Unsafe fix: it can change behaviour.

**[add-void-return-type](/docs/rules/lint/types/add-void-return-type)**

Add a `void` return type to functions, methods, closures and tests that never return a value.

In the `types` set. Unsafe fix: it can change behaviour.

**[no-loose-comparison](/docs/rules/lint/types/no-loose-comparison)**

Comparisons should be strict.

In the `code-quality` set. Safe fix where types prove it, unsafe otherwise. Intent: suspicious.

**[no-nullsafe-on-non-null](/docs/rules/lint/types/no-nullsafe-on-non-null)**

Cleanup unneeded nullsafe operator

In the `code-quality` set. Safe fix.

**[no-phpstan-phpdoc-tag](/docs/rules/lint/types/no-phpstan-phpdoc-tag)**

Merge more precise @phpstan-var/@phpstan-param/@phpstan-return docblock tag into its native @var/@param/@return tag

In the `types` set. Unsafe fix: it can change behaviour. **Planned: not in Pun yet.** Enabling it is a config error.

**[prefer-explicit-null-instanceof](/docs/rules/lint/types/prefer-explicit-null-instanceof)**

Make implicit nullable object checks explicit with instanceof

In the `code-quality` set. Unsafe fix: it can change behaviour.

**[prefer-generic-collection-phpdoc](/docs/rules/lint/types/prefer-generic-collection-phpdoc)**

Change @return "Type[]&#124;ArrayCollection" union docblock to a generic "ArrayCollection&lt;int, Type>"

In the `types` set. Unsafe fix: it can change behaviour.

**[prefer-identical-same-type](/docs/rules/lint/types/prefer-identical-same-type)**

Use ===/!== over ==/!=, if values have the same type

In the `code-quality` set. Safe fix where types prove it, unsafe otherwise. Intent: suspicious.

**[prefer-instanceof](/docs/rules/lint/types/prefer-instanceof)**

Use instanceof instead of is_a(), null checks or truthiness checks on nullable objects.

In the `code-quality` set. Unsafe fix: it can change behaviour.

**[prefer-literal-bool-phpdoc](/docs/rules/lint/types/prefer-literal-bool-phpdoc)**

Narrow @return docblock "bool" to "false" or "true" when the native return type only allows one of them

In the `types` set. Unsafe fix: it can change behaviour. **Planned: not in Pun yet.** Enabling it is a config error.

**[prefer-narrow-param-type](/docs/rules/lint/types/prefer-narrow-param-type)**

Narrow an already nullable array_any()/array_all()/array_find()/array_find_key() closure param to the non-nullable array item type

In the `types` set. Unsafe fix: it can change behaviour.

**[prefer-specific-return-type](/docs/rules/lint/types/prefer-specific-return-type)**

Narrows return type from generic `object` or parent class to specific class in final classes/methods

In the `types` set. Unsafe fix: it can change behaviour.

**[require-strict-param](/docs/rules/lint/types/require-strict-param)**

Functions should be used with `$strict` param set to `true`.

In the `coding-style` set. Safe fix where types prove it, unsafe otherwise. Intent: suspicious.
