mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Update docs once more
This commit is contained in:
parent
d22fe29a60
commit
3f2615290d
@ -11,3 +11,7 @@ abstract class Base {
|
||||
|
||||
Base::bar();
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
It's not allowed by PHP.
|
||||
|
@ -9,9 +9,13 @@ function foo() : void {}
|
||||
$a = foo();
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
Though `void`-returning functions are treated by PHP as returning `null` (so this on its own doesn’t lead to runtime errors), `void` is a concept more broadly in programming languages which is not designed for assignment purposes.
|
||||
|
||||
## How to fix
|
||||
|
||||
You should just be able to remove the assignment:
|
||||
You should just be able to remove the assignment entirely:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
@ -8,3 +8,7 @@ Emitted when a class references itself as one of its parents
|
||||
class A extends B {}
|
||||
class B extends A {}
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
The code above will not compile
|
||||
|
@ -33,3 +33,7 @@ if (rand(0, 1)) {
|
||||
|
||||
$v = 8;
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
Psalm doesn't understand what the type of `$c` should be
|
||||
|
@ -8,3 +8,7 @@ Emitted when encountering a `continue` statement outside a loop context.
|
||||
$a = 5;
|
||||
continue;
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
The code won't compile in PHP 5.6 and above.
|
||||
|
@ -10,6 +10,10 @@ class A {}
|
||||
new A();
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
The `@deprecated` tag is normally indicative of code that will stop working in the near future.
|
||||
|
||||
## How to fix
|
||||
|
||||
Don’t use the deprecated class.
|
||||
|
@ -13,6 +13,10 @@ class A {
|
||||
echo A::FOO;
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
The `@deprecated` tag is normally indicative of code that will stop working in the near future.
|
||||
|
||||
## How to fix
|
||||
|
||||
Don’t use the deprecated constant.
|
||||
|
@ -10,6 +10,10 @@ function foo() : void {}
|
||||
foo();
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
The `@deprecated` tag is normally indicative of code that will stop working in the near future.
|
||||
|
||||
## How to fix
|
||||
|
||||
Don’t use the deprecated function.
|
||||
|
@ -11,6 +11,10 @@ interface I {}
|
||||
class A implements I {}
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
The `@deprecated` tag is normally indicative of code that will stop working in the near future.
|
||||
|
||||
## How to fix
|
||||
|
||||
Don’t use the deprecated interface.
|
||||
|
@ -12,6 +12,10 @@ class A {
|
||||
(new A())->foo();
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
The `@deprecated` tag is normally indicative of code that will stop working in the near future.
|
||||
|
||||
## How to fix
|
||||
|
||||
Don’t use the deprecated method.
|
||||
|
@ -15,6 +15,10 @@ class A {
|
||||
(new A())->foo = 5;
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
The `@deprecated` tag is normally indicative of code that will stop working in the near future.
|
||||
|
||||
## How to fix
|
||||
|
||||
Don’t use the deprecated property.
|
||||
|
@ -12,6 +12,10 @@ class A {
|
||||
}
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
The `@deprecated` tag is normally indicative of code that will stop working in the near future.
|
||||
|
||||
## How to fix
|
||||
|
||||
Don’t use the deprecated trait.
|
||||
|
@ -19,6 +19,10 @@ function foo($s) {
|
||||
}
|
||||
```
|
||||
|
||||
## Why this is bad
|
||||
|
||||
This can sometimes point to a flaw in either your docblock types, or some unnecessary runtime checks in an environment where all types can be checked by Psalm, without the need for additional runtime checks.
|
||||
|
||||
## How to fix
|
||||
|
||||
A lot of old PHP code is set up to prevent unexpected errors with checks like the one above.
|
||||
|
@ -6,7 +6,7 @@ Emitted when using a possibly `false` value as part of an operation (e.g. `+`, `
|
||||
<?php
|
||||
|
||||
function echoCommaPosition(string $str) : void {
|
||||
echo 'The comma is located at ' . false;
|
||||
echo 'The comma is located at ' . strpos($str, ',');
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user