Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply rector fixes #10305

Merged
merged 77 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
c9493c5
First pass
danog Oct 19, 2023
575db97
Revert tests
danog Oct 19, 2023
900807d
Fixes
danog Oct 19, 2023
19a5c01
Fix
danog Oct 19, 2023
4d4b6ca
More finalization
danog Oct 19, 2023
0b25592
Fix
danog Oct 19, 2023
7890085
Fix
danog Oct 19, 2023
048f55d
Fixes
danog Oct 19, 2023
d5ab48e
Fix
danog Oct 19, 2023
1cf3233
Fix
danog Oct 19, 2023
3852123
Fix
danog Oct 19, 2023
9ddc39d
Fix
danog Oct 19, 2023
a8ccc92
Update
danog Oct 19, 2023
34b4272
Fixup
danog Oct 19, 2023
f3c6193
Fix
danog Oct 19, 2023
887d2ff
Fix
danog Oct 19, 2023
69cddcf
Update
danog Oct 19, 2023
9d3fee4
Fix
danog Oct 19, 2023
dd2d3a2
Fixes
danog Oct 20, 2023
c88fa5c
Fix
danog Oct 20, 2023
dd8ee0f
Remove legacy code
danog Oct 20, 2023
96f2dde
Merge remote-tracking branch 'origin/5.x'
danog Oct 21, 2023
7f92c33
Merge branch 'rector'
danog Oct 21, 2023
97e5a07
Switch back to function JIT
danog Oct 21, 2023
e3396aa
Fixes
danog Oct 21, 2023
e19caf0
Fix
danog Oct 21, 2023
8ff340e
Fixup
danog Oct 21, 2023
b709673
Fixes
danog Oct 21, 2023
d0f832f
cs-fixes
danog Oct 21, 2023
a36d2fc
cs-fixes
danog Oct 21, 2023
1175c71
Update
danog Oct 21, 2023
cb48b00
cs-fix
danog Oct 21, 2023
4a433d3
More readonly props
danog Oct 21, 2023
f1d7843
Make more properties readonly
danog Oct 21, 2023
b2bde47
cs-fix
danog Oct 21, 2023
6613c92
Revert
danog Oct 21, 2023
64ef0d9
cs-fix
danog Oct 21, 2023
b62fe44
Fix
danog Oct 21, 2023
46ae91e
Fix
danog Oct 21, 2023
17b70c5
Fixes
danog Oct 21, 2023
90dea2f
Fix
danog Oct 21, 2023
dc2b724
cs-fix
danog Oct 21, 2023
601c842
Merge branch 'rector_5.x'
danog Oct 21, 2023
3017016
Merge branch 'rector_5.x'
danog Oct 21, 2023
4b1c2dd
Merge remote-tracking branch 'origin/master'
danog Oct 22, 2023
fa97e6d
Fix
danog Oct 22, 2023
edf9bbb
Merge remote-tracking branch 'origin/master'
danog Nov 26, 2023
3238f4e
Merge branch 'origin_master'
danog Nov 27, 2023
af1b185
Merge branch 'master' into master
danog Nov 27, 2023
4c0d4f9
Merge branch 'master' into master
danog Nov 28, 2023
a88bf62
Tweak config
danog Nov 29, 2023
337c7af
Merge branch 'master' into master
danog Dec 3, 2023
f1733c3
Merge branch 'merge_5.x'
danog Dec 19, 2023
d5b713e
Fix https://github.com/vimeo/psalm/issues/10501 - report error for no…
kkmuffme Dec 18, 2023
f3543ca
add the fix for empty() too and fix empty returning bool on true/fals…
kkmuffme Jan 12, 2024
fb93aed
create a separate issue type
kkmuffme Jan 12, 2024
63ea734
fix shepherd issue
kkmuffme Jan 12, 2024
19b1a33
fix possibly undefined array key in keyed array doesnt include null w…
kkmuffme Jan 13, 2024
93dc221
fix bugs in tests
kkmuffme Jan 12, 2024
dca17bc
unrelated fix spelling
kkmuffme Jan 13, 2024
2414070
simplify and remove redundant variable
kkmuffme Jan 13, 2024
5643cf5
fix mixed test not actually checking mixed (since superglobals have a…
kkmuffme Jan 13, 2024
f34ec2c
change error level to 2
kkmuffme Jan 15, 2024
4b41891
update baseline
kkmuffme Jan 15, 2024
a1b8b3d
Merge remote-tracking branch 'vimeo/master'
danog Jan 15, 2024
645e59e
cs-fix
danog Jan 15, 2024
a3a1324
fix baseline somehow incorrect paths
kkmuffme Jan 17, 2024
0504394
Fixup
danog Jan 17, 2024
680c8cd
Merge pull request #10502 from kkmuffme/warn-for-non-strict-compariso…
danog Jan 17, 2024
4e5e306
Fixup
danog Jan 17, 2024
823c918
Fixup
danog Jan 17, 2024
950293c
Fixup test
danog Jan 17, 2024
11e2163
Update baseline
danog Jan 17, 2024
2a7d6d2
cs-fix
danog Jan 17, 2024
0ba0928
Try bumping PHP on windows CI
danog Jan 17, 2024
58c5598
Try disabling opcache
danog Jan 17, 2024
3411dd8
Skip opcache on windows
danog Jan 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
ini-values: zend.assertions=1, assert.exception=1, opcache.enable_cli=1, opcache.jit=function, opcache.jit_buffer_size=512M
#ini-values: zend.assertions=1, assert.exception=1, opcache.enable_cli=1, opcache.jit=function, opcache.jit_buffer_size=512M
ini-values: zend.assertions=1, assert.exception=1
tools: composer:v2
coverage: none
extensions: none, curl, dom, filter, intl, json, libxml, mbstring, openssl, opcache, pcre, phar, reflection, simplexml, spl, tokenizer, xml, xmlwriter
#extensions: none, curl, dom, filter, intl, json, libxml, mbstring, openssl, opcache, pcre, phar, reflection, simplexml, spl, tokenizer, xml, xmlwriter
extensions: none, curl, dom, filter, intl, json, libxml, mbstring, openssl, pcre, phar, reflection, simplexml, spl, tokenizer, xml, xmlwriter
env:
fail-fast: true

Expand Down
1 change: 1 addition & 0 deletions config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@
<xs:element name="ReferenceReusedFromConfusingScope" type="IssueHandlerType" minOccurs="0" />
<xs:element name="ReservedWord" type="IssueHandlerType" minOccurs="0" />
<xs:element name="RiskyCast" type="IssueHandlerType" minOccurs="0" />
<xs:element name="RiskyTruthyFalsyComparison" type="IssueHandlerType" minOccurs="0" />
<xs:element name="StringIncrement" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TaintedCallable" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TaintedCookie" type="IssueHandlerType" minOccurs="0" />
Expand Down
1 change: 1 addition & 0 deletions docs/running_psalm/error_levels.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Level 5 and above allows a more non-verifiable code, and higher levels are even
- [RedundantConditionGivenDocblockType](issues/RedundantConditionGivenDocblockType.md)
- [RedundantFunctionCallGivenDocblockType](issues/RedundantFunctionCallGivenDocblockType.md)
- [ReferenceConstraintViolation](issues/ReferenceConstraintViolation.md)
- [RiskyTruthyFalsyComparison](issues/RiskyTruthyFalsyComparison.md)
- [UndefinedTrace](issues/UndefinedTrace.md)
- [UnresolvableInclude](issues/UnresolvableInclude.md)
- [UnsafeInstantiation](issues/UnsafeInstantiation.md)
Expand Down
1 change: 1 addition & 0 deletions docs/running_psalm/issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
- [ReferenceReusedFromConfusingScope](issues/ReferenceReusedFromConfusingScope.md)
- [ReservedWord](issues/ReservedWord.md)
- [RiskyCast](issues/RiskyCast.md)
- [RiskyTruthyFalsyComparison](issues/RiskyTruthyFalsyComparison.md)
- [StringIncrement](issues/StringIncrement.md)
- [TaintedCallable](issues/TaintedCallable.md)
- [TaintedCookie](issues/TaintedCookie.md)
Expand Down
29 changes: 29 additions & 0 deletions docs/running_psalm/issues/RiskyTruthyFalsyComparison.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# RiskyTruthyFalsyComparison

Emitted when comparing a value with multiple types that can both contain truthy and falsy values.

```php
<?php

/**
* @param array|null $arg
* @return void
*/
function foo($arg) {
if ($arg) {
// this is risky, bc the empty array and null case are handled together
}

if (!$arg) {
// this is risky, bc the empty array and null case are handled together
}
}
```

## Why this is bad

The truthy/falsy type of one variable is often forgotten and not handled explicitly causing hard to track down errors.

## How to fix

Explicitly validate the variable with strict comparison.
4 changes: 2 additions & 2 deletions examples/TemplateChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

final class TemplateAnalyzer extends Psalm\Internal\Analyzer\FileAnalyzer
{
const VIEW_CLASS = 'Your\\View\\Class';
final public const VIEW_CLASS = 'Your\\View\\Class';

public function analyze(?Context $file_context = null, ?Context $global_context = null): void
{
Expand Down Expand Up @@ -148,7 +148,7 @@ private function checkMethod(MethodIdentifier $method_id, PhpParser\Node $stmt,
/**
* @param array<PhpParser\Node\Stmt> $stmts
*/
protected function checkWithViewClass(Context $context, array $stmts): void
private function checkWithViewClass(Context $context, array $stmts): void
{
$pseudo_method_stmts = [];

Expand Down
2 changes: 1 addition & 1 deletion examples/TemplateScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

final class TemplateScanner extends Psalm\Internal\Scanner\FileScanner
{
const VIEW_CLASS = 'Your\\View\\Class';
final public const VIEW_CLASS = 'Your\\View\\Class';

public function scan(
Codebase $codebase,
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/ClassUnqualifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function afterClassLikeExistenceCheck(
return;
}

if (strpos($candidate_type, '\\' . $fq_class_name) !== false) {
if (str_contains($candidate_type, '\\' . $fq_class_name)) {
$type_tokens = TypeTokenizer::tokenize($candidate_type, false);

foreach ($type_tokens as &$type_token) {
Expand Down
4 changes: 2 additions & 2 deletions examples/plugins/FunctionCasingChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
$statements_source->getSuppressedIssues(),
);
}
} catch (Exception $e) {
} catch (Exception) {
// can throw if storage is missing
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public static function afterFunctionCallAnalysis(AfterFunctionCallAnalysisEvent
$statements_source->getSuppressedIssues(),
);
}
} catch (Exception $e) {
} catch (Exception) {
// can throw if storage is missing
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/InternalChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event
{
$storage = $event->getClasslikeStorage();
if (!$storage->internal
&& strpos($storage->name, 'Psalm\\Internal') === 0
&& str_starts_with($storage->name, 'Psalm\\Internal')
&& $storage->location
) {
IssueBuffer::maybeAdd(
Expand Down
4 changes: 2 additions & 2 deletions examples/plugins/StringChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $eve
if ($expr instanceof PhpParser\Node\Scalar\String_) {
$class_or_class_method = '/^\\\?Psalm(\\\[A-Z][A-Za-z0-9]+)+(::[A-Za-z0-9]+)?$/';

if (strpos($statements_source->getFileName(), 'base/DefinitionManager.php') === false
&& strpos($expr->value, 'TestController') === false
if (!str_contains($statements_source->getFileName(), 'base/DefinitionManager.php')
&& !str_contains($expr->value, 'TestController')
&& preg_match($class_or_class_method, $expr->value)
) {
/** @psalm-suppress PossiblyInvalidArrayAccess */
Expand Down
Loading