Psalm uses an XML config file. A recommended default Psalm config is located [here](examples/psalm.default.xml).
### Options
-`stopOnFirstError`<br/>
whether or not to stop when the first error is encountered
-`useDocblockTypes`<br/>
whether or not to use types as defined in docblocks
-`autoloader` (optional)
if you script that registers a custom autoloader and/or universal constants/functions, register them here
### Parameters
-`<inspectFiles>`<br/>
Contains a list of all the directories that Psalm should inspect
-`<fileExtensions>` (optional)<br/>
A list of extensions to search over. See [Checking non-PHP files](#checking-non-php-files) to understand how to extend this.
-`<plugins>` (optional)<br/>
A list of `<plugin filename="path_to_plugin.php" />` entries. See the [Plugins](#plugins) section for more information.
-`<issueHandler>` (optional)<br/>
If you don't want Psalm to complain about every single issue it finds, the issueHandler tag allows you to configure that. [Dealing with code issues](#dealing-with-code-issues) tells you more.
-`<includeHandler>` (optional)<br/>
If there are files that your scripts include that you don't want Psalm to traverse, include them here with `<file name="path_to_file.php" />`.
-`<mockClasses>` (optional)<br/>
Do you use mock classes in your tests? If you want Psalm to ignore them when checking files, include a fully-qualified path to the class with `<class name="Your\Namespace\ClassName" />`
You can use the `/** @var Type */` docblock to annotate both [property declarations](http://php.net/manual/en/language.oop5.properties.php) and to help Psalm understand variable assignment.
When checking `$this->foo = $some_variable;`, Psalm will check to see whether `$some_variable` is either `string` or `null` and, if neither, emit an issue.
Because Psalm scans a file progressively, it cannot tell that `return $a` produces an integer. Instead it returns knows only that `$a` is not `empty`. We can fix this by adding a type hint docblock:
```php
/** @var int|null */
$a = null;
foreach ([1, 2, 3] as $i) {
if ($a) {
return $a;
}
else {
$a = $i;
}
}
```
This tells Psalm that `int` is a possible type for `$a`, and allows it to infer that `return $a;` produces an integer.
Unlike property types, however, assignment typehints are not binding – they can be overridden by a new assignment without Psalm emitting an issue e.g.
PHPDoc [allows you to specify](https://phpdoc.org/docs/latest/references/phpdoc/types.html#arrays) the type of values the array holds with the annotation:
where `TValue` is a union type, but it does not allow you to specify the type of keys.
Psalm uses a syntax [borrowed from Java](https://en.wikipedia.org/wiki/Generics_in_Java) to denote the types of both keys *and* values:
```php
/** @return array<TKey,TValue> */
```
#### Makeshift Structs
Ideally (in the author's opinion), all data would either be encoded as lists, associative arrays, or as well-defined objects. However, PHP arrays are often used as makeshift structs.
Hack (by Facebook) supports this usage by way of the [Shape datastructure](https://docs.hhvm.com/hack/shapes/introduction), but there is no agreed-upon documentation format for such arrays in regular PHP-land.
Psalm solves this by adding another way annotate array types, by using an object-like syntax when describing them.
is assigned the type `array{ name: string, type: string}`.
#### Backwards compatibility
Psalm fully supports PHPDoc's array typing syntax, such that any array typed with `TValue[]` will be typed in Psalm as `array<mixed, TValue>`. That also extends to generic type definitions with only one param e.g. `array<TValue>`, which is equivalent to `array<mixed, TValue>`.
Psalm supports the ability to check various PHPish files by extending the `FileChecker` class. For example, if you have a template where the variables are set elsewhere, Psalm can scrape those variables and check the template with those variables pre-populated.
An example TemplateChecker is provided [here](examples/TemplateChecker.php).
To ensure your custom `FileChecker` is used, you must update the Psalm `fileExtensions` config in psalm.xml: