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
orklah
0e17a3354f
add stubs for standard iterators ( #4725 )
...
* add stubs for standard iterators
* Apply suggestions from code review cc @weirdan
Co-authored-by: Bruce Weirdan <weirdan@gmail.com>
* complete stub + delete code made redundant by stubs + fix some syntax in stubs
* fix parse error
Co-authored-by: Bruce Weirdan <weirdan@gmail.com>
2021-01-07 10:07:07 -05:00
orklah
f9fccb2b2d
implement DTO for plugins ( #4881 )
...
* implement DTO for plugins
* introduce EventHandler + reintroduce legacy API for plugins
2021-01-06 09:05:53 -05:00
Matthew Brown
630f646bd4
Break out large chunk
2021-01-05 17:47:15 -05:00
Bruce Weirdan
89ff4282df
Allow assertions on static class properties ( #4833 )
...
* Minimal implementation for assertions on static properties
* Added inheritance tests
* Add support for `ClassName::$var`
* Import strpos() to keep phpcs happy
* Add support for conditional assertions on static properties
2020-12-21 17:05:44 +00:00
Matt Brown
add536760f
Fix phpcs
2020-12-16 12:12:26 -05:00
Matt Brown
f9f82f1da6
Fix #4851 - use better methhod for determining incorrect stub docblocks
2020-12-16 07:31:28 -05:00
Matt Brown
e6dad6e65f
Be smarter when choosing inherited param types
...
Ref #4803
2020-12-10 00:15:37 -05:00
Jack Bentley
7fe8e5a1cf
Fix functions being resolved to other functions ( #4793 )
...
Fixes #4750
Reusing the $function_id variable causes an incorrect global function to be added at line 654
2020-12-06 17:28:19 -05:00
Matt Brown
1a5d5e4476
Simplify FunctionLikeDocblockScanner
2020-12-03 00:19:01 -05:00
Matt Brown
db8a3ab846
Fix #4751 - allow MethodSignatureMismatch to be overridable when info comes from docblock
2020-12-02 15:13:28 -05:00
Matt Brown
1a629ccc82
Fix a few issues
2020-12-01 18:26:15 -05:00
orklah
a760a2418a
support shift and bitwise operations in constants ( #4740 )
2020-11-29 21:43:49 -05:00
Matt Brown
15a5bd5e29
Simplify storage and retrieval of extended template params
2020-11-29 15:05:32 -05:00
orklah
f19cac6ecf
add annotation @psalm-param-out ( #4717 )
...
* add annotation @psalm-param-out
* add tag in documentation
2020-11-27 17:05:26 -05:00
Matt Brown
5f065d3d74
Turn template bound tuples into object
...
Ref #4714
2020-11-27 11:43:30 -05:00
Matt Brown
af008953a8
Fix #4661 - support conditional escaping for functions
2020-11-22 13:24:33 -05:00
Matt Brown
bd612c476c
Break apart large function
2020-11-22 13:24:33 -05:00
Matt Brown
1fc1cae1d5
Fix #4615 - ensure promoted properties are not treated as uninitialized
2020-11-22 00:32:02 -05:00
orklah
ae0486529e
Unused psalm-suppress ( #4646 )
2020-11-21 17:39:40 -05:00
Matt Brown
42802e11d1
Allow PHP major version to determine substr return type
2020-11-16 16:31:33 -05:00
Adrien LUCAS
4cb8e86737
Add a proxy
capability to the flow annotation ( #4495 )
...
* Add a `passthru` capability to the flow annotation
* Fix passthru-calls type
* Fix types and rename to proxy
* Allow to proxy a method
Co-authored-by: Matthew Brown <github@muglug.com>
2020-11-09 15:22:35 -05:00
Matt Brown
6acd667e55
Fix #4509 - treat expression-derived constants as mixed
2020-11-08 15:36:38 -05:00
Matt Brown
b3ff107c20
Add functions
2020-11-04 23:34:38 -05:00
Matt Brown
3bde327f1b
Break up CommentAnalyzer
2020-11-04 23:25:08 -05:00
Matt Brown
b35db3e523
Reorganise things a little
2020-11-03 16:15:54 -05:00
Matt Brown
957a554c4b
Support a bunch of attributes
2020-10-30 21:38:27 -04:00
Matt Brown
938cebc9f8
Use better inference for getAttributes return type
...
Fixes #4367
2020-10-30 17:37:16 -04:00
Matt Brown
82f35c1454
Ensure Stringable is always available to tests that need it
2020-10-29 19:41:10 -04:00
Matt Brown
fee5eab671
If interface implements __toString it’s also Stringable
2020-10-28 09:06:52 -04:00
Matt Brown
d00a02a06b
Fix #4429 - any class with a __toString method in PHP8 assumed to implement Stringable
2020-10-27 15:41:04 -04:00
Matt Brown
d27d86a84c
Fix #4422 - be aware of nested template params
2020-10-27 10:01:17 -04:00
Matt Brown
b91370e4ae
Fix #4407 - always scan types in @var docblocks regardless of next element
2020-10-26 12:35:29 -04:00
Matt Brown
f8eee22f77
Add basic support for PHP attributes
...
Ref #4367 - supports creation and argument checks
2020-10-24 00:10:22 -04:00
Matt Brown
f3cc7a7f2f
Break apart ReflectorVisitor
2020-10-23 19:53:04 -04:00
Matt Brown
6e262ca753
Add slash
2020-10-22 18:30:36 -04:00
Matt Brown
1c836ad2fb
Invalidate signature types when use changes
2020-10-22 18:07:27 -04:00
Matt Brown
ad5a8c247b
Fix #4386 - fix issues with property promotion
2020-10-21 14:41:15 -04:00
Niclas van Eyk
0261024aa6
Initial proposal for psalm-require-{extends, implements} ( #4361 )
...
* initial implementation of psalm-require-extends
* Added @psalm-require-implements
* Added shortcode for ExtensionRequirementViolation
* Docs & cofig entries for @pasalm-require-{implements,extends}
* Added requirement violations to issues.md
2020-10-19 15:08:18 -04:00
orklah
ceaaa39ec3
improve phpdoc ( #4352 )
2020-10-17 12:36:44 -04:00
orklah
ffe7874906
Misc improvements ( #4314 )
...
* extract the operation out of the loop when possible
* remove unnecessary interfaces when already inherited in parent
* simplify expressions
* avoid using alias functions
* redundant phpdoc
* unused imports
2020-10-15 13:23:35 -04:00
Matt Brown
8d2e88ef41
Fix #4333 - don’t get tripped up on try with no catches
2020-10-15 10:15:55 -04:00
orklah
62e79fb7ea
param types ( #4313 )
2020-10-12 15:46:47 -04:00
orklah
10f2966dcb
return types ( #4311 )
...
* return types
* remove willReturn for void methods
2020-10-12 15:02:52 -04:00
Matt Brown
fb604bfacb
4.x - move class constants into their own storage object
2020-10-05 09:50:32 -04:00
Matt Brown
127e66df65
Elevate trait mismatch issues in PHP 8.0
2020-10-03 22:59:43 -04:00
Matt Brown
2cd306b75c
Promoted properties are always initialized
2020-10-02 19:44:58 -04:00
Matt Brown
211553c53f
Support property type promotion ref #4089
2020-10-02 18:31:32 -04:00
Matt Brown
6866e443dc
Small refactor
2020-10-02 18:24:46 -04:00
Matt Brown
6ad5e1c013
Fix #4264 - prevent crash when analysing file with duplicate classes
2020-10-01 15:07:25 -04:00
Matt Brown
14efde286f
4.x - refactor unused variable detection
...
This turns unused variable detection into an explicit control-flow problem, where before we had a more simplistic mark-and-sweep algorithm
2020-09-30 12:28:13 -04:00
orklah
cb7065ae07
replace deprecated methods with their equivalent ( #4217 )
2020-09-20 08:56:49 -04:00
Brown
1ac527bbf1
Meke staticy methods properly static
2020-09-19 18:24:36 -04:00
Brown
17a0ecb60e
Fix regression – detect unused params with defaults again
2020-09-14 10:58:36 -04:00
Brown
f180fb23bc
Fix #4178 - always detect missing property types
2020-09-13 16:50:50 -04:00
Bruce Weirdan
cd110c7e2f
Added @psalm-stub-override
for classlikes and methods ( #4177 )
...
Fixes vimeo/psalm#1252
2020-09-13 16:40:31 -04:00
orklah
da47588f91
replace return;
by return null;
in every non-void method, add return null;
when mising, add return types, remove redundant phpdoc ( #4176 )
2020-09-13 16:39:06 -04:00
orklah
ead107fa9e
More return types ( #4173 )
...
* add native return types
* redundant phpdoc
2020-09-12 11:24:05 -04:00
Brown
02a58f787b
Fix #4148 - add Closure to scanned classes when arrow function is seen
2020-09-07 11:11:01 -04:00
orklah
8c7423505a
add native param types ( #4137 )
...
* add native param types
* redundant phpdoc
* add more param types and adds "?" to nullable types
* remove redundant phpdoc
* add more param types and remove redundant phpdoc
* add more param types and remove redundant phpdoc
2020-09-06 19:36:47 -04:00
Matthew Brown
422271b2cf
Prevent variables named "haystack" from receiving literal strings
...
cc @staabm
2020-09-05 00:35:48 -04:00
Brown
4d82d3ddad
Fix #4128 - improve understanding of preg_match_all
2020-09-04 18:10:14 -04:00
orklah
f66d57f19d
add native return types ( #4116 )
...
* add native return types
* remove redundant phpdoc
2020-09-04 16:26:33 -04:00
orklah
73f6fcde48
Short list syntax ( #4102 )
...
* Short list syntax
* revert unrelated CS
2020-09-02 00:17:41 -04:00
Brown
548ac1129c
Fix crash with @var
over echo
2020-09-01 00:12:12 -04:00
Brown
99d6af0f9a
Support static return type
2020-08-30 13:32:42 -04:00
Brown
f34e54ec41
Support PHP 8 union types
2020-08-30 13:16:37 -04:00
Brown
92239add4d
Add some backwards-incompatible changes for 4.x
2020-08-30 11:44:14 -04:00
Brown
988e17f11d
Make clause fully immutable
2020-08-26 15:35:29 -04:00
Brown
ba1ff21af4
Add a couple more pure annotations
2020-08-23 18:53:34 -04:00
Olle
3630b4a2f9
Merge remote-tracking branch 'remotes/upstream/master'
2020-08-18 15:59:46 +00:00
Brown
1468a28273
Fix #3999 - allow @psalm-type to reference imported type right above
2020-08-18 09:34:07 -04:00
Bruce Weirdan
7adc25c421
Improve import errors ( #3997 )
...
* Better errors for invalid type imports
Fixes vimeo/psalm#3885
* Finishing touches
Docs, schema, CS
* Drop unused import
* Drop more unused imports
2020-08-16 22:53:53 -04:00
Matthew Brown
ec2178d14a
Fix #3927 - prevent crash with bad type ref
2020-08-16 12:43:46 -04:00
Matthew Brown
8731b10bc6
Use older method
2020-08-15 10:31:24 -04:00
Brown
cdef4ec351
Alter docblock params too
2020-08-14 16:26:55 -04:00
Brown
dbcf154036
Add fixer for mismatching param names
2020-08-14 15:25:21 -04:00
Matthew Brown
72ecb57def
Improve names of things
2020-08-14 00:27:33 -04:00
Brown
209d17c868
Fix #2891 - treat autoloaded constants better
2020-08-13 09:14:27 -04:00
Brown
42c3a703b5
Fix #3741 - detect scalar class constants in if-true assertions
2020-08-12 17:03:41 -04:00
m0003r
e81593f359
Localize types on magic properties ( #3971 )
...
* Fix #3949 - localize types on magic properties
* fix failing tests
* fix code style
Co-authored-by: m03r <m03r@m03r.net>
2020-08-10 12:45:21 -04:00
Matthew Brown
6085e42fc1
Detect mismatching param names effectively
2020-08-10 09:58:43 -04:00
Matthew Brown
50cc3a8afa
Align paramter names
2020-08-09 23:19:59 -04:00
Brown
bcf0df4170
Fix a bug with lowercase-string unions
2020-08-05 20:05:57 -04:00
Brown
488a899823
Fix Psalm issues
2020-08-05 19:49:09 -04:00
Brown
c0b0036109
Fix #3934 - prevent unsafe use of new static
2020-08-05 19:39:27 -04:00
Daniel Melchior
fa73c7c9d9
Fix #3757 - allow multiple mixins ( #3772 )
2020-08-05 15:49:19 -04:00
Brown
20a9b103ec
Restrict narrowing fix
2020-08-03 02:20:58 -04:00
Brown
6919e88423
Add performance logging under a --debug-performance flag
2020-07-30 15:30:19 -04:00
Brown
7367e8e6c2
Allow assertions of non-empty lists on typed lists
...
Fixes #3906
2020-07-29 18:10:43 -04:00
Brown
8c5e4edab0
Fix extra test
2020-07-26 15:50:07 -04:00
Brown
657f9db2e0
Fix bugs
2020-07-26 15:21:05 -04:00
Brown
23f5d66516
Fix #3897 - support aliasing final methods
2020-07-26 14:46:52 -04:00
Barney Laurance
ff432ff73d
Simplify error messages and implementation for internal errors ( #3881 )
...
* Use more consistent language for Internal errors
There's no meaningful distinction between something being internal and
being 'marked as internal'.
* Rename property psalm_internal to internal in all storage classes
This property holds metadata that can be set using either @internal
or @psalm-internal in docblocks
* Change types of internal properties in storage from ?string to string
Simpler type is easier to handle. Non-internal methods can be considered
to be internal to the entire universe of PHP code, i.e. that code whose
namespace starts with the empty string. It's not a special case.
2020-07-24 09:32:54 -04:00
Barney Laurance
3bc91b9944
Fix multiple issues with @internal and @psalm-internal ( #3841 )
...
* Add passing tests for property fetch on an @internal class
I'm trying to work out why the equivilent InvalidCodeParse test is
failing for PsalmInternal
* Treat all properties of a psalm-internal class as psalm-internal
* Remove all $internal properties from storage - use psalm_internal instead
@internal can be represented as internal to the namespace root, avoiding
the need to check for both properties in storage later.
* Raise InternalClass issue when an internal class is used with e.g. instanceOf
* fix docs and tests
* Add return type declartion to code example in doc
* Don't allow class psalm-internal to overide a tighter method psalm-internal
* Break up long line
* Code style - move && from EOL to SOL
* Restore misplaced &&
* Fix code style
* Fix namespace fetching so it works
Co-authored-by: Matthew Brown <github@muglug.com>
2020-07-22 19:27:35 -04:00
Brown
76bd5b6278
Refactor type comparison
2020-07-21 19:40:35 -04:00
Brown
5392ae0b39
Fix UnusedMethodCall examples
2020-07-16 18:14:15 -04:00
Brown
262bb9fd89
Invalidate memoized getter method results after property assignment
2020-07-16 12:59:49 -04:00
Brown
b361b44889
Rip out plain getter property logic cc @m0003r
...
It gets in the way of the other IMO more useful memoisation logic (e.g. when a getter is declared final)
2020-07-16 12:42:59 -04:00
Olle
285348efe9
New annotation: @psalm-if-this-is
2020-07-08 19:51:02 +00:00
Olle Härstedt
d8e8ce428e
Add new annotation: @psalm-self-out ( #3650 )
...
* Add new config: sealAllMethods
* Add some more tests
* Fix codesniffer issue with preg_quote
* Fix missing method in test
* New tag @self-out (WIP)
* Add self_out_type to method storage
* Add some notes
* More work on self-out (WIP)
* More work on self-out (WIP)
* Use psalm-self-out instead of self-out
* Remove extra file
* Cleanup
* Wrap around try-catch - how to check if a method has/should have storage?
* New method hasStorage()
* Fix indentation
* Fix some errors
* Fix indentation
* Cast storage type to type
* Add proper use-statement in method storage
* Correct test class name
* Allow self_out to be null
* method_id can be string (why, when?)
Co-authored-by: Olle <noemail>
2020-07-01 18:10:24 -04:00
Olle
290207dd3f
Merge remote-tracking branch 'upstream/master'
2020-06-30 17:01:56 +00:00
Olle
111f4b4f6e
Add proper use-statement in method storage
2020-06-30 15:33:14 +00:00
Barney Laurance
3f8aa64ee9
Treat methods of internal or psalm internal classes as internal ( #3698 )
...
When both the method and the class are annotated as psalm-internal,
but to different namespaces, we consider the method internal to
whichever namespace is longer, i.e. the smaller code module.
Issue reported at https://github.com/vimeo/psalm/issues/3457
2020-06-28 13:15:54 -04:00
Brown
de85e7c539
Fix blips
2020-06-24 13:19:14 -04:00
Brown
c29b3744ec
Change storage of out types
2020-06-24 11:51:31 -04:00
Olle
79d2e25084
Merge remote-tracking branch 'upstream/master'
2020-06-23 17:08:12 +00:00
Brown
e8be2c500e
Support taint flows in more functions
2020-06-22 17:53:03 -04:00
Olle
fffbccdacb
More work on self-out (WIP)
2020-06-21 22:18:14 +00:00
Brown
dc83c2e2fc
Add annotation for taint sources
2020-06-21 00:58:56 -04:00
Brown
8f2e28c36b
Improve tainting of specializable classes
2020-06-19 01:22:51 -04:00
Olle
9d284f1331
Add self_out_type to method storage
2020-06-18 21:55:43 +00:00
Olle
20cde0ca2c
New tag @self-out (WIP)
2020-06-18 20:46:49 +00:00
Matthew Brown
081a284759
Fix #3567 - remember which variables a callable sets byref in use
2020-06-14 11:58:50 -04:00
Andrei Petre
3497ca07b6
Extending final class is prohibited #3037 ( #3576 )
2020-06-13 00:29:59 -04:00
Brown
a6c0991073
Fix #3532 - expand type alias types recursively
2020-06-07 12:01:04 -04:00
Brown
4d149de764
Fix #3506 - prevent black classes in throws check
2020-06-01 14:56:27 -04:00
Brown
30907f0269
Clean up comment parsing
2020-05-28 22:14:41 -04:00
Brown
b9ea115487
Support string class_alias calls with leading backslash
...
Fixes #3465
2020-05-27 08:14:47 -04:00
Brown
d04e21ee5a
Define mixin declaring classname
2020-05-26 23:32:07 -04:00
Brown
b4855b3ecd
Catch errors during yield annotation tokenisation
...
Fixes #3430
2020-05-26 17:57:55 -04:00
Brown
118b700436
Simplify sink mapping for internal calls
2020-05-25 13:10:06 -04:00
Brown
240b2f898c
Add some negative test cases for @mixin
...
Also fix #3452
2020-05-25 00:19:52 -04:00
Matthew Brown
15e753e279
Fix #3443 - add InvalidDocblock issue for @psalm-assert Foo|!Bar
2020-05-23 22:52:21 -04:00
Brown
dc73e25157
Detect taints in include calls
2020-05-22 23:53:37 -04:00
Brown
1b84fc2c12
Fix #3419 - don’t add null to return type when template/conditional return is used
2020-05-22 12:44:19 -04:00
Matthew Brown
187b944680
Add faster taint analysis
2020-05-22 12:33:29 -04:00
Brown
0b2da18f1e
Break up StatementsAnalyzer
2020-05-19 12:56:30 -04:00
Brown
5ee1487a01
Make ExpressionAnalyzer more beautiful
2020-05-18 15:13:27 -04:00