Skip to content

Commit

Permalink
Add opening PHP tags to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 20, 2020
1 parent dd0898c commit 84bfba0
Show file tree
Hide file tree
Showing 216 changed files with 472 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/AbstractInstantiation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when an attempt is made to instantiate an abstract class:

```php
<?php

abstract class A {}
new A();
```
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/AbstractMethodCall.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when an attempt is made to call an abstract static method directly

```php
<?php

abstract class Base {
abstract static function bar() : void;
}
Expand Down
6 changes: 6 additions & 0 deletions docs/running_psalm/issues/ArgumentTypeCoercion.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when calling a function with an argument which has a less specific type than the function expects

```php
<?php

class A {}
class B extends A {}

Expand All @@ -17,6 +19,8 @@ function takesB(B $b) : void {}
You could add a typecheck before the call to `takesB`:

```php
<?php

function takesA(A $a) : void {
if ($a instanceof B) {
takesB($a);
Expand All @@ -27,6 +31,8 @@ function takesA(A $a) : void {
Or, if you have control over the function signature of `takesA` you can change it to expect `B`:

```php
<?php

function takesA(B $a) : void {
takesB($a);
}
Expand Down
4 changes: 4 additions & 0 deletions docs/running_psalm/issues/AssignmentToVoid.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when assigning from a function that returns `void`:

```php
<?php

function foo() : void {}
$a = foo();
```
Expand All @@ -12,6 +14,8 @@ $a = foo();
You should just be able to remove the assignment:

```php
<?php

function foo() : void {}
foo();
```
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/CircularReference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when a class references itself as one of its parents

```php
<?php

class A extends B {}
class B extends A {}
```
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ConflictingReferenceConstraint.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when a by-ref variable is set in two different branches of an if to different types.

```php
<?php

class A {
/** @var int */
private $foo;
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ContinueOutsideLoop.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when encountering a `continue` statement outside a loop context.

```php
<?php

$a = 5;
continue;
```
6 changes: 6 additions & 0 deletions docs/running_psalm/issues/DeprecatedClass.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
Emitted when referring to a deprecated class:

```php
<?php

/** @deprecated */
class A {}
new A();
```

## How to fix

Don’t use the deprecated class.
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/DeprecatedConstant.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when referring to a deprecated constant:

```php
<?php

class A {
/** @deprecated */
const FOO = 'foo';
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/DeprecatedFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when calling a deprecated function:

```php
<?php

/** @deprecated */
function foo() : void {}
foo();
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/DeprecatedInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when referring to a deprecated interface

```php
<?php

/** @deprecated */
interface I {}

Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/DeprecatedMethod.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when calling a deprecated method on a given class:

```php
<?php

class A {
/** @deprecated */
public function foo() : void {}
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/DeprecatedProperty.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when getting/setting a deprecated property of a given class

```php
<?php

class A {
/**
* @deprecated
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/DeprecatedTrait.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when referring to a deprecated trait:

```php
<?php

/** @deprecated */
trait T {}
class A {
Expand Down
4 changes: 4 additions & 0 deletions docs/running_psalm/issues/DocblockTypeContradiction.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when conditional doesn't make sense given the docblock types supplied.

```php
<?php

/**
* @param string $s
*
Expand All @@ -24,6 +26,8 @@ A lot of old PHP code is set up to prevent unexpected errors with checks like th
As you migrate your code to newer versions of PHP you can also use stricter type-hints:

```php
<?php

function foo(string $s) : void {
echo $s;
}
Expand Down
18 changes: 18 additions & 0 deletions docs/running_psalm/issues/DuplicateArrayKey.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,28 @@
Emitted when an array has a key more than once

```php
<?php

$arr = [
'a' => 1,
'b' => 2,
'c' => 3,
'c' => 4,
];
```

## How to fix

Remove the offending duplicates:

```php
<?php

$arr = [
'a' => 1,
'b' => 2,
'c' => 4,
];
```

The first matching `'c'` key was removed to prevent a change in behaviour (any new duplicate keys overwrite the values of prevvious ones).
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/DuplicateClass.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when a class is defined twice

```php
<?php

class A {}
class A {}
```
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/DuplicateFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when a function is defined twice

```php
<?php

function foo() : void {}
function bar() : void {}
function foo() : void {}
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/DuplicateMethod.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when a method is defined twice

```php
<?php

class A {
public function foo() {}
public function foo() {}
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/DuplicateParam.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
Emitted when a function has a param defined twice

```php
<?php

function foo(int $b, string $b) {}
```
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/EmptyArrayAccess.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when attempting to access a value on an empty array

```php
<?php

$a = [];
$b = $a[0];
```
6 changes: 6 additions & 0 deletions docs/running_psalm/issues/FalsableReturnStatement.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted if a return statement contains a false value, but the function return type does not allow false

```php
<?php

function getCommaPosition(string $a) : int {
return strpos($a, ',');
}
Expand All @@ -13,6 +15,8 @@ function getCommaPosition(string $a) : int {
You can add a specific check for false:

```php
<?php

function getCommaPosition(string $a) : int {
$pos = return strpos($a, ',');

Expand All @@ -27,6 +31,8 @@ function getCommaPosition(string $a) : int {
Alternatively you may chose to throw an exception:

```php
<?php

function getCommaPosition(string $a) : int {
$pos = return strpos($a, ',');

Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/FalseOperand.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
Emitted when using `false` as part of an operation (e.g. `+`, `.`, `^` etc.)

```php
<?php

echo false . 'hello';
```
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ForbiddenCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
Emitted when Psalm encounters a var_dump, exec or similar expression that may make your code more vulnerable

```php
<?php

var_dump("bah");
```
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ForbiddenEcho.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
Emitted when Psalm encounters an echo statement and the `forbidEcho` flag in your config is set to `true`

```php
<?php

echo("bah");
```
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ImplementedParamTypeMismatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when a class that inherits another, or implements an interface, has docblock param type that's entirely different to the parent. Subclasses of the parent return type are permitted, in docblocks.

```php
<?php

class D {
/** @param string $a */
public function foo($a): void {}
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ImplementedReturnTypeMismatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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
<?php

class A {
/** @return bool */
public function foo() {
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ImplicitToStringCast.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when implicitly converting an object with a `__toString` method to a string

```php
<?php

class A {
public function __toString() {
return "foo";
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ImpureByReferenceAssignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when assigning a passed-by-reference variable inside a function or method marked as mutation-free.

```php
<?php

/**
* @psalm-pure
*/
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ImpureFunctionCall.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when calling an impure function from a function or method marked as pure.

```php
<?php

function impure(array $a) : array {
/** @var int */
static $i = 0;
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ImpureMethodCall.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when calling an impure method from a function or method marked as pure.

```php
<?php

class A {
public int $a = 5;

Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ImpurePropertyAssignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when updating a property value from a function or method marked as pure.

```php
<?php

class A {
public int $a = 5;
}
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ImpureStaticProperty.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when attempting to use a static property from a function or method marked as pure

```php
<?php

class ValueHolder {
public static ?string $value = null;

Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/ImpureStaticVariable.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when attempting to use a static variable from a function or method marked as pure

```php
<?php

/** @psalm-pure */
function addCumulative(int $left) : int {
/** @var int */
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/InaccessibleClassConstant.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when a public/private class constant is not accessible from the calling context

```php
<?php

class A {
protected const FOO = 'FOO';
}
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/InaccessibleMethod.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Emitted when attempting to access a protected/private method from outside its available scope

```php
<?php

class A {
protected function foo() : void {}
}
Expand Down
Loading

0 comments on commit 84bfba0

Please sign in to comment.