Skip to content

Commit

Permalink
Merge pull request #11283 from vimeo/enable_more_features
Browse files Browse the repository at this point in the history
Enable more features by default
  • Loading branch information
danog authored Feb 17, 2025
2 parents a6e223b + 8daae1d commit 782756e
Show file tree
Hide file tree
Showing 21 changed files with 1,123 additions and 24 deletions.
11 changes: 6 additions & 5 deletions config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<xs:attribute name="checkForThrowsInGlobalScope" type="xs:boolean" default="false" />
<xs:attribute name="ensureArrayIntOffsetsExist" type="xs:boolean" default="false" />
<xs:attribute name="ensureArrayStringOffsetsExist" type="xs:boolean" default="false" />
<xs:attribute name="ensureOverrideAttribute" type="xs:boolean" default="false" />
<xs:attribute name="ensureOverrideAttribute" type="xs:boolean" default="true" />
<xs:attribute name="findUnusedCode" type="xs:boolean" default="true" />
<xs:attribute name="disallowLiteralKeysOnUnshapedArrays" type="xs:boolean" default="false" />
<xs:attribute name="allFunctionsGlobal" type="xs:boolean" default="false" />
Expand All @@ -61,7 +61,8 @@
<xs:attribute name="memoizeMethodCallResults" type="xs:boolean" default="false" />
<xs:attribute name="rememberPropertyAssignmentsAfterCall" type="xs:boolean" default="true" />
<xs:attribute name="resolveFromConfigFile" type="xs:boolean" default="true" />
<xs:attribute name="strictBinaryOperands" type="xs:boolean" default="false" />
<xs:attribute name="strictBinaryOperands" type="xs:boolean" default="true" />
<xs:attribute name="allowBoolToLiteralBoolComparison" type="xs:boolean" default="true" />
<xs:attribute name="throwExceptionOnError" type="xs:boolean" default="false" />
<xs:attribute name="disableVarParsing" type="xs:boolean" default="false" />
<xs:attribute name="errorLevel" type="xs:integer" default="2" />
Expand All @@ -72,16 +73,16 @@
<xs:attribute name="usePhpDocMethodsWithoutMagicCall" type="xs:boolean" default="false" />
<xs:attribute name="usePhpDocPropertiesWithoutMagicCall" type="xs:boolean" default="false" />
<xs:attribute name="skipChecksOnUnresolvableIncludes" type="xs:boolean" default="false" />
<xs:attribute name="sealAllMethods" type="xs:boolean" default="false" />
<xs:attribute name="sealAllProperties" type="xs:boolean" default="false" />
<xs:attribute name="sealAllMethods" type="xs:boolean" default="true" />
<xs:attribute name="sealAllProperties" type="xs:boolean" default="true" />
<xs:attribute name="runTaintAnalysis" type="xs:boolean" default="false" />
<xs:attribute name="usePhpStormMetaPath" type="xs:boolean" default="true" />
<xs:attribute name="allowInternalNamedArgumentCalls" type="xs:boolean" default="true" />
<xs:attribute name="allowNamedArgumentCalls" type="xs:boolean" default="true" />
<xs:attribute name="reportInfo" type="xs:boolean" default="true" />
<xs:attribute name="restrictReturnTypes" type="xs:boolean" default="false" />
<xs:attribute name="limitMethodComplexity" type="xs:boolean" default="false" />
<xs:attribute name="disableSuppressAll" type="xs:boolean" default="false" />
<xs:attribute name="disableSuppressAll" type="xs:boolean" default="true" />
<xs:attribute name="triggerErrorExits" type="TriggerErrorExitsType" default="default" />
<xs:attribute name="threads" type="xs:integer" />
<xs:attribute name="scanThreads" type="xs:integer" />
Expand Down
22 changes: 16 additions & 6 deletions docs/running_psalm/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,17 @@ Disables parsing of `@var` PHPDocs everywhere except for properties. Setting thi
strictBinaryOperands="[bool]"
>
```
If true we force strict typing on numerical and string operations (see https://github.com/vimeo/psalm/issues/24). Defaults to `false`.
If true we force strict typing on numerical and string operations (see https://github.com/vimeo/psalm/issues/24). Defaults to `true`.

#### allowBoolToLiteralBoolComparison

```xml
<psalm
allowBoolToLiteralBoolComparison="[bool]"
>
```

If false, disallows comparing a boolean to a literal boolean (mostly a codestyle rule, not a bug detection rule; see [RedundantIdentityWithTrue](https://psalm.dev/docs/running_psalm/issues/RedundantIdentityWithTrue/)). Defaults to `true`.

#### rememberPropertyAssignmentsAfterCall

Expand All @@ -161,7 +171,7 @@ When `true`, strings can be used as classes, meaning `$some_string::someMethod()
disableSuppressAll="[bool]"
>
```
When `true`, disables wildcard suppression of all issues with `@psalm-suppress all`. Defaults to `false`.
When `true`, disables wildcard suppression of all issues with `@psalm-suppress all`. Defaults to `true`.

#### memoizeMethodCallResults

Expand Down Expand Up @@ -247,7 +257,7 @@ When `true`, Psalm will attempt to find all unused variables, the equivalent of
findUnusedCode="[bool]"
>
```
When `true`, Psalm will attempt to find all unused code (including unused variables), the equivalent of running with `--find-unused-code`. Defaults to `false`.
When `true`, Psalm will attempt to find all unused code (including unused variables), the equivalent of running with `--find-unused-code`. Defaults to `true`.

#### disallowLiteralKeysOnUnshapedArrays
```xml
Expand Down Expand Up @@ -304,7 +314,7 @@ When `true`, Psalm will complain when referencing an explicit integer offset on
ensureOverrideAttribute="[bool]"
>
```
When `true`, Psalm will report class and interface methods that override a method on a parent, but do not have an `Override` attribute. Defaults to `false`.
When `true`, Psalm will report class and interface methods that override a method on a parent, but do not have an `Override` attribute. Defaults to `true`.

#### phpVersion
```xml
Expand Down Expand Up @@ -335,7 +345,7 @@ This defaults to `false`.
>
```

When `true`, Psalm will treat all classes as if they had sealed methods, meaning that if you implement the magic method `__call`, you also have to add `@method` for each magic method. Defaults to false.
When `true`, Psalm will treat all classes as if they had sealed methods, meaning that if you implement the magic method `__call`, you also have to add `@method` for each magic method. Defaults to true.

#### sealAllProperties

Expand All @@ -345,7 +355,7 @@ When `true`, Psalm will treat all classes as if they had sealed methods, meaning
>
```

When `true`, Psalm will treat all classes as if they had sealed properties, meaning that Psalm will disallow getting and setting any properties not contained in a list of `@property` (or `@property-read`/`@property-write`) annotations and not explicitly defined as a `property`. Defaults to false.
When `true`, Psalm will treat all classes as if they had sealed properties, meaning that Psalm will disallow getting and setting any properties not contained in a list of `@property` (or `@property-read`/`@property-write`) annotations and not explicitly defined as a `property`. Defaults to true.

#### runTaintAnalysis

Expand Down
23 changes: 22 additions & 1 deletion docs/running_psalm/issues/RedundantIdentityWithTrue.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# RedundantIdentityWithTrue

Emitted when comparing a known boolean with true and the `strictBinaryOperands` flag is set to true.
This is a codestyle rule, it does not indicate a possible bug.

Emitted when comparing a known boolean with with a literal boolean and the `allowBoolToLiteralBoolComparison` flag is set to false.

```php
<?php
Expand All @@ -17,3 +19,22 @@ if (returnsABool() !== false) {
echo "hi!";
}
```

To fix:

```php
<?php

function returnsABool(): bool {
return rand(1, 2) === 1;
}

if (returnsABool()) {
echo "hi!";
}

if (returnsABool()) {
echo "hi!";
}
```

36 changes: 36 additions & 0 deletions docs/running_psalm/issues/UndefinedMagicPropertyAssignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,39 @@ class A {
$a = new A();
$a->foo = "bar";
```

To fix, add all used magic properties as `@property` annotations:

```php
<?php

/**
* @property string $bar
* @property string $foo
*/
class A {
/** @param mixed $value */
public function __set(string $name, $value) {}
}
$a = new A();
$a->foo = "bar";
```

Or, **only if** dealing with generic container objects (like `ArrayObject`), use `@psalm-no-seal-properties`.

```php
<?php

/** @psalm-no-seal-properties */
class ArrayBag {
public function __construct(private array $arr = []) {}
public function __set(string $k, mixed $v) {
$this->arr[$k] = $v;
}
public function __get(string $k): mixed {
return $this->arr[$k];
}
}
$a = new A(['bar' => 'foo']);
$a->foo = "bar";
```
36 changes: 36 additions & 0 deletions docs/running_psalm/issues/UndefinedMagicPropertyFetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,39 @@ class A {
$a = new A();
echo $a->foo;
```

To fix, add all used magic properties as `@property` annotations:

```php
<?php

/**
* @property string $bar
* @property string $foo
*/
class A {
/** @param mixed $value */
public function __set(string $name, $value) {}
}
$a = new A();
echo $a->foo;
```

Or, **only if** dealing with generic container objects (like `ArrayObject`), use `@psalm-no-seal-properties`.

```php
<?php

/** @psalm-no-seal-properties */
class ArrayBag {
public function __construct(private array $arr = []) {}
public function __set(string $k, mixed $v) {
$this->arr[$k] = $v;
}
public function __get(string $k): mixed {
return $this->arr[$k];
}
}
$a = new A(['bar' => 'foo']);
echo $a->bar;
```
Loading

0 comments on commit 782756e

Please sign in to comment.