1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-14 18:36:58 +01:00
Commit Graph

313 Commits

Author SHA1 Message Date
orklah
3322801903 ignore comments after taint-sink 2021-11-07 10:17:25 +01:00
Bruce Weirdan
0cdb0dc04a
Merge pull request #6768 from zoonru/psalm-self-out-templates 2021-11-02 21:41:16 +02:00
Alexey Borzov
91ec5712ad Add a means to switch return types based on PHP_VERSION_ID
As suggested in vimeo/psalm#6755
2021-10-29 22:19:38 +03:00
orklah
67a3f3cd5c fix spacing 2021-10-28 22:11:30 +02:00
orklah
067f8375cf replace exception by InvalidDocblock 2021-10-28 22:05:43 +02:00
5fae548e62
Add template support to @psalm-self-out 2021-10-28 10:44:37 +02:00
orklah
e17ca1ba10 fix CS/test 2021-10-27 22:45:16 +02:00
orklah
9b7eabe17f allow documenting promoted properties with @var 2021-10-27 22:35:21 +02:00
Aleksandr Zhuravlev
b664850cdc Added support of asserting properties of objects out of scope 2021-10-17 21:29:25 +13:00
orklah
64df00baba
Merge pull request #6660 from orklah/cleanup4
Code trimming
2021-10-14 00:12:21 +02:00
orklah
ae193ca4da replace elvis operator by coalesce operator when applicable 2021-10-13 20:16:06 +02:00
orklah
dbc6f503b1 use of strtolower only once 2021-10-13 20:16:06 +02:00
orklah
bee5b69f7f use Attribute feature of PHP-Parser to avoid dealing with dynamic properties 2021-10-13 13:27:56 +02:00
orklah
911076939c
Merge pull request #6628 from orklah/phpparser2
Php-Parser 4.13
2021-10-11 20:42:32 +02:00
orklah
da4a0fe9a9 return null when expression can't be stored as unresolved 2021-10-10 09:28:19 +02:00
orklah
e7a86148b0 Allow Psalm to store unresolved Unary Ops 2021-10-10 09:24:25 +02:00
orklah
ded92ef83c forbid intersection types for now 2021-10-09 23:48:32 +02:00
orklah
870ee4ff93 ->args to ->getArgs 2021-10-09 23:37:04 +02:00
orklah
d44d00fb6d fix two more cases 2021-10-09 18:10:49 +02:00
orklah
a2f415e2e0 fix @return 0 2021-10-09 17:58:06 +02:00
orklah
8b07e69645
Merge pull request #6514 from zoonru/if-this-is
Add if-this-is
2021-10-04 09:49:26 +02:00
orklah
53c0a4e63a cleanup 2021-10-04 00:03:06 +02:00
Oliver Hader
51333e8f6e
[TASK] Resolve namespace of class related AST statements
This change allows using `Class_` namespaces like in
PhpParser's original `NameResolver` implementation.

```
if ($node instanceof \PhpParser\Node\Stmt\Class_) {
    $fqcn = (string)($node->namespacedName ?? $node->name);
    $extents = (string)($node->extends->getAttribute('resolvedName'));
}
```

Corresponding parts have been duplicated and modified from
https://github.com/nikic/PHP-Parser/blob/v4.10.4/lib/PhpParser/NodeVisitor/NameResolver.php#L69-L81
2021-09-27 11:19:24 +02:00
orklah
ab6efe49b2 fix CS 2021-09-26 23:41:26 +02:00
orklah
38dac34846 unnecessary null initialization 2021-09-26 23:34:32 +02:00
orklah
9170b0af8f replace list() 2021-09-26 23:34:32 +02:00
orklah
2315316b17 return types 2021-09-26 23:34:32 +02:00
orklah
72eab30a3a coalesce operator 2021-09-26 23:34:31 +02:00
orklah
46801c4b98 clearer string operations 2021-09-26 23:34:31 +02:00
orklah
53e4719c19 boolean cast 2021-09-26 22:39:01 +02:00
orklah
ddf74919f6 if with common parts 2021-09-26 22:37:17 +02:00
orklah
a85cba3973 dead code 2021-09-26 22:37:17 +02:00
orklah
ae1afd90c6 coalesce operator 2021-09-26 22:37:17 +02:00
orklah
5b684309fd unnecessary ternary 2021-09-26 22:37:16 +02:00
orklah
fce60a018a param defaults 2021-09-26 22:37:16 +02:00
orklah
c0f6474bc6 merging exceptions 2021-09-26 22:36:17 +02:00
orklah
a214b14388 CS fix 2021-09-25 18:38:01 +02:00
orklah
f4fa1f7a1b CS fix 2021-09-25 18:35:18 +02:00
orklah
f1e5ecf876 CS fix 2021-09-25 18:28:25 +02:00
orklah
06da96843a interface compat 2021-09-25 18:09:49 +02:00
orklah
7447489133 better types 2021-09-25 17:57:18 +02:00
orklah
6c892125c3 interface compat 2021-09-25 17:33:12 +02:00
orklah
06f497fca9 missing return 2021-09-25 16:50:14 +02:00
orklah
e61d490662 missing return 2021-09-25 16:49:46 +02:00
orklah
a92fee8ae3 better combining 2021-09-25 11:21:06 +02:00
orklah
97e91e6bf0 code trimming 2021-09-25 02:34:21 +02:00
83d596e2e5
Fixes 2021-09-22 10:36:54 +02:00
ba2c2bdaa2
Fix tests 2021-09-21 13:00:13 +02:00
7e0b489efe
Merge remote-tracking branch 'origin/master' into if-this-is 2021-09-21 12:12:15 +02:00
orklah
96adb96dab fix or suppress cases in Psalm 2021-09-12 23:12:23 +02:00
Bruce Weirdan
b4f024b1fe
Basic enum checks
* Duplicate cases
* Duplicate case values
* Invalid case values: value on a pure enum case, missing value on a
backed enum case, backing type / case type mismatch
* Literal expression evaluation for case values

Fixes vimeo/psalm#6426
Fixes vimeo/psalm#6427
2021-09-07 12:35:38 +03:00
piporoid
1df5f3012a Prevent @property annotations on class properties 2021-08-17 23:40:26 +09:00
orklah
2253667bd5 fix CS, remove redundant vars 2021-08-07 00:22:47 +02:00
orklah
b194291bb3 try to fix offsets 2021-08-07 00:08:19 +02:00
Bruce Weirdan
4cb9d8ceec
Merge pull request #6205 from orklah/typos
fix typos
2021-07-29 22:31:03 +03:00
orklah
d0fe1528b6 fix typos 2021-07-29 20:59:52 +02:00
orklah
72d60249a9 Inaccurate error with different types in PHPDoc and typehint 2021-07-26 23:03:00 +02:00
Matthew Brown
43cff22b25 Add support for native PHP readonly 2021-07-21 13:29:07 -04:00
Claas Augner
c6ccf61a5c Make ClassLikeNodeScanner resilient against missing class storage 2021-07-09 16:56:45 +02:00
Claas Augner
b91e00b03f Always keep FunctionLikeStorage->param_lookup in sync 2021-07-06 11:58:58 +02:00
Claas Augner
601a981898 Extract FunctionLikeStorage::setParams()/addParam() 2021-07-06 11:52:42 +02:00
Matt Brown
aade5d0def Add slash 2021-06-12 17:17:27 -04:00
Matt Brown
b678461f5c Improve detection of fluent methods 2021-06-12 17:09:42 -04:00
Bruce Weirdan
6abce3525a
Enforce use sort (#5900) 2021-06-07 22:55:21 -04:00
Bruce Weirdan
c98b20247b
Flag unexpected tags on function docblocks (#5845)
* Flag unexpected tags on function docblocks

Fixes vimeo/psalm#5782

* Document new issue

* Fix spacing

Co-authored-by: Matthew Brown <github@muglug.com>
2021-05-28 09:47:39 -04:00
orklah
aaab522a98
update baseline and fix issues (#5821) 2021-05-23 16:49:46 -04:00
Matt Brown
7354ec9903 Fix #5298 - improve handling of method that may write properties 2021-05-23 16:22:52 -04:00
Matt Brown
4f9067f5c8 Fix unused properties in Psalm’s own codebase 2021-05-21 09:15:23 -04:00
Bruce Weirdan
f5a58adcac
Prefer @psalm-template over @phpstan-template (#5713)
* Prefer `@psalm-template` over `@phpstan-template`

Fixes vimeo/psalm#5590

* Prefer `@psalm` templates for methods as well
2021-05-05 21:47:01 -04:00
Bruce Weirdan
27ea40eda0
Fix notice for certain invalid docblocks (#5709)
Fixes vimeo/psalm#5680
2021-05-03 22:28:17 -04:00
Matthew Brown
832a190dd4
Support enums (#5699)
* Add initial enum preparation

* Support cases method

* Ignore bad use error

cc @weirdan

* Fix type
2021-05-03 17:54:09 -04:00
Bruce Weirdan
105c6f3a1c
Remove (and prevent) unused uses (#5704)
* Updates `slevomat/coding-standard`
* Removes unused uses
* Prevents unused uses
* Fixes a number of symbol case mismatches
2021-05-03 17:22:15 -04:00
Vincent Langlet
39e61ae942
Add support for phpstan import-type and type annotations (#5648)
* Add support for phpstan import-type and type annotations

* Add test

* Fix cs
2021-04-19 22:56:08 -04:00
Matt Brown
012dafad79 Fix #5383 - prevent unsound use of new static for generics 2021-04-10 13:16:19 -04:00
AndrolGenhald
9a03598a6d
Improve type resolution of class constants. (#5591)
Handle array plus operator (fixes #5588).
Handle array spread operator.
Improve string concatenation to resolve to literal instead of unknown string.

I feel like it should be possible to let ConstantTypeResolver take advantage of
the better type analysis in ArrayAnalyzer, ConcatAnalyzer, etc, but it would
require a restructuring that's beyond me for the time being.
2021-04-07 21:56:35 -04:00
Bruce Weirdan
6bd7f5b867
Forbid template annotation on closures (#5499)
They don't work properly anyway.

Fixes vimeo/psalm#5472
2021-03-29 15:10:04 -04:00
Matt Brown
a96645d2e3 Fix many uses of offsets 2021-03-23 01:30:51 -04:00
Bruce Weirdan
65f0fb0288
Allow multiple version-dependent method stubs (#5337)
Fixed vimeo/psalm#4836
2021-03-06 17:18:51 -05:00
Matt Brown
c97ee5ccdb Fix #5258 - allow ReflectionParameeter::hasType() to inform getType() return 2021-03-06 16:54:23 -05:00
Matt Brown
ca331f5afa Consolidate assertion sanitisation 2021-03-06 16:43:11 -05:00
Matt Brown
ad82c93edb Fix #5297 - be more sensitive to additions and deletions in language server mode 2021-02-28 01:36:06 -05:00
Joe Hoyle
e59670ef68
Add documentation to LSP (#5267)
* Add documention to LSP

Add descriptions for all Classes, Functions, Methods, Class Constants for LSP methods for Hover, SignatureInformation and Completions

* Descriptions for class name completions

* PHPCS

* Fix docblock being overriden

* Remove trailing comma in args

* Add description to function param before early `continue`

* Update php-language-server-protocol to 1.5

* Break up long array docblocks

* Break up docblock onto newline

Co-authored-by: Matthew Brown <github@muglug.com>
2021-02-24 10:14:04 -05:00
Matt Brown
3106635953 Fix inference of conditional types when wildcard constant given 2021-02-20 12:21:52 -05:00
Matt Brown
e93e532e4e Fix #5239 - make replacement work in 7.1-7.3 2021-02-17 16:54:11 -05:00
Matt Brown
9d6d3916da Revert "Prevent TypeParseException when dealing with nested template in assertion"
This reverts commit 196f24aac3.
2021-02-17 09:46:54 -05:00
Matt Brown
196f24aac3 Prevent TypeParseException when dealing with nested template in assertion 2021-02-16 20:06:15 -05:00
Matt Brown
77feecb370 Apply the partial diff hack earlier 2021-02-15 15:32:35 -05:00
Matt Brown
86ba3b02f6 Improve documentation further 2021-02-15 11:40:45 -05:00
Matt Brown
472fbf790b Update comment 2021-02-15 11:33:56 -05:00
Matt Brown
a115d311b6 Fix small things 2021-02-15 11:31:34 -05:00
Matt Brown
bfe8bf523c Add slash 2021-02-15 11:13:50 -05:00
Matt Brown
e60c333f2d Fix completion of Foo:: before an if statement 2021-02-15 11:12:04 -05:00
Matt Brown
6b53e79505 When there’s an irrecoverqable syntax error invalidate all issues in the file 2021-02-14 21:16:12 -05:00
Leighton Thomas
e476625c1e
Allow @psalm-type and @psalm-import-type to be used in extends/implements (#5205)
* Fix #4240 - allow type aliases to be used as type parameters

* Fix issues that phpcs found

* Fix #4240 - stop type aliases being everywhere in the same file

* Fix #4240- re-add stuff that was deleted unnecessarily
2021-02-12 17:02:24 -05:00
Barney Laurance
0cd5442c47
Enforce property type invariance (#5131)
* Implement NonInvariantChildProperty detection

See https://github.com/vimeo/psalm/issues/4184

* Delete test cases with 'parentSetsWiderTypeInConstructor'

As I understand it these are not valid test cases. They
emit NonInvariantPropertyType issues which seems correct - the property
type variation is I think a latent bug in the sample code.

* Reduce shortcode for NonInvariantPropertyType to 1+max used shortcode on master
2021-01-31 11:32:24 -05:00
Matt Brown
0624098865 Ensure getId() output can always be parsed as a type
Ref #5105
2021-01-25 23:41:51 -05:00
Matt Brown
4378bec917 Fix #5025 - prevent crash in assert function during reflection 2021-01-17 12:08:19 -05:00
Matt Brown
4faa6bb320 Fix #4976 - improve type narrowing 2021-01-11 17:14:23 -05:00
Matt Brown
951afcf4af Fix #4982 - ensure destructuring assignments are seen inside a loop 2021-01-11 12:46:02 -05:00
Bruce Weirdan
c1a710999c
Skip conditional includes when registering autoload files (#4967)
This should allow analysis of forward-compatible polyfills used in
codebases targeting older PHP versions.

The following previously problematic polyfills should now emit no parse
errors:

* `symfony/polyfill-ctype`
* `symfony/polyfill-intl-grapheme`
* `symfony/polyfill-intl-normalizer`
* `symfony/polyfill-mbstring`

The pattern that is now works as intended looks like this:
```php
if (\PHP_VERSION_ID >= 80000) {
    require __DIR__ . '/bootstrap80.php';
    return;
}
```

Previously Psalm would scan the required file even when codebase
targeted older PHP versions, and would emit parse errors when that file
contained PHP 8 syntax.

Fixes #4961 and #4965
2021-01-09 16:14:58 -05:00