Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Nov 26, 2023
2 parents fa97e6d + baa6d5d commit edf9bbb
Show file tree
Hide file tree
Showing 83 changed files with 1,099 additions and 339 deletions.
3 changes: 3 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
- [BC] The only optional boolean parameter of `TKeyedArray::getGenericArrayType` was removed, and was replaced with a string parameter with a different meaning.

- [BC] The `TDependentListKey` type was removed and replaced with an optional property of the `TIntRange` type.
-
- [BC] `TCallableArray` and `TCallableList` removed and replaced with `TCallableKeyedArray`.

- [BC] Class `Psalm\Issue\MixedInferredReturnType` was removed

- [BC] Value of constant `Psalm\Type\TaintKindGroup::ALL_INPUT` changed to reflect new `TaintKind::INPUT_SLEEP` and `TaintKind::INPUT_XPATH` have been added. Accordingly, default values for `$taint` parameters of `Psalm\Codebase::addTaintSource()` and `Psalm\Codebase::addTaintSink()` have been changed as well.

- [BC] Property `Config::$shepherd_host` was replaced with `Config::$shepherd_endpoint`
Expand Down
3 changes: 2 additions & 1 deletion config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<xs:attribute name="findUnusedPsalmSuppress" type="xs:boolean" default="false" />
<!-- TODO: Update default to true in Psalm 6 -->
<xs:attribute name="findUnusedBaselineEntry" type="xs:boolean" default="false" />
<xs:attribute name="findUnusedIssueHandlerSuppression" type="xs:boolean" default="true" />
<xs:attribute name="hideExternalErrors" type="xs:boolean" default="false" />
<xs:attribute name="hoistConstants" type="xs:boolean" default="false" />
<xs:attribute name="ignoreInternalFunctionFalseReturn" type="xs:boolean" default="false" />
Expand Down Expand Up @@ -333,7 +334,6 @@
<xs:element name="MixedAssignment" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedClone" type="ArgumentIssueHandlerType" minOccurs="0" />
<xs:element name="MixedFunctionCall" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedInferredReturnType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedMethodCall" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedOperand" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedPropertyAssignment" type="IssueHandlerType" minOccurs="0" />
Expand Down Expand Up @@ -494,6 +494,7 @@
<xs:element name="UnusedClosureParam" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UnusedConstructor" type="MethodIssueHandlerType" minOccurs="0" />
<xs:element name="UnusedDocblockParam" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UnusedIssueHandlerSuppression" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UnusedForeachValue" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UnusedFunctionCall" type="FunctionIssueHandlerType" minOccurs="0" />
<xs:element name="UnusedMethod" type="MethodIssueHandlerType" minOccurs="0" />
Expand Down
8 changes: 4 additions & 4 deletions docs/annotating_code/supported_annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ takesFoo(getFoo());

This provides the same, but for `false`. Psalm uses this internally for functions like `preg_replace`, which can return false if the given input has encoding errors, but where 99.9% of the time the function operates as expected.

### `@psalm-seal-properties`, `@psalm-no-seal-properties`
### `@psalm-seal-properties`, `@psalm-no-seal-properties`, `@seal-properties`, `@no-seal-properties`

If you have a magic property getter/setter, you can use `@psalm-seal-properties` to instruct Psalm to disallow getting and setting any properties not contained in a list of `@property` (or `@property-read`/`@property-write`) annotations.
This is automatically enabled with the configuration option `sealAllProperties` and can be disabled for a class with `@psalm-no-seal-properties`
Expand All @@ -211,7 +211,7 @@ This is automatically enabled with the configuration option `sealAllProperties`
<?php
/**
* @property string $foo
* @psalm-seal-properties
* @seal-properties
*/
class A {
public function __get(string $name): ?string {
Expand All @@ -227,7 +227,7 @@ $a = new A();
$a->bar = 5; // this call fails
```

### `@psalm-seal-methods`, `@psalm-no-seal-methods`
### `@psalm-seal-methods`, `@psalm-no-seal-methods`, `@seal-methods`, `@no-seal-methods`

If you have a magic method caller, you can use `@psalm-seal-methods` to instruct Psalm to disallow calling any methods not contained in a list of `@method` annotations.
This is automatically enabled with the configuration option `sealAllMethods` and can be disabled for a class with `@psalm-no-seal-methods`
Expand All @@ -236,7 +236,7 @@ This is automatically enabled with the configuration option `sealAllMethods` and
<?php
/**
* @method foo(): string
* @psalm-seal-methods
* @seal-methods
*/
class A {
public function __call(string $name, array $args) {
Expand Down
5 changes: 5 additions & 0 deletions docs/running_psalm/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ class PremiumCar extends StandardCar {
Emits [UnusedBaselineEntry](issues/UnusedBaselineEntry.md) when a baseline entry
is not being used to suppress an issue.

#### findUnusedIssueHandlerSuppression

Emits [UnusedIssueHandlerSuppression](issues/UnusedIssueHandlerSuppression.md) when a suppressed issue handler
is not being used to suppress an issue.

## Project settings

#### &lt;projectFiles&gt;
Expand Down
1 change: 0 additions & 1 deletion docs/running_psalm/error_levels.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ Level 5 and above allows a more non-verifiable code, and higher levels are even
- [MixedAssignment](issues/MixedAssignment.md)
- [MixedClone](issues/MixedClone.md)
- [MixedFunctionCall](issues/MixedFunctionCall.md)
- [MixedInferredReturnType](issues/MixedInferredReturnType.md)
- [MixedMethodCall](issues/MixedMethodCall.md)
- [MixedOperand](issues/MixedOperand.md)
- [MixedPropertyAssignment](issues/MixedPropertyAssignment.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/running_psalm/issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
- [MixedAssignment](issues/MixedAssignment.md)
- [MixedClone](issues/MixedClone.md)
- [MixedFunctionCall](issues/MixedFunctionCall.md)
- [MixedInferredReturnType](issues/MixedInferredReturnType.md)
- [MixedMethodCall](issues/MixedMethodCall.md)
- [MixedOperand](issues/MixedOperand.md)
- [MixedPropertyAssignment](issues/MixedPropertyAssignment.md)
Expand Down Expand Up @@ -298,6 +297,7 @@
- [UnusedDocblockParam](issues/UnusedDocblockParam.md)
- [UnusedForeachValue](issues/UnusedForeachValue.md)
- [UnusedFunctionCall](issues/UnusedFunctionCall.md)
- [UnusedIssueHandlerSuppression](issues/UnusedIssueHandlerSuppression.md)
- [UnusedMethod](issues/UnusedMethod.md)
- [UnusedMethodCall](issues/UnusedMethodCall.md)
- [UnusedParam](issues/UnusedParam.md)
Expand Down
11 changes: 0 additions & 11 deletions docs/running_psalm/issues/MixedInferredReturnType.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/running_psalm/issues/TaintedEval.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TaintedEval

Emitted when user-controlled input can be passed into to an `eval` call.
Emitted when user-controlled input can be passed into an `eval` call.

Passing untrusted user input to `eval` calls is dangerous, as it allows arbitrary data to be executed on your server.

Expand Down
2 changes: 1 addition & 1 deletion docs/running_psalm/issues/TaintedHtml.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TaintedHtml

Emitted when user-controlled input that can contain HTML can be passed into to an `echo` statement.
Emitted when user-controlled input that can contain HTML can be passed into an `echo` statement.

## Risk

Expand Down
2 changes: 1 addition & 1 deletion docs/running_psalm/issues/TaintedInclude.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TaintedInclude

Emitted when user-controlled input can be passed into to an `include` or `require` expression.
Emitted when user-controlled input can be passed into an `include` or `require` expression.

Passing untrusted user input to `include` calls is dangerous, as it can allow an attacker to execute arbitrary scripts on your server.

Expand Down
2 changes: 1 addition & 1 deletion docs/running_psalm/issues/TaintedShell.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TaintedShell

Emitted when user-controlled input can be passed into to an `exec` call or similar.
Emitted when user-controlled input can be passed into an `exec` call or similar.

```php
<?php
Expand Down
2 changes: 1 addition & 1 deletion docs/running_psalm/issues/TaintedSql.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TaintedSql

Emitted when user-controlled input can be passed into to a SQL command.
Emitted when user-controlled input can be passed into a SQL command.

```php
<?php
Expand Down
2 changes: 1 addition & 1 deletion docs/running_psalm/issues/TaintedTextWithQuotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TaintedTextWithQuotes

Emitted when user-controlled input that can contain quotation marks can be passed into to an `echo` statement.
Emitted when user-controlled input that can contain quotation marks can be passed into an `echo` statement.

## Risk

Expand Down
2 changes: 1 addition & 1 deletion docs/running_psalm/issues/TaintedXpath.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TaintedXpath

Emitted when user-controlled input can be passed into to a xpath query.
Emitted when user-controlled input can be passed into a xpath query.

```php
<?php
Expand Down
17 changes: 17 additions & 0 deletions docs/running_psalm/issues/UnusedIssueHandlerSuppression.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# UnusedIssueHandlerSuppression

Emitted when an issue type suppression in the configuration file is not being used to suppress an issue.

Enabled by [findUnusedIssueHandlerSuppression](../configuration.md#findunusedissuehandlersuppression)

```php
<?php
$a = 'Hello, World!';
echo $a;
```
```xml
<?xml version="1.0" encoding="UTF-8"?>
<issueHandlers>
<PossiblyNullOperand errorLevel="suppress"/>
</issueHandlers>
```
25 changes: 1 addition & 24 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
errorBaseline="psalm-baseline.xml"
findUnusedPsalmSuppress="true"
findUnusedBaselineEntry="true"
findUnusedIssueHandlerSuppression="true"
>
<stubs>
<file name="stubs/phpparser.phpstub"/>
Expand Down Expand Up @@ -63,24 +64,6 @@
</errorLevel>
</DeprecatedMethod>

<DeprecatedClass>
<errorLevel type="suppress">
<referencedClass name="PackageVersions\Versions"/>
</errorLevel>
</DeprecatedClass>

<UnusedParam>
<errorLevel type="suppress">
<directory name="examples"/>
</errorLevel>
</UnusedParam>

<PossiblyUnusedParam>
<errorLevel type="suppress">
<directory name="examples"/>
</errorLevel>
</PossiblyUnusedParam>

<UnusedClass>
<errorLevel type="suppress">
<directory name="examples"/>
Expand All @@ -104,12 +87,6 @@
</errorLevel>
</PossiblyUndefinedIntArrayOffset>

<ImpureMethodCall>
<errorLevel type="suppress">
<directory name="src/Psalm/Storage/Assertion"/>
</errorLevel>
</ImpureMethodCall>

<MissingThrowsDocblock errorLevel="info"/>

<PossiblyUnusedProperty>
Expand Down
37 changes: 36 additions & 1 deletion src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ final class Config
'MixedArrayTypeCoercion',
'MixedAssignment',
'MixedFunctionCall',
'MixedInferredReturnType',
'MixedMethodCall',
'MixedOperand',
'MixedPropertyFetch',
Expand Down Expand Up @@ -230,6 +229,8 @@ final class Config
*/
public string $base_dir;

public ?string $source_filename = null;

/**
* The PHP version to assume as declared in the config file
*/
Expand Down Expand Up @@ -369,6 +370,8 @@ final class Config

public bool $find_unused_baseline_entry = true;

public bool $find_unused_issue_handler_suppression = true;

public bool $run_taint_analysis = false;

public bool $use_phpstorm_meta_path = true;
Expand Down Expand Up @@ -935,6 +938,7 @@ private static function fromXmlAndPaths(
'allowNamedArgumentCalls' => 'allow_named_arg_calls',
'findUnusedPsalmSuppress' => 'find_unused_psalm_suppress',
'findUnusedBaselineEntry' => 'find_unused_baseline_entry',
'findUnusedIssueHandlerSuppression' => 'find_unused_issue_handler_suppression',
'reportInfo' => 'report_info',
'restrictReturnTypes' => 'restrict_return_types',
'limitMethodComplexity' => 'limit_method_complexity',
Expand All @@ -950,6 +954,7 @@ private static function fromXmlAndPaths(
}
}

$config->source_filename = $config_path;
if ($config->resolve_from_config_file) {
$config->base_dir = $base_dir;
} else {
Expand Down Expand Up @@ -1311,6 +1316,12 @@ public function setComposerClassLoader(?ClassLoader $loader = null): void
$this->composer_class_loader = $loader;
}

/** @return array<string, IssueHandler> */
public function getIssueHandlers(): array
{
return $this->issue_handlers;
}

public function setAdvancedErrorLevel(string $issue_key, array $config, ?string $default_error_level = null): void
{
$this->issue_handlers[$issue_key] = new IssueHandler();
Expand Down Expand Up @@ -1858,6 +1869,30 @@ public static function getParentIssueType(string $issue_type): ?string
return null;
}

/** @return array{type: string, index: int, count: int}[] */
public function getIssueHandlerSuppressions(): array
{
$suppressions = [];
foreach ($this->issue_handlers as $key => $handler) {
foreach ($handler->getFilters() as $index => $filter) {
$suppressions[] = [
'type' => $key,
'index' => $index,
'count' => $filter->suppressions,
];
}
}
return $suppressions;
}

/** @param array{type: string, index: int, count: int}[] $filters */
public function combineIssueHandlerSuppressions(array $filters): void
{
foreach ($filters as $filter) {
$this->issue_handlers[$filter['type']]->getFilters()[$filter['index']]->suppressions += $filter['count'];
}
}

public function getReportingLevelForFile(string $issue_type, string $file_path): string
{
if (isset($this->issue_handlers[$issue_type])) {
Expand Down
2 changes: 2 additions & 0 deletions src/Psalm/Config/ErrorLevelFileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ final class ErrorLevelFileFilter extends FileFilter
{
private string $error_level = '';

public int $suppressions = 0;

public static function loadFromArray(
array $config,
string $base_dir,
Expand Down
Loading

0 comments on commit edf9bbb

Please sign in to comment.