1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/docs/issues.md

1889 lines
31 KiB
Markdown
Raw Normal View History

2017-12-12 06:49:40 +01:00
# Issue types
### AbstractInstantiation
Emitted when an attempt is made to instatiate an abstract class:
```php
abstract class A {}
new A();
```
### AssignmentToVoid
Emitted when assigning from a function that returns `void`:
```php
function foo() : void {}
$a = foo();
```
2018-01-01 02:32:47 +01:00
### CircularReference
Emitted when a class references itself as one of its parents
```php
class A extends B {}
class B extends A {}
```
### ConflictingReferenceConstraint
Emitted when a by-ref variable is set in two different branches of an if to different types.
```php
class A {
/** @var int */
private $foo;
public function __construct(int &$foo) {
$this->foo = &$foo;
}
}
class B {
/** @var string */
private $bar;
public function __construct(string &$bar) {
$this->bar = &$bar;
}
}
if (rand(0, 1)) {
$v = 5;
$c = (new A($v)); // $v is constrained to an int
} else {
$v = "hello";
$c = (new B($v)); // $v is constrained to a string
}
$v = 8;
```
2017-12-12 06:49:40 +01:00
### ContinueOutsideLoop
Emitted when encountering a `continue` statement outside a loop context.
```php
$a = 5;
continue;
```
2017-12-12 06:49:40 +01:00
### DeprecatedClass
Emitted when referring to a deprecated class:
2017-12-12 06:49:40 +01:00
```php
/** @deprecated */
class A {}
new A();
```
### DeprecatedInterface
Emitted when referring to a deprecated interface
```php
/** @deprecated */
interface I {}
class A implements I {}
```
2017-12-12 06:49:40 +01:00
### DeprecatedMethod
Emitted when calling a deprecated method on a given class:
```php
class A {
/** @deprecated */
public function foo() : void {}
}
(new A())->foo();
```
### DeprecatedProperty
Emitted when getting/setting a deprecated property of a given class
```php
class A {
/**
* @deprecated
* @var ?string
*/
public $foo;
}
(new A())->foo = 5;
```
### DocblockTypeContradiction
Emitted when conditional doesn't make sense given the docblock types supplied.
```php
/**
* @param string $s
*
* @return void
*/
function foo($s) {
if ($s === 5) { }
}
```
### DuplicateArrayKey
Emitted when an array has a key more than once
```php
$arr = [
'a' => 1,
'b' => 2,
'c' => 3,
'c' => 4,
];
```
2017-12-12 06:49:40 +01:00
### DuplicateClass
Emitted when a class is defined twice
```php
class A {}
class A {}
```
### DuplicateParam
Emitted when a function has a param defined twice
2017-12-12 06:49:40 +01:00
```php
function foo(int $b, string $b) {}
2017-12-12 06:49:40 +01:00
```
### EmptyArrayAccess
Emitted when attempting to access a value on an empty array
```php
$a = [];
$b = $a[0];
```
2018-01-07 23:17:18 +01:00
### FalsableReturnStatement
Emitted if a return statement contains a false value, but the function return type does not allow false
```php
function foo() : string {
if (rand(0, 1)) {
return "foo";
}
return false; // emitted here
}
```
### FalseOperand
Emitted when using `false` as part of an operation (e.g. `+`, `.`, `^` etc.`)
```php
echo false . 'hello';
```
2017-12-12 06:49:40 +01:00
### ForbiddenCode
Emitted when Psalm encounters a var_dump, exec or similar expression that may make your code more vulnerable
```php
var_dump($foo);
```
### ImplementedReturnTypeMismatch
Emitted when a class that inherits another, or implements an interface, has docblock return type that's entirely different to the parent. Subclasses of the parent return type are permitted, in docblocks.
```php
class A {
/** @return bool */
public function foo() {
return true;
}
}
class B extends A {
/** @return string */
public function foo() {
2018-01-01 02:42:06 +01:00
return "hello";
2017-12-12 06:49:40 +01:00
}
}
```
### ImplicitToStringCast
Emitted when implictly converting an object with a `__toString` method to a string
```php
class A {
public function __toString() {
return "foo";
}
}
function takesString(string $s) : void {}
takesString(new A);
```
### InaccessibleClassConstant
Emitted when a public/private class constant is not accessible from the calling context
```php
class A {
protected const FOO = 'FOO';
}
echo A::FOO;
```
### InaccessibleMethod
2017-12-12 07:16:51 +01:00
Emitted when attempting to access a protected/private method from outside its available scope
2017-12-12 06:49:40 +01:00
```php
2017-12-12 07:16:51 +01:00
class A {
protected function foo() : void {}
}
echo (new A)->foo();
2017-12-12 06:49:40 +01:00
```
### InterfaceInstantiation
Emitted when an attempt is made to instatiate an interface:
```php
interface I {}
new I();
```
2017-12-12 06:49:40 +01:00
### InaccessibleProperty
2017-12-12 07:16:51 +01:00
Emitted when attempting to access a protected/private property from outside its available scope
2017-12-12 06:49:40 +01:00
```php
2017-12-12 07:16:51 +01:00
class A {
/** @return string */
protected $foo;
}
echo (new A)->foo;
2017-12-12 06:49:40 +01:00
```
### InvalidArgument
2017-12-12 07:16:51 +01:00
Emitted when a supplied function/method argument is incompatible with the method signature or docblock one.
2017-12-12 06:49:40 +01:00
```php
2017-12-12 07:16:51 +01:00
class A {}
function foo(A $a) : void {}
foo("hello");
2017-12-12 06:49:40 +01:00
```
### InvalidArrayAccess
2017-12-12 07:16:51 +01:00
Emitted when attempting to access an array offset on a value that does not permit it
2017-12-12 06:49:40 +01:00
```php
2017-12-12 07:16:51 +01:00
$arr = 5;
echo $arr[0];
2017-12-12 06:49:40 +01:00
```
### InvalidArrayAssignment
2017-12-13 17:57:46 +01:00
Emitted when attempting to assign a value on a non-array
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$arr = 5;
$arr[0] = 3;
2017-12-12 06:49:40 +01:00
```
### InvalidArrayOffset
2017-12-13 17:57:46 +01:00
Emitted when when attempting to access an array using a value that's not a valid offet for that array
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$a = [5, 20, 18];
echo $a["hello"];
2017-12-12 06:49:40 +01:00
```
### InvalidCast
2017-12-13 17:57:46 +01:00
Emitted when attempting to cast a value that's not castable
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
class A {}
$a = new A();
$b = (string)$a;
2017-12-12 06:49:40 +01:00
```
2018-01-01 02:32:47 +01:00
### InvalidCatch
Emitted when trying to catch a class/interface that doesn't extend `Exception` or implement `Throwable`
```php
class A {}
try {
$worked = true;
}
catch (A $e) {}
```
2017-12-12 06:49:40 +01:00
### InvalidClass
2017-12-13 17:57:46 +01:00
Emitted when referencing a class with the wrong casing
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
class Foo {}
(new foo());
2017-12-12 06:49:40 +01:00
```
### InvalidStringClass
Emitted when you have `allowStringToStandInForClass="false"` in your config and youre passing a string instead of calling a class directly
```php
class Foo {}
$a = "Foo";
new $a();
```
2017-12-12 06:49:40 +01:00
### InvalidClone
2017-12-13 17:57:46 +01:00
Emitted when trying to clone a value that's not cloneable
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$a = "hello";
$b = clone $a;
2017-12-12 06:49:40 +01:00
```
### InvalidDocblock
2017-12-13 17:57:46 +01:00
Emitted when there's an error in a docblock type
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
/** @var array() */
$a = [];
2017-12-12 06:49:40 +01:00
```
2018-01-07 23:17:18 +01:00
### InvalidFalsableReturnType
Emitted when a function can return a nullable value, but its given return type says otherwise
```php
function foo() : string {
if (rand(0, 1)) {
return "foo";
}
return false;
}
```
2017-12-12 06:49:40 +01:00
### InvalidFunctionCall
2017-12-13 17:57:46 +01:00
Emitted when calling a function on a non-callable variable
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$a = 5;
$b = $a();
2017-12-12 06:49:40 +01:00
```
### InvalidGlobal
2017-12-22 17:56:21 +01:00
Emitted when there's a reference to the global keyword where it's not expected
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
global $e;
2017-12-12 06:49:40 +01:00
```
### InvalidIterator
2017-12-13 17:57:46 +01:00
Emitted when trying to iterate over a value that's not iterable
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$a = 5;
foreach ($a as $b) {}
2017-12-12 06:49:40 +01:00
```
### InvalidMethodCall
2017-12-13 17:57:46 +01:00
Emitted when attempting to call a method on a non-object
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$a = 5;
$a->foo();
2017-12-12 06:49:40 +01:00
```
2018-01-07 23:17:18 +01:00
### InvalidNullableReturnType
Emitted when a function can return a nullable value, but its given return type says otherwise
```php
function foo() : string {
if (rand(0, 1)) {
return "foo";
}
return null;
}
```
2017-12-12 06:49:40 +01:00
### InvalidOperand
2017-12-22 17:56:21 +01:00
Emitted when using something as an operand that is unexected
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {}
echo (new A) . ' ';
2017-12-12 06:49:40 +01:00
```
### InvalidParamDefault
2017-12-22 17:56:21 +01:00
Emitted when a function parameter default clashes with the type Psalm expects the param to be
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo(int $i = false) : void {}
2017-12-12 06:49:40 +01:00
```
### InvalidPassByReference
2017-12-22 17:56:21 +01:00
Emitted when passing a non-variable to a function that expects a by-ref variable
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo(array &$arr) : void {}
foo([0, 1, 2]);
2017-12-12 06:49:40 +01:00
```
### InvalidPropertyAssignment
2017-12-22 17:56:21 +01:00
Emitted when attempting to assign a property to a non-object
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
$a = "foo";
$a->bar = "bar";
2017-12-12 06:49:40 +01:00
```
### InvalidPropertyAssignmentValue
Emitted when attempting to assign a value to a property that cannot contain that type.
```php
class A {
/** @var string|null */
public $foo;
}
$a = new A();
$a->foo = new stdClass();
```
2017-12-12 06:49:40 +01:00
### InvalidPropertyFetch
2017-12-22 17:56:21 +01:00
Emitted when attempting to get a property from a non-object
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
$a = "foo";
echo $a->bar;
2017-12-12 06:49:40 +01:00
```
### InvalidReturnStatement
2017-12-22 17:56:21 +01:00
Emitted when a function return statement is incorrect
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo() : string {
return 5; // emitted here
}
2017-12-12 06:49:40 +01:00
```
### InvalidReturnType
2018-01-07 23:17:18 +01:00
Emitted when a functions signature return type is incorrect (often emitted with `InvalidReturnStatement`)
2017-12-12 06:49:40 +01:00
```php
2018-01-07 23:17:18 +01:00
function foo() : int {
2017-12-22 17:56:21 +01:00
if (rand(0, 1)) {
2018-01-07 23:17:18 +01:00
return "hello";
2017-12-22 17:56:21 +01:00
}
2018-01-07 23:17:18 +01:00
return 5;
2017-12-22 17:56:21 +01:00
}
2017-12-12 06:49:40 +01:00
```
### InvalidScalarArgument
2017-12-22 17:56:21 +01:00
Emitted when a scalar value is passed to a method that expected another scalar type
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo(int $i) : void {}
function bar(string $s) : void {
if (is_numeric($s)) {
foo($s);
}
}
2017-12-12 06:49:40 +01:00
```
### InvalidScope
2017-12-22 17:56:21 +01:00
Emitted when referring to `$this` outside a class
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
echo $this;
2017-12-12 06:49:40 +01:00
```
### InvalidStaticInvocation
2017-12-22 17:56:21 +01:00
Emitted when trying to call an instance function statically
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {
/** @var ?string */
public $foo;
2017-12-12 06:49:40 +01:00
2017-12-22 17:56:21 +01:00
public function bar() : void {
echo $this->foo;
}
}
2017-12-12 06:49:40 +01:00
2017-12-22 17:56:21 +01:00
A::bar();
2017-12-12 06:49:40 +01:00
```
2018-01-01 02:32:47 +01:00
### InvalidThrow
Emitted when trying to throw a class that doesn't extend `Exception` or implement `Throwable`
```php
class A {}
throw new A();
```
2017-12-12 06:49:40 +01:00
### InvalidToString
2017-12-22 17:56:21 +01:00
Emitted when a `__toString` method does not always return a `string`
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {
public function __toString() {
return true;
}
}
2017-12-12 06:49:40 +01:00
```
### LessSpecificReturnStatement
2017-12-22 17:56:21 +01:00
Emitted when a return statement is more general than the return type given for the function
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {}
class B extends A {}
2017-12-12 06:49:40 +01:00
2017-12-22 17:56:21 +01:00
function foo() : B {
return new A(); // emitted here
}
2017-12-12 06:49:40 +01:00
```
### LessSpecificReturnType
2017-12-22 17:56:21 +01:00
Emitted when a return type covers more possibilities than the function itself
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo() : ?int {
return 5;
}
```
### LoopInvalidation
2017-12-12 06:49:40 +01:00
2017-12-22 17:56:21 +01:00
Emitted when logic inside a loop invalidates one of the conditionals of the loop
```php
for ($i = 0; $i < 10; $i++) {
$i = 5;
}
2017-12-12 06:49:40 +01:00
```
### MethodSignatureMismatch
2017-12-22 17:56:21 +01:00
Emitted when a method parameter differs from a parent method parameter, or if there are fewer parameters than the parent method
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {
public function foo(int $i) : void {}
}
class B extends A {
public function foo(string $s) : void {}
}
2017-12-12 06:49:40 +01:00
```
2018-01-07 23:17:18 +01:00
### MismatchingDocblockParamType
Emitted when an `@param` entry in a functions docblock doesnt match the param typehint,
```php
class A {}
class B {}
/**
* @param B $b // emitted here
*/
function foo(A $b) : void {}
```
This, however, is fine:
```php
class A {}
class B extends A {}
/**
* @param B
*/
function foo(A $b) : void {}
```
### MismatchingDocblockReturnType
Emitted when an `@return` entry in a functions docblock doesnt match the function return typehint
```php
class A {}
class B {}
/**
* @return B // emitted here
*/
function foo() : A {
return new A();
}
```
This, however, is fine:
```php
class A {}
class B extends A {}
/**
* @return B // emitted here
*/
function foo() : A {
return new B();
}
```
### MismatchingDocblockParamType
Emitted when an `@param` entry in a functions docblock doesnt match the param typehint
```php
/**
* @param int $b
2018-01-07 23:17:18 +01:00
*/
function foo(string $b) : void {}
```
2017-12-12 06:49:40 +01:00
### MisplacedRequiredParam
2017-12-22 17:56:21 +01:00
Emitted when a required param is before a param that is not required. Included in Psalm because it is an E_WARNING in PHP
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo(int $i = 5, string $j) : void {}
2017-12-12 06:49:40 +01:00
```
### MissingClosureParamType
Emitted when a closure paramter has no type information associated with it
```php
$a = function($a): string {
return "foo";
};
```
2017-12-12 06:49:40 +01:00
### MissingClosureReturnType
2017-12-22 17:56:21 +01:00
Emitted when a closure lacks a return type
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
$a = function() {
return "foo";
};
2017-12-12 06:49:40 +01:00
```
### MissingConstructor
2017-12-22 17:56:21 +01:00
Emitted when non-null properties without default values are defined in a class without a `__construct` method
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {
/** @var string */
public $foo;
}
2017-12-12 06:49:40 +01:00
```
### MissingDependency
Emitted when referencing a class that doesnt exist
```php
/**
* @psalm-suppress UndefinedClass
*/
class A extends B {}
$a = new A();
```
2017-12-12 06:49:40 +01:00
### MissingDocblockType
2017-12-22 17:56:21 +01:00
Emitted when a docblock is present, but the type is missing or badly formatted
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
/** @var $a */
$a = [];
2017-12-12 06:49:40 +01:00
```
### MissingFile
2017-12-22 17:56:21 +01:00
Emitted when using `include` or `require` on a file that does not exist
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
require("nonexistent.php");
2017-12-12 06:49:40 +01:00
```
### MissingParamType
Emitted when a function paramter has no type information associated with it
```php
function foo($a) : void {}
```
2017-12-12 06:49:40 +01:00
### MissingPropertyType
2017-12-22 17:56:21 +01:00
Emitted when a property is defined on a class without a type
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {
public $foo;
}
2017-12-12 06:49:40 +01:00
```
### MissingReturnType
2017-12-22 17:56:21 +01:00
Emitted when a function doesn't have a return type defined
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo() {
return "foo";
}
2017-12-12 06:49:40 +01:00
```
### MixedArgument
2017-12-22 17:56:21 +01:00
Emitted when Psalm cannot determine the type of an argument
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function takesInt(int $i) : void {}
2017-12-24 01:11:08 +01:00
takesInt($_GET['foo']);
2017-12-12 06:49:40 +01:00
```
### MixedArrayAccess
2017-12-22 17:56:21 +01:00
Emitted when trying to access an array offset on a value whose type Psalm cannot determine
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
echo $_GET['foo'][0];
2017-12-12 06:49:40 +01:00
```
### MixedArrayAssignment
2017-12-22 17:56:21 +01:00
Emitted when trying to assign a value to an array offset on a value whose type Psalm cannot determine
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
$_GET['foo'][0] = "5";
2017-12-12 06:49:40 +01:00
```
### MixedArrayOffset
2017-12-22 17:56:21 +01:00
Emitted when attempting to access an array offset where Psalm cannot determine the offset type
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
echo [1, 2, 3][$_GET['foo']];
2017-12-12 06:49:40 +01:00
```
### MixedAssignment
2017-12-31 19:13:12 +01:00
Emitted when assigning a variable to a value for which Psalm cannot infer a type
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
$a = $_GET['foo'];
2017-12-12 06:49:40 +01:00
```
### MixedInferredReturnType
2017-12-24 01:11:08 +01:00
Emitted when Psalm cannot determine a function's return type
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
function foo() : int {
return $_GET['foo'];
}
2017-12-12 06:49:40 +01:00
```
### MixedMethodCall
2017-12-24 01:11:08 +01:00
Emitted when calling a method on a value that Psalm cannot infer a type for
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
/** @param mixed $a */
function foo($a) : void {
$a->foo();
}
2017-12-12 06:49:40 +01:00
```
### MixedOperand
2017-12-24 01:11:08 +01:00
Emitted when Psalm cannot infer a type for an operand in any calculated expression
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
echo $_GET['foo'] + "hello";
2017-12-12 06:49:40 +01:00
```
### MixedPropertyAssignment
2017-12-31 19:13:12 +01:00
Emitted when assigning a property to a value for which Psalm cannot infer a type
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
/** @param mixed $a */
function foo($a) : void {
$a->foo = "bar";
}
2017-12-12 06:49:40 +01:00
```
### MixedPropertyFetch
2017-12-31 19:13:12 +01:00
Emitted when retrieving a property on a value for which Psalm cannot infer a type
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
/** @param mixed $a */
function foo($a) : void {
echo $a->foo;
}
2017-12-12 06:49:40 +01:00
```
2018-01-07 23:17:18 +01:00
### MixedReturnStatement
Emitted when Psalm cannot determine the type of a given return statement
```php
function foo() : int {
return $_GET['foo']; // emitted here
}
```
2017-12-12 06:49:40 +01:00
### MixedStringOffsetAssignment
2017-12-24 01:11:08 +01:00
Emitted when assigning a value on a string using a value for which Psalm cannot infer a type
2017-12-12 06:49:40 +01:00
```php
"hello"[0] = $_GET['foo'];
2017-12-12 06:49:40 +01:00
```
### MixedTypeCoercion
2017-12-24 01:11:08 +01:00
Emitted when Psalm cannot be sure that part of an array/iterabble argument's type constraints can be fulfilled
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
function foo(array $a) : void {
takesStringArray($a);
}
2017-12-12 06:49:40 +01:00
2017-12-24 01:11:08 +01:00
/** @param string[] $a */
function takesStringArray(array $a) : void {}
2017-12-12 06:49:40 +01:00
```
### MoreSpecificImplementedParamType
Emitted when a class implements an interface method but a param type is less specific than the interface method param type
```php
class A {}
class B extends A {
public function bar(): void {}
}
class C extends A {
public function bar(): void {}
}
class D {
public function foo(A $a): void {}
}
class E extends D {
/** @param B|C $a */
public function foo(A $a): void {
$a->bar();
}
}
```
2017-12-12 06:49:40 +01:00
### MoreSpecificImplementedReturnType
2017-12-31 19:13:12 +01:00
Emitted when a class implements an interface method but its return type is less specific than the interface method return type
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
class A {}
class B extends A {}
interface I {
/** @return B[] */
public function foo();
}
class D implements I {
/** @return A[] */
public function foo() {
return [new A, new A];
}
}
2017-12-12 06:49:40 +01:00
```
### MoreSpecificReturnType
2017-12-31 19:13:12 +01:00
Emitted when the declared return type for a method is more specific than the inferred one (emitted in the same methods that `LessSpecificReturnStatement` is)
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
class A {}
class B extends A {}
function foo() : B {
/** @psalm-suppress LessSpecificReturnStatement */
return new A();
}
2017-12-12 06:49:40 +01:00
```
### NoInterfaceProperties
2017-12-31 19:13:12 +01:00
Emitted when trying to fetch a property on an interface as interfaces, by definition, do not have definitions for properties.
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
interface I {}
class A implements I {
/** @var ?string */
public $foo;
}
function bar(I $i) : void {
if ($i->foo) {}
}
2017-12-12 06:49:40 +01:00
```
### NonStaticSelfCall
Emitted when calling a non-static function statically
2017-12-12 06:49:40 +01:00
```php
class A {
public function foo(): void {}
2017-12-12 06:49:40 +01:00
public function bar(): void {
self::foo();
}
}
2017-12-12 06:49:40 +01:00
```
2018-01-07 23:17:18 +01:00
### NullableReturnStatement
Emitted if a return statement contains a null value, but the function return type is not nullable
```php
function foo() : string {
if (rand(0, 1)) {
return "foo";
}
return null; // emitted here
}
```
2017-12-12 06:49:40 +01:00
### NullArgument
2017-12-31 19:13:12 +01:00
Emitted when calling a function with a null value argument when the function does not expect it
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
function foo(string $s) : void {}
foo(null);
2017-12-12 06:49:40 +01:00
```
### NullArrayAccess
2017-12-31 19:13:12 +01:00
Emitted when trying to access an array value on `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$arr = null;
echo $arr[0];
2017-12-12 06:49:40 +01:00
```
### NullArrayOffset
2017-12-31 19:13:12 +01:00
Emitted when trying to access an array offset with `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$arr = ['' => 5, 'foo' => 1];
echo $arr[null];
2017-12-12 06:49:40 +01:00
```
### NullFunctionCall
2017-12-31 19:13:12 +01:00
Emitted when trying to use `null` as a `callable`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$arr = null;
echo $arr();
2017-12-12 06:49:40 +01:00
```
### NullIterator
2017-12-31 19:13:12 +01:00
Emitted when iterating over `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
foreach (null as $a) {}
2017-12-12 06:49:40 +01:00
```
### NullOperand
2017-12-31 19:13:12 +01:00
Emitted when using `null` as part of an operation (e.g. `+`, `.`, `^` etc.`)
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
echo null . 'hello';
2017-12-12 06:49:40 +01:00
```
### NullPropertyAssignment
2017-12-31 19:13:12 +01:00
Emitted when trying to set a property on `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$a = null;
$a->foo = "bar";
2017-12-12 06:49:40 +01:00
```
### NullPropertyFetch
2017-12-31 19:13:12 +01:00
Emitted when trying to fetch a property on a `null` value
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$a = null;
echo $a->foo;
2017-12-12 06:49:40 +01:00
```
### NullReference
2017-12-31 19:13:12 +01:00
Emitted when attempting to call a method on `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$a = null;
$a->foo();
2017-12-12 06:49:40 +01:00
```
### OverriddenMethodAccess
2017-12-31 19:13:12 +01:00
Emitted when a method is less accessible than its parent
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
class A {
public function foo() : void {}
}
class B extends A {
protected function foo() : void {}
}
2017-12-12 06:49:40 +01:00
```
### OverriddenPropertyAccess
Emitted when a property is less accessible than the same-named property in its parent class
```php
class A {
/** @var string|null */
public $foo;
}
class B extends A {
/** @var string|null */
protected $foo;
}
```
2017-12-12 06:49:40 +01:00
### ParadoxicalCondition
2017-12-31 19:13:12 +01:00
Emitted when a paradox is encountered in your programs logic that could not be caught by `RedundantCondition`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
function foo(?string $a) : ?string {
if ($a) return $a;
if ($a) echo "cannot happen";
}
2017-12-12 06:49:40 +01:00
```
### ParentNotFound
Emitted when using `parent::` in a class without a parent class.
2017-12-12 06:49:40 +01:00
```php
class A {
public function foo() : void {
parent::foo();
}
}
2017-12-12 06:49:40 +01:00
```
### PossiblyFalseArgument
Emitted when a function argument is possibly `false`, but the function doesnt expect `false`. This is distinct from a function argument is possibly `bool`, which results in `PossiblyInvalidArgument`.
2017-12-12 06:49:40 +01:00
```php
function foo(string $s) : void {
$a_pos = strpos($s, "a");
echo substr($s, $a_pos);
}
2017-12-12 06:49:40 +01:00
```
### PossiblyFalseOperand
Emitted when using a possibly `false` value as part of an operation (e.g. `+`, `.`, `^` etc.`)
```php
function foo(string $a) : void {
echo strpos($a, ":") + 5;
}
```
### PossiblyFalsePropertyAssignmentValue
Emitted when trying to assign a value that may be false to a property that only takes non-false values.
```php
class A {
/** @var int */
public $foo = 0;
}
function assignToA(string $s) {
$a = new A();
$a->foo = strpos("haystack", $s);
}
```
2017-12-12 06:49:40 +01:00
### PossiblyFalseReference
Emitted when making a method call on a value than might be `false`
2017-12-12 06:49:40 +01:00
```php
class A {
public function bar() : void {}
}
2017-12-12 06:49:40 +01:00
/** @return A|false */
function foo() {
return rand(0, 1) ? new A : false;
}
foo()->bar();
2017-12-12 06:49:40 +01:00
```
### PossiblyInvalidArgument
Emitted when
```php
/** @return int|stdClass */
function foo() {
return rand(0, 1) ? 5 : new stdClass;
}
function bar(int $i) : void {}
bar(foo());
2017-12-12 06:49:40 +01:00
```
### PossiblyInvalidArrayAccess
Emitted when attempting to access an array offset on a value that may not be an array
2017-12-12 06:49:40 +01:00
```php
$arr = rand(0, 1) ? 5 : [4, 3, 2, 1];
echo $arr[0];
2017-12-12 06:49:40 +01:00
```
### PossiblyInvalidArrayAssignment
Emitted when attempting to assign an array offset on a value that may not be an array
2017-12-12 06:49:40 +01:00
```php
$arr = rand(0, 1) ? 5 : [4, 3, 2, 1];
$arr[0] = "hello";
2017-12-12 06:49:40 +01:00
```
### PossiblyInvalidArrayOffset
Emitted when its possible that the array offset is not applicable to the value youre trying to access.
2017-12-12 06:49:40 +01:00
```php
$arr = rand(0, 1) ? ["a" => 5] : "hello";
echo $arr[0];
2017-12-12 06:49:40 +01:00
```
### PossiblyInvalidFunctionCall
Emitted when trying to call a function on a value that may not be callable
```php
$a = rand(0, 1) ? 5 : function() : int { return 5; };
$b = $a();
```
2017-12-12 06:49:40 +01:00
### PossiblyInvalidMethodCall
Emitted when trying to call a method on a value that may not be an object
2017-12-12 06:49:40 +01:00
```php
class A {
public function bar() : void {}
}
2017-12-12 06:49:40 +01:00
/** @return A|int */
function foo() {
return rand(0, 1) ? new A : 5;
}
foo()->bar();
2017-12-12 06:49:40 +01:00
```
### PossiblyInvalidOperand
Emitted when using a possibly invalid value as part of an operation (e.g. `+`, `.`, `^` etc.`)
```php
function foo() : void {
$b = rand(0, 1) ? [] : 4;
echo $b + 5;
}
```
2017-12-12 06:49:40 +01:00
### PossiblyInvalidPropertyAssignment
Emitted when trying to assign a property on a value that may not be an object or may be an object that doesnt have the desired property.
2017-12-12 06:49:40 +01:00
```php
class A {
/** @var ?string */
public $bar;
}
2017-12-12 06:49:40 +01:00
/** @return A|int */
function foo() {
return rand(0, 1) ? new A : 5;
}
$a = foo();
$a->bar = "5";
2017-12-12 06:49:40 +01:00
```
### PossiblyInvalidPropertyAssignmentValue
Emitted when trying to assign a possibly invalid value to a typed property.
```php
class A {
/** @var int[] */
public $bb = [];
}
class B {
/** @var string[] */
public $bb;
}
$c = rand(0, 1) ? new A : new B;
$c->bb = ["hello", "world"];
```
2017-12-12 06:49:40 +01:00
### PossiblyInvalidPropertyFetch
Emitted when trying to fetch a property on a value that may not be an object or may be an object that doesnt have the desired property.
2017-12-12 06:49:40 +01:00
```php
class A {
/** @var ?string */
public $bar;
}
/** @return A|int */
function foo() {
return rand(0, 1) ? new A : 5;
}
2017-12-12 06:49:40 +01:00
$a = foo();
echo $a->bar;
2017-12-12 06:49:40 +01:00
```
### PossiblyNullArgument
Emitted when calling a function with a value thats possibly null when the function does not expect it
2017-12-12 06:49:40 +01:00
```php
function foo(string $s) : void {}
foo(rand(0, 1) ? "hello" : null);
2017-12-12 06:49:40 +01:00
```
### PossiblyNullArrayAccess
Emitted when trying to access an array offset on a possibly null value
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:40:27 +01:00
function foo(?array $a) : void {
echo $a[0];
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullArrayAssignment
Emitted when trying to set a value on a possibly null array
2017-12-12 06:49:40 +01:00
```php
$a = null;
$a[0][] = 1;
2017-12-12 06:49:40 +01:00
```
### PossiblyNullArrayOffset
Emitted when trying to access a value on an array using a possibly null offset
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:40:27 +01:00
function foo(?int $a) : void {
echo [1, 2, 3, 4][$a];
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullFunctionCall
Emitted when trying to call a function on a value that may be null
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:40:27 +01:00
function foo(?callable $a) : void {
$a();
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullIterator
Emitted when trying to iterate over a value that may be null
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:40:27 +01:00
function foo(?array $arr) : void {
foreach ($arr as $a) {}
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullOperand
Emitted when using a possibly `null` value as part of an operation (e.g. `+`, `.`, `^` etc.`)
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:40:27 +01:00
function foo(?int $a) : void {
echo $a + 5;
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullPropertyAssignment
Emitted when trying to assign a property to a possibly null object
2017-12-12 06:49:40 +01:00
```php
class A {
/** @var ?string */
public $foo;
}
function foo(?A $a) : void {
$a->foo = "bar";
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullPropertyAssignmentValue
Emitted when trying to assign a value that may be null to a property that only takes non-null values.
```php
class A {
/** @var string */
public $foo = "bar";
}
function assignToA(?string $s) {
$a = new A();
$a->foo = $s;
}
```
2017-12-12 06:49:40 +01:00
### PossiblyNullPropertyFetch
Emitted when trying to fetch a property on a possibly null object
2017-12-12 06:49:40 +01:00
```php
class A {
/** @var ?string */
public $foo;
}
function foo(?A $a) : void {
echo $a->foo;
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullReference
Emitted when trying to call a method on a possibly null value
2017-12-12 06:49:40 +01:00
```php
class A {
public function bar() : void {}
}
function foo(?A $a) : void {
$a->bar();
}
2017-12-12 06:49:40 +01:00
```
### PossiblyUndefinedGlobalVariable
Emitted when trying to access a variable in the global scope that may not be defined
2017-12-12 06:49:40 +01:00
```php
if (rand(0, 1)) {
$a = 5;
}
echo $a;
2017-12-12 06:49:40 +01:00
```
### PossiblyUndefinedMethod
Emitted when trying to access a method that may not be defined on the object
2017-12-12 06:49:40 +01:00
```php
class A {
public function bar() : void {}
}
class B {}
2017-12-12 06:49:40 +01:00
$a = rand(0, 1) ? new A : new B;
$a->bar();
2017-12-12 06:49:40 +01:00
```
### PossiblyUndefinedVariable
Emitted when trying to access a variable in function scope that may not be defined
2017-12-12 06:49:40 +01:00
```php
function foo() : void {
if (rand(0, 1)) {
$a = 5;
}
echo $a;
}
2017-12-12 06:49:40 +01:00
```
### PossiblyUnusedMethod
Emitted when `--find-dead-code` is turned on and Psalm cannot find any calls to a given class method
2017-12-12 06:49:40 +01:00
```php
class A {
public function foo() : void {}
public function bar() : void {}
}
(new A)->foo();
2017-12-12 06:49:40 +01:00
```
2018-01-01 02:32:47 +01:00
### PossiblyUnusedParam
2017-12-12 06:49:40 +01:00
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a particular parameter in a public/protected method
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {
public function foo(int $a, int $b) : int {
return $a + 4;
}
}
$a = new A();
$a->foo(1, 2);
2017-12-12 06:49:40 +01:00
```
### PossiblyUnusedProperty
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a particular public/protected property
```php
class A {
/** @var string|null */
public $foo;
/** @var int|null */
public $bar;
}
$a = new A();
echo $a->foo;
```
2017-12-12 06:49:40 +01:00
### PropertyNotSetInConstructor
2017-12-31 23:32:35 +01:00
Emitted when a non-null property without a default value is declared but not set in the classs constructor
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
class A {
/** @var string */
public $foo;
2017-12-12 06:49:40 +01:00
2017-12-31 23:32:35 +01:00
public function __construct() {}
}
2017-12-12 06:49:40 +01:00
```
### RawObjectIteration
2017-12-31 23:32:35 +01:00
Emitted when iterating over an objects properties. This issue exists because it may be undesired behaviour (e.g. you may have meant to iterate over an array)
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
class A {
/** @var string|null */
2017-12-31 23:32:35 +01:00
public $foo;
/** @var string|null */
2017-12-31 23:32:35 +01:00
public $bar;
}
2017-12-12 06:49:40 +01:00
2017-12-31 23:32:35 +01:00
function takesA(A $a) {
foreach ($a as $property) {}
}
2017-12-12 06:49:40 +01:00
```
### RedundantCondition
2017-12-31 19:13:12 +01:00
Emitted when conditional is redundant given previous assertions
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
class A {}
function foo(?A $a) : ?A {
if ($a) return $a;
if ($a) echo "cannot happen";
}
2017-12-12 06:49:40 +01:00
```
### RedundantConditionGivenDocblockType
Emitted when conditional is redundant given information supplied in one or more docblocks.
This may be desired (e.g. when checking user input) so is distinct from RedundantCondition, which only applies to non-docblock types.
```php
/**
* @param string $s
*
* @return void
*/
function foo($s) {
if (is_string($s)) {};
}
```
2017-12-12 06:49:40 +01:00
### ReferenceConstraintViolation
2017-12-31 23:32:35 +01:00
Emitted when changing the type of a pass-by-reference variable
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
function foo(string &$a) {
$a = 5;
}
2017-12-12 06:49:40 +01:00
```
### ReservedWord
2017-12-31 23:32:35 +01:00
Emitted when using a reserved word as a class name
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
function foo(resource $res) : void {}
2017-12-12 06:49:40 +01:00
```
### TooFewArguments
2017-12-31 23:32:35 +01:00
Emitted when calling a function with fewer arguments than the function has parameters
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
function foo(string $a) : void {}
foo();
2017-12-12 06:49:40 +01:00
```
### TooManyArguments
2017-12-31 23:32:35 +01:00
Emitted when calling a function with more arguments than the function has parameters
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
function foo(string $a) : void {}
foo("hello", 4);
2017-12-12 06:49:40 +01:00
```
### TypeCoercion
2017-12-31 23:32:35 +01:00
Emitted when calling a function with an argument which has a less specific type than the function expects
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
class A {}
class B extends A {}
2017-12-12 06:49:40 +01:00
2017-12-31 23:32:35 +01:00
function takesA(A $a) : void {
takesB($a);
}
function takesB(B $b) : void {}
2017-12-12 06:49:40 +01:00
```
### TypeDoesNotContainNull
2017-12-31 23:32:35 +01:00
Emitted when checking a non-nullable type for `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
$a = "hello";
if ($a === null) {}
2017-12-12 06:49:40 +01:00
```
### TypeDoesNotContainType
2017-12-31 23:32:35 +01:00
Emitted checking whether one value has a type or value that is impossible given its currently-known type
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
$a = "hello";
if ($a === 5) {}
2017-12-12 06:49:40 +01:00
```
### UndefinedClass
2017-12-31 23:32:35 +01:00
Emitted when referencing a class that doesnt exist
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
$a = new A();
2017-12-12 06:49:40 +01:00
```
### UndefinedConstant
2017-12-31 23:32:35 +01:00
Emitted when referencing a constant that doesnt exist
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
echo FOO_BAR;
2017-12-12 06:49:40 +01:00
```
### UndefinedFunction
2017-12-31 23:32:35 +01:00
Emitted when referencing a function that doesn't exist
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
foo();
2017-12-12 06:49:40 +01:00
```
### UndefinedGlobalVariable
2017-12-31 23:32:35 +01:00
Emitted when referencing a variable that doesn't exist
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
echo $a;
2017-12-12 06:49:40 +01:00
```
### UndefinedMethod
2017-12-31 23:32:35 +01:00
Emitted when calling a method that doesnt exist
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
class A {}
A::foo();
2017-12-12 06:49:40 +01:00
```
### UndefinedPropertyAssignment
2018-01-01 02:32:47 +01:00
Emitted when assigning a property on an object that doesnt have that property defined
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {}
$a = new A();
$a->foo = "bar";
2017-12-12 06:49:40 +01:00
```
### UndefinedPropertyFetch
2018-01-01 02:32:47 +01:00
Emitted when getting a property on an object that doesnt have that property defined
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {}
$a = new A();
echo $a->foo;
2017-12-12 06:49:40 +01:00
```
### UndefinedThisPropertyAssignment
2018-01-01 02:32:47 +01:00
Emitted when assigning a property on an object in one of that objects methods when no such property exists
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {
function foo() {
$this->foo = "bar";
}
}
2017-12-12 06:49:40 +01:00
```
### UndefinedThisPropertyFetch
2018-01-01 02:32:47 +01:00
Emitted when getting a property for an object in one of that objects methods when no such property exists
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {
function foo() {
echo $this->foo;
}
}
2017-12-12 06:49:40 +01:00
```
### UndefinedTrait
2018-01-01 02:32:47 +01:00
Emitted when referencing a trait that doesnt exist
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {
use T;
}
2017-12-12 06:49:40 +01:00
```
### UndefinedVariable
2018-01-01 02:32:47 +01:00
Emitted when referencing a variable that doesn't exist in a given functions scope
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
function foo() {
echo $a;
}
2017-12-12 06:49:40 +01:00
```
### UnevaluatedCode
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm encounters code that will not be evaluated
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
function foo() : void {
return;
$a = "foo";
}
2017-12-12 06:49:40 +01:00
```
### UnimplementedAbstractMethod
2018-01-01 02:32:47 +01:00
Emitted when a class extends another, but does not implement all of its abstract methods
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
abstract class A {
abstract public function foo();
}
class B extends A {}
2017-12-12 06:49:40 +01:00
```
### UnimplementedInterfaceMethod
2018-01-01 02:32:47 +01:00
Emitted when a class `implements` an interface but does not implement all of its methods
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
interface I {
public function foo();
}
class A implements I {}
2017-12-12 06:49:40 +01:00
```
### UnrecognizedExpression
2018-01-01 02:32:47 +01:00
Emitted when Psalm encounters an expression that it doesn't know how to handle. This should never happen.
2017-12-12 06:49:40 +01:00
### UnrecognizedStatement
2018-01-01 02:32:47 +01:00
Emitted when Psalm encounters a code construct that it doesn't know how to handle. This should never happen.
2017-12-12 06:49:40 +01:00
### UnresolvableInclude
2018-01-01 02:32:47 +01:00
Emitted when Psalm cannot figure out what specific file is being included/required by PHP.
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
function requireFile(string $s) : void {
require_once($s);
}
2017-12-12 06:49:40 +01:00
```
### UnusedClass
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a given class
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {}
class B {}
$a = new A();
2017-12-12 06:49:40 +01:00
```
### UnusedMethod
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a given private method or function
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {
public function __construct() {
$this->foo();
}
private function foo() : void {}
private function bar() : void {}
}
$a = new A();
2018-01-01 02:32:47 +01:00
```
### UnusedParam
2017-12-12 06:49:40 +01:00
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a particular parameter in a private method or function
```php
function foo(int $a, int $b) : int {
return $a + 4;
}
2017-12-12 06:49:40 +01:00
```
### UnusedProperty
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a private property
```php
class A {
/** @var string|null */
private $foo;
/** @var int|null */
private $bar;
public function getFoo(): ?string {
return $this->foo;
}
}
$a = new A();
echo $a->getFoo();
```
2017-12-12 06:49:40 +01:00
### UnusedVariable
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any references to a variable, once instantiated
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
function foo() : void {
$a = 5;
$b = 4;
echo $b;
}
2017-12-12 06:49:40 +01:00
```