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

310 Commits

Author SHA1 Message Date
Bruce Weirdan
89ff4282df
Allow assertions on static class properties ()
* 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 - 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 
2020-12-10 00:15:37 -05:00
Jack Bentley
7fe8e5a1cf
Fix functions being resolved to other functions ()
Fixes  

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 - 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 () 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 ()
* 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 
2020-11-27 11:43:30 -05:00
Matt Brown
af008953a8 Fix - 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 - ensure promoted properties are not treated as uninitialized 2020-11-22 00:32:02 -05:00
orklah
ae0486529e
Unused psalm-suppress () 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 ()
* 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 - 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 
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 - any class with a __toString method in PHP8 assumed to implement Stringable 2020-10-27 15:41:04 -04:00
Matt Brown
d27d86a84c Fix - be aware of nested template params 2020-10-27 10:01:17 -04:00
Matt Brown
b91370e4ae Fix - 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  - 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 - fix issues with property promotion 2020-10-21 14:41:15 -04:00
Niclas van Eyk
0261024aa6
Initial proposal for psalm-require-{extends, implements} ()
* 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 () 2020-10-17 12:36:44 -04:00
orklah
ffe7874906
Misc improvements ()
* 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 - don’t get tripped up on try with no catches 2020-10-15 10:15:55 -04:00
orklah
62e79fb7ea
param types () 2020-10-12 15:46:47 -04:00
orklah
10f2966dcb
return types ()
* 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 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 - 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 () 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 - always detect missing property types 2020-09-13 16:50:50 -04:00
Bruce Weirdan
cd110c7e2f
Added @psalm-stub-override for classlikes and methods ()
Fixes 
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 () 2020-09-13 16:39:06 -04:00
orklah
ead107fa9e
More return types ()
* add native return types

* redundant phpdoc
2020-09-12 11:24:05 -04:00
Brown
02a58f787b Fix - add Closure to scanned classes when arrow function is seen 2020-09-07 11:11:01 -04:00
orklah
8c7423505a
add native param types ()
* 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 - improve understanding of preg_match_all 2020-09-04 18:10:14 -04:00
orklah
f66d57f19d
add native return types ()
* add native return types

* remove redundant phpdoc
2020-09-04 16:26:33 -04:00
orklah
73f6fcde48
Short list syntax ()
* 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 - allow @psalm-type to reference imported type right above 2020-08-18 09:34:07 -04:00
Bruce Weirdan
7adc25c421
Improve import errors ()
* Better errors for invalid type imports

Fixes 

* Finishing touches

Docs, schema, CS

* Drop unused import

* Drop more unused imports
2020-08-16 22:53:53 -04:00
Matthew Brown
ec2178d14a Fix - 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 - treat autoloaded constants better 2020-08-13 09:14:27 -04:00
Brown
42c3a703b5 Fix - detect scalar class constants in if-true assertions 2020-08-12 17:03:41 -04:00
m0003r
e81593f359
Localize types on magic properties ()
* Fix  - 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 - prevent unsafe use of new static 2020-08-05 19:39:27 -04:00
Daniel Melchior
fa73c7c9d9
Fix - allow multiple mixins () 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 
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 - support aliasing final methods 2020-07-26 14:46:52 -04:00
Barney Laurance
ff432ff73d
Simplify error messages and implementation for internal errors ()
* 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 ()
* 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 ()
* 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 ()
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 - 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 () 2020-06-13 00:29:59 -04:00
Brown
a6c0991073 Fix - expand type alias types recursively 2020-06-07 12:01:04 -04:00
Brown
4d149de764 Fix - 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 
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 
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 
2020-05-25 00:19:52 -04:00
Matthew Brown
15e753e279 Fix - 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 - 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
Brown
013467dc0e Add reference to ensure proper hydration 2020-05-15 00:31:55 -04:00
Brown
2d92943625 Add support for expansion of type aliases 2020-05-15 00:15:48 -04:00
Brown
48504aa88c Pass through typa aliases where appropriate 2020-05-14 00:48:58 -04:00
Brown
006c6e09f1 Add more details to type alias creation 2020-05-14 00:41:50 -04:00
Brown
190c9ce27e Use TypeAlias object to allow future extension 2020-05-13 19:29:59 -04:00
Brown
0fc3398631 Move parsing methods into internal namespace 2020-05-13 19:12:45 -04:00
Brown
28349c6423 Remove mixin_fqcln hack 2020-05-10 09:04:30 -04:00
Brown
65b4263315 Fix - add final flag to pseudo methods where appropriate 2020-05-08 07:28:12 -04:00
Brown
4295f9525f Fix - add check for very specific pattern 2020-05-07 12:30:15 -04:00
Matthew Brown
dc64d4b1ca Support evaluation of boolean conditionals in scanning stage
Fixes 
2020-05-03 10:44:00 -04:00
Matthew Brown
23b0a18632 Fix property type 2020-05-03 10:22:52 -04:00
Matthew Brown
b69c37acdf Simplify logic around evaluating expressions a little 2020-05-03 10:19:15 -04:00
feek
c5319fc379
fix: mixin parameter of self should be properly resolved ()
Co-authored-by: Matthew Brown <github@muglug.com>
2020-05-02 14:32:43 -04:00
Brown
07e5250292 Fix - add support for func_num_args() in conditional type 2020-05-01 16:02:53 -04:00
Brown
f0487c216d Add slash 2020-04-27 09:50:27 -04:00
Brown
95dbb93732 Fix - allow mixin to reference generic params 2020-04-27 09:10:24 -04:00
Brown
d88c31f461 Support templated @mixin 2020-04-26 16:49:52 -04:00
Brown
6b42efed3f Fix - only inherit docblock return when same type is returned 2020-04-20 09:22:58 -04:00
Brown
7af771a006 Fix - resolve array access in constant properly 2020-04-18 12:39:00 -04:00
Brown
61f5a06a7b Fix - always scan @mixin classes 2020-04-18 11:57:25 -04:00
Brown
5ef82b53f6 Fix - support nested templates in class definitions 2020-04-17 01:16:15 -04:00
Brown
1309eece2e At the very least interpret nested templates as templates 2020-04-17 00:56:11 -04:00
Brown
c733d6d373 Only perform assertions where the property type is known
cc @m0003r
2020-04-12 12:56:33 -04:00
m0003r
77270dc9b7
Getters automagic ()
* When method is a plain getter: (1) correct method return type if property type is known (2) auto assert-if-true that corresponding property is not falsy

* do not use getter automagic if getter is overridden somewhere
2020-04-12 08:40:24 -04:00
Brown
1bf1a6e46b Accept partial match of template type 2020-04-04 17:14:33 -04:00
Brown
4aae4fc631 Add slash 2020-04-04 11:16:26 -04:00
Brown
b73b75f1a1 Allow newlines in shortcut version of return type provider 2020-04-04 11:04:00 -04:00
Brown
989269a6f6 Ignore issue 2020-04-04 09:39:39 -04:00
Brown
56cc5fb611 Allow shortcut for specifying conditional template types 2020-04-04 09:31:12 -04:00
Brown
af4a7cabe9 Fix and add support for @psalm-yield annotation 2020-04-02 22:38:10 -04:00
Brown
72104a52ad Improve file invalidation when using --diff mode 2020-04-02 17:18:04 -04:00
Matthew Brown
93735712f0 Fix - always replay docblock issues when analysing files 2020-03-28 19:54:55 -04:00
Matthew Brown
de6aee32d1 Fix - improve templating for property assignments 2020-03-28 17:18:21 -04:00
iggyvolz
94b246b987
Initial commit () 2020-03-24 18:32:57 -04:00
Matthew Brown
43189b3d55 Allow types to be traversed 2020-03-14 23:54:51 -04:00