1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 17:27:28 +01:00
Commit Graph

1569 Commits

Author SHA1 Message Date
Matthew Brown
66dd794101 Add return function 2020-03-31 22:26:48 -04:00
Brown
4ef7cb50a5 Make Psalm faster when there aren’t any changes whatsoever 2020-03-31 22:22:34 -04:00
Brown
da729cfbc6 Don’t check params when mutations are being collected 2020-03-31 15:49:43 -04:00
Matthew Brown
b46e147735 Add some limits on switch case assertion calculation
Ref #2728
2020-03-30 00:20:00 -04:00
Matthew Brown
1b88316c51 Convert method from recursive to inline 2020-03-29 19:42:22 -04:00
Matthew Brown
82197f1761 Add many slashes 2020-03-29 15:56:45 -04:00
Matthew Brown
ce3532490c Add profiling for analysing slow methods 2020-03-29 15:42:00 -04:00
Matthew Brown
194f02507d Allow conditional types to reference class constants 2020-03-29 13:37:37 -04:00
Matthew Brown
1b2017e4f4 Add slash 2020-03-29 10:44:38 -04:00
Matthew Brown
5ad55ae693 Fix type inference on simple conditional function calls 2020-03-29 10:42:57 -04:00
Matthew Brown
0e919a0696 Allow arithmetic on simple templated types 2020-03-29 10:34:46 -04:00
Matthew Brown
788da0680e Allow var_export userland implementation 2020-03-29 10:19:09 -04:00
Matthew Brown
7fdccc0439 Fix #3014 - change constant class access rules 2020-03-29 09:47:29 -04:00
Matthew Brown
e85d22f004 Fix #3033 - allow __invoke on unions with non-objects 2020-03-28 23:41:05 -04:00
Matthew Brown
5395183837 Use more accurate means of determining whether function did return 2020-03-28 23:37:42 -04:00
Matthew Brown
7195ea6842 Fix #3030 - don’t suggest return types can do more 2020-03-28 23:15:54 -04:00
Matthew Brown
93735712f0 Fix #3032 - always replay docblock issues when analysing files 2020-03-28 19:54:55 -04:00
Matthew Brown
86a89b2d27 Fix #3034 - expand out while expressions for more accurate variable initialisation 2020-03-28 18:22:08 -04:00
Matthew Brown
de6aee32d1 Fix #3035 - improve templating for property assignments 2020-03-28 17:18:21 -04:00
Matthew Brown
47c1470e3b Refactor reference checks to use more appropriate properties 2020-03-28 16:30:56 -04:00
Brown
cc548a45fa Improve detection of unused classes 2020-03-28 14:45:58 -04:00
Brown
60613462fe Improve static resolution a little more 2020-03-28 08:14:35 -04:00
Brown
5835c34a29 Expand out static extra types 2020-03-28 00:08:31 -04:00
Brown
e3ff856cac Improve treatment of static in intersection 2020-03-27 19:17:44 -04:00
Brown
5cb1538448 Don’t add unnecessary taints 2020-03-27 19:09:15 -04:00
Brown
056f4aaac6 Fix #3027 - inherited properties should be templated properly 2020-03-27 18:31:48 -04:00
Brown
b57563c8cf Renamed function to be a little better 2020-03-27 18:30:59 -04:00
Tyson Andre
e560858b23
Fix grammar nit in "is can never happen" message (#3025)
Should either be "is impossible" or "can never happen"
2020-03-27 17:32:49 -04:00
Brown
4021114b04 Fix too-long line 2020-03-27 10:43:12 -04:00
Brown
ae31ec6805 Fix resolution of get_called_class 2020-03-27 09:51:53 -04:00
Brown
3253f57c94 Don’t rescan everything when finding unused code 2020-03-27 09:45:54 -04:00
Brown
05f8f30d8c Use more specific type description 2020-03-27 09:45:18 -04:00
Brown
031c5be8e6 Check trait methods better 2020-03-27 00:37:33 -04:00
Brown
53612d0df6 Make --diff imply --diff-methods 2020-03-26 18:14:54 -04:00
Brown
f88c7c1ec5 Fix closure return type inference 2020-03-26 14:38:32 -04:00
Brown
4ced26bec2 Fix #3024 - replay errors in --diff --diff-methods mode 2020-03-26 14:22:06 -04:00
Brown
971ae50bea Do prep work for #3024 - improve handling of absent class references 2020-03-26 12:35:27 -04:00
Matthew Brown
68c95c622a Save information about last runs whether or not there were errors 2020-03-26 00:46:39 -04:00
Matthew Brown
f94ab22a5f Be better about strict inference 2020-03-25 09:18:49 -04:00
Matthew Brown
4734583444 Don’t overwrite already-defined template 2020-03-24 23:40:01 -04:00
Brown
467da32f84 Fix instanceof static and isa (static::class) handling 2020-03-24 18:58:15 -04:00
iggyvolz
94b246b987
Initial commit (#3013) 2020-03-24 18:32:57 -04:00
Brown
a9b6c51748 Improve new $class to make it more static-y 2020-03-24 18:30:08 -04:00
Brown
1bfc61d402 Allow final classes to bypass static checks 2020-03-24 18:14:10 -04:00
Brown
ec34a16291 Warn about invalid static returns 2020-03-24 18:00:20 -04:00
Brown
f6759c3d16 Check return statement types for inherited docblocks 2020-03-24 17:59:48 -04:00
Brown
1e480ade12 Fix bugs 2020-03-24 14:49:05 -04:00
Brown
a7245b4459 Fix bugs 2020-03-23 13:29:00 -04:00
Matthew Brown
27a0651b6c Fix #3009 - make sure return type is set when returning early 2020-03-23 13:25:55 -04:00
Matthew Brown
ce9eef9ed7 Improve returning 2020-03-23 13:25:55 -04:00
Brown
4c081f7835 Things with mixed values can be the same 2020-03-23 12:08:05 -04:00
Matthew Brown
eeed5ecccc Only prevent AbstractMethodCall on direct calls
Fixes #3007
2020-03-23 07:40:30 -04:00
Matthew Brown
6058725256 Add prototype for conditional return type 2020-03-22 10:44:48 -04:00
Matthew Brown
26694345d6 Fix unknown variable 2020-03-21 20:53:46 -04:00
Matthew Brown
6746f1c047 Fix #3004 - reset property types inside a closure defined in a class 2020-03-21 20:46:38 -04:00
Matthew Brown
c986cdf12e Allow edge-case of by-reference assignment with unitiliazed property
Fixes #3003
2020-03-21 19:23:32 -04:00
Matthew Brown
a237ba307c Use simpler method for generating links 2020-03-19 17:12:16 -04:00
Matthew Brown
fa2adfe1b3 Add slashes 2020-03-19 16:35:04 -04:00
Matthew Brown
4e07dfebaa Make link part of IssueData so it’s available to all consumers 2020-03-19 16:22:43 -04:00
Matthew Brown
f532dc316c Add informational links to Psalm‘s output
Fixes #2978
2020-03-19 16:04:40 -04:00
Matthew Brown
f7907eb43f Fix #2987 - ignore MixedReturnTypeCoercion for generator send param 2020-03-18 21:25:25 -04:00
Ben Davies
47f43fdcd7
use file contents intead of filemtime to detect changed files (#2991)
* use file contents intead of filemtime to detect changed files

* Add as extra filter step

Co-authored-by: Matthew Brown <github@muglug.com>
2020-03-18 13:36:11 -04:00
Matthew Brown
474b9dc01b Fix too-long line 2020-03-17 17:44:31 -04:00
Matthew Brown
9cd817077e Improve fix 2020-03-17 17:34:45 -04:00
Matthew Brown
4166e5a4ef Fix tests 2020-03-17 16:30:03 -04:00
Matthew Brown
da170efb65 Don’t coerce literal values
Fixes #2982
2020-03-17 16:16:58 -04:00
Matthew Brown
951b943c38 Fix #2981 - check that class exists before making it a phantom 2020-03-17 15:04:50 -04:00
Matthew Brown
309a229db1 Add codes to all issues 2020-03-17 09:19:47 -04:00
Matthew Brown
a4add37293 Check for variadic functions 2020-03-16 11:46:44 -04:00
Matthew Brown
9556e9ad69 Disable enclosing method/function return type inference
cc @ragboyjr – this makes Psalm unstable, as method return types cannot change midway through analysis (as it means results would be dependent on file analysis order)
2020-03-16 11:45:49 -04:00
Matthew Brown
4232bfb6e6 Fix location 2020-03-15 23:29:52 -04:00
Matthew Brown
6c3ff8f245 Remove unused variable 2020-03-15 23:21:48 -04:00
Matthew Brown
a8a1142889 Fix #2977 - make MixedAssignment message a bit more clear, hopefully 2020-03-15 23:20:12 -04:00
Matthew Brown
c85fa9083d Fix #2915 - prevent "if (true)" and similar 2020-03-15 22:23:31 -04:00
Matthew Brown
b6380ae595 Fix false-positives around unevaluated code 2020-03-15 14:43:05 -04:00
Matthew Brown
6c7f89b0ab Fix #2920 - track unevaluated code after nested returns 2020-03-15 14:31:41 -04:00
Matthew Brown
af9e362c80 Fix indentation 2020-03-15 14:14:53 -04:00
Matthew Brown
73badf59d1 Fix #2925 - ignore null return type for array_replace_recursive 2020-03-15 14:07:55 -04:00
Matthew Brown
3ebb5a1142 Fix #1843 - ignore intersection TooManyArguments issues 2020-03-15 14:01:33 -04:00
Matthew Brown
0022de1f13 Fix #946 - allow too many arguments when one of union agrees 2020-03-15 13:44:00 -04:00
Matthew Brown
0af2eba4b9 Fix #2973 - don’t allow template type through 2020-03-15 11:14:06 -04:00
Matthew Brown
2c0cf4030f Detect assigning collections of mutable objects in immutable
Fixes #2946
2020-03-15 00:21:20 -04:00
Matthew Brown
43189b3d55 Allow types to be traversed 2020-03-14 23:54:51 -04:00
RJ Garcia
2de3e27f10
Initial inferred Closure Returns (#2945)
- Added detection for when we can infer
  closure types from parent fn return types
- Implemented functionality for infering types of
  returned closures
- Added ability to infer type of return from typed
  closures
- Added a new getFunctionLikeStorage method in
  Codebase to support easily getting a function
  despite being a method, closure, or function
- Added some utilities to the MethodIdentifier
  to facilitate creating MethodIdentifier's from
  string method references

Closes #2896

Signed-off-by: RJ Garcia <rj@bighead.net>
2020-03-14 14:51:43 -04:00
Matthew Brown
acac77b3f0 Improve message 2020-03-14 01:19:50 -04:00
Matthew Brown
0aca01faea Improve fix to #2805 2020-03-14 01:09:12 -04:00
Matthew Brown
aba29f0cbf Add slash 2020-03-13 20:28:32 -04:00
Matthew Brown
aaf74f084a Fix #2954 - filter out used vars before checking params 2020-03-13 20:21:49 -04:00
Matthew Brown
54d38e562f Fix #2970 - use correct unreferenced vars when analysing do 2020-03-13 11:41:17 -04:00
Matthew Brown
5210f9b69b Fix #2966 - register constructor use for new $templated_class 2020-03-12 11:42:01 -04:00
Matthew Brown
c6a5781e78 Break apart FunctionCallAnalyzer::analyze method 2020-03-12 11:05:50 -04:00
Matthew Brown
99ca359f8b Break apart large methods 2020-03-12 01:19:11 -04:00
Matthew Brown
96fbcd5a64 Break out more methods 2020-03-11 23:38:49 -04:00
Matthew Brown
329c9afdf5 Actually remove method 2020-03-11 23:20:19 -04:00
Matthew Brown
973703e396 Break out template param collection 2020-03-11 23:15:15 -04:00
Matthew Brown
9732697e45 Break out method call purity checks 2020-03-11 23:09:09 -04:00
Matthew Brown
bfb919d26a Break out methods into their own classes 2020-03-11 23:04:52 -04:00
Matthew Brown
8f28f41399 Improve magic checks 2020-03-11 18:42:41 -04:00
Matthew Brown
950260a041 No erroneous UndefinedMethod when accessing sealed class 2020-03-11 18:27:07 -04:00
Matthew Brown
f128c8ffda Fix overriding of mapped property type visibility 2020-03-11 17:41:05 -04:00
Matthew Brown
43d9361395 Break out more methods 2020-03-11 13:35:33 -04:00
Matthew Brown
89f6866893 Fix magic property test 2020-03-11 12:45:30 -04:00
Matthew Brown
50cddb5350 Break out purity checks 2020-03-11 12:24:25 -04:00
Matthew Brown
c5fa07920c Fix improper property var calculation
Ref #1332
2020-03-11 11:03:27 -04:00
Matthew Brown
ef64e6e8eb Improve abstract call handling 2020-03-11 10:36:39 -04:00
Matthew Brown
27598f508e Fix too-long line 2020-03-11 10:18:53 -04:00
Matthew Brown
0d62fbdf98 Detect erroneous abstract static method calls 2020-03-11 10:18:40 -04:00
Matthew Brown
d2950af636 Break apart MethodCallAnalyzer a bit 2020-03-11 09:38:09 -04:00
Matthew Brown
1dc26afb27 Fix #2958 - prevent overriding final methods 2020-03-10 21:26:02 -04:00
Brown
d1fcbf38ae Fix #2956 - treat Exception::getMessage as final and mutation-free 2020-03-10 15:12:55 -04:00
Brown
0cfe565d0a Fix #2952 - always be cloning 2020-03-09 18:59:56 -04:00
Brown
2a72990d62 Add back support for unused method checks 2020-03-09 18:55:35 -04:00
leightonthomas
60fb3924bc Fix #2914 - falsable functions who only expect true now produce errors 2020-03-09 14:25:18 -04:00
Brown
2c8688dd97 Don’t crash when conditionally defining classes with properties 2020-03-09 14:24:19 -04:00
Brown
04bcc32efb Fix #2940 - fix array offset assignment under ??= 2020-03-09 14:09:41 -04:00
Brown
3c416482ec Fix #2932 - don’t crash when trying to expand callable object-like array 2020-03-09 10:56:37 -04:00
Brown
a0da7356e9 Fix #2935 - make handling of templated properties much less hacky 2020-03-09 09:59:02 -04:00
Brown
40a7a1156f Fix #2930 2020-03-09 09:45:35 -04:00
Matthew Brown
5b7ab6a542 Fix coercion 2020-03-09 01:32:27 -04:00
Matthew Brown
3243819f1b Fix #2941 - allow class-string<self> to be fleshed out 2020-03-09 01:29:16 -04:00
Matthew Brown
5b4ed6b516 Fix #2942 - support array_splice properly for numeric-keyed arrays 2020-03-09 01:15:52 -04:00
Sergey Melesh
a5da866d97 Ignore exceptions already caught by previous catch 2020-03-08 20:19:56 -05:00
Matthew Brown
b999037263 Fix #2928 - properly expand out skipped template inheritance 2020-03-06 19:24:47 -05:00
Matthew Brown
352bd3f5c5 Remove redundant condition 2020-03-06 15:23:11 -05:00
Matthew Brown
766effb0db Improve accuracy of diff generation 2020-03-06 13:48:59 -05:00
Matthew Brown
10b807b4f6 Fix reference generation from methods in --diff mode 2020-03-06 13:02:34 -05:00
Matthew Brown
a2a507166d Fix #2923 - remove hack to fix a template issue 2020-03-06 09:42:23 -05:00
Matthew Brown
51bfc7c619 Only emit mixed issues for MissingClassPropertyType
Fixes #2388
2020-03-06 07:57:00 -05:00
Matthew Brown
7ea06c7b1a Only emit PossiblyUndefinedVariable issue on variables 2020-03-05 23:40:47 -05:00
Matthew Brown
75a3412a42 Downgrade error when using unknown variable in mixed method 2020-03-05 21:24:08 -05:00
Matthew Brown
b2678d40aa Revert "Fix #2909 - don’t treat args of unknown calls as possible by-reference vars"
This reverts commit 105fe012c4.
2020-03-05 21:10:29 -05:00
leightonthomas
06f7df9974 Fix #1799 - support trailing commas in type aliases 2020-03-05 15:36:28 -05:00
Matthew Brown
105fe012c4 Fix #2909 - don’t treat args of unknown calls as possible by-reference vars 2020-03-04 23:49:06 -05:00
Matthew Brown
1615612394 Fix #2910 - prevent ternaries from ever being considered valid reference 2020-03-04 22:30:53 -05:00
Matthew Brown
c0c878cc9d Don’t cache all traits 2020-03-02 22:27:54 -05:00
Matthew Brown
88c4088bc2 Prevent self/static refs outside classes
Fixes #2895
2020-03-01 17:25:55 -05:00
Matthew Brown
f44c3488eb Keep track of which arg a given template was assigned from
Fixes #2900 - We only care about the depth of a templated match when templating from a particular argument. The next argument should essentially start afresh
2020-03-01 12:27:18 -05:00
Matthew Brown
e0d555e203 Allow function names to passed in as strings for callable template resolution 2020-02-29 15:43:45 -05:00
Matthew Brown
2d6cf8a0b0 Get bindable params earlier, before replacing with extended ones 2020-02-27 23:10:26 -05:00
Matthew Brown
abb3800d20 Fix bad template replacement 2020-02-27 23:00:40 -05:00
Matthew Brown
39d6800531 Remove default 2020-02-27 21:54:19 -05:00
Matthew Brown
c565afde64 Fix method call after method_exists check 2020-02-27 21:46:58 -05:00
Matthew Brown
1f19aed31b Fix support for replacing mocked types in own classes 2020-02-27 21:36:03 -05:00
Philip Hofstetter
d315822bfa make skipping of checks after invalid includes configurable
as suggested in the PR it's best to make the setting configurable.

In order not to break existing installations, we default to keeping the
old behaviour, but in a later version of psalm, we might change the
default.
2020-02-27 18:49:23 -05:00
Philip Hofstetter
f2277ebb6d don't disable checks when includes can't be resolved
Any unresolvable include (even suppressed ones) would lead to some
subsequent tests being disabled as a side-effect.

this fixes #2817
2020-02-27 18:49:23 -05:00
Brown
35c1670602 Fix #2875 - treat intersections more similarly than before 2020-02-27 18:42:15 -05:00
Matthew Brown
eeb2858b30 Add additional fix for #2784 2020-02-27 08:56:39 -05:00
Brown
ea0a670230 Flesh out class constants in function call return type
Fixes #2884
2020-02-26 17:28:44 -05:00
Matthew Brown
746f8d4973 Prevent returning named object where template return assumed 2020-02-24 23:14:16 -05:00
Brown
234a6ba4b4 Suppress null check 2020-02-24 16:22:50 -05:00
Brown
ff7fbcda99 Fix #2871 - prevent keyed arrays from being interpreted as callables 2020-02-24 16:19:33 -05:00
Brown
0a8bb32115 Fix #2866 - prevent use of impure __toString via concatenation in pure contexts 2020-02-24 14:50:34 -05:00
Brown
3f226e2e86 Fix #2867 - treat echo as impure 2020-02-24 14:38:05 -05:00
Matthew Brown
f1a9b73a78 Fix message 2020-02-23 18:24:43 -05:00
Matthew Brown
ed4f4e35b8 Fix null checks 2020-02-23 18:20:59 -05:00
Matthew Brown
41e076e0ee Fix bad 2020-02-23 18:19:53 -05:00
Matthew Brown
618ae77846 Prevent implicit __toString method calls in a pure context 2020-02-23 18:18:25 -05:00
Matthew Brown
1abece4f7c Use more accurate types 2020-02-23 17:03:27 -05:00
Matthew Brown
b01bc9ab12 Fix union-of-mixed array key creation 2020-02-22 21:13:14 -05:00
Matthew Brown
4dae5b3190 Prevent more mixed array keys 2020-02-22 20:52:39 -05:00
Matthew Brown
27fd76649c Prevent more array<mixed, ...> construction 2020-02-22 12:20:03 -05:00
Matthew Brown
6ad3d039df Prevent more array<mixed,...> creation 2020-02-22 12:12:40 -05:00
Matthew Brown
952045e2ba Fix return type checks 2020-02-22 11:28:24 -05:00
Matthew Brown
1a3129b0e0 Fix test condition 2020-02-22 10:53:30 -05:00
Matthew Brown
1c218c020e Fix #1684 - detect error in assertion on return type of direct call 2020-02-22 10:41:57 -05:00
Matthew Brown
a706f4d722 Fix #2242 - warn when using mutable dependencies 2020-02-22 10:04:46 -05:00
Matthew Brown
3cc4c2b37e Fix #2721 - only warn about deprecated classes exactly where they are used 2020-02-22 01:12:19 -05:00
Matthew Brown
db17c85dd6 Fix #2787 - make accessing undefined objectlike key an error 2020-02-22 00:29:59 -05:00
Matthew Brown
9f13341ef9 Fix #2827 - detect literal numeric values 2020-02-22 00:16:15 -05:00
Matthew Brown
4707b21227 Fix tests 2020-02-21 22:15:25 -05:00
Brown
7d99a15072 Fix #2805 - forbid passing in mutable class to mutation-free context 2020-02-21 18:25:35 -05:00
Brown
f4485cc529 Fix #2847 - use fully-qualified function name 2020-02-21 16:44:31 -05:00
Brown
ae08552f40 Add null check 2020-02-21 16:04:18 -05:00
Brown
443558ca49 Fix #2844 - resolve constant offset references 2020-02-21 15:56:30 -05:00
Brown
292a2359b3 Add slash 2020-02-21 15:44:26 -05:00
Brown
b51863fc9b Fix #2848 - allow casting templated types 2020-02-21 15:17:35 -05:00
Brown
f44a0f9f4c Fix #2849 - allow object-like templated array comparison 2020-02-21 15:13:07 -05:00
Matthew Brown
aea33824e6 Fix #1555 - allow phantom class constants 2020-02-18 19:46:05 -05:00
Brown
0e23fab5d2 Detect bugs similar to that which caused #2832 2020-02-18 12:53:54 -05:00
Brown
6e8088776d Use better return type for SimpleXMLElement::offsetGet 2020-02-18 10:58:56 -05:00
Matthew Brown
ced092874a Make config generation smarter 2020-02-17 22:05:58 -05:00
Matthew Brown
00afcda5e0 Fix #2824 - allow unpacking of non-arrays with template params 2020-02-17 19:54:11 -05:00
Matthew Brown
3561c7d5dc Make sure yield from expressions counted as used
Fixes #2823
2020-02-17 19:21:04 -05:00
Matthew Brown
cf977c3542 Don’t convert constant descriptions to lowercase 2020-02-17 18:19:33 -05:00
Matthew Brown
8dd49b1cbf Fix lowercase-string to constant string coercion 2020-02-17 17:58:36 -05:00
Matthew Brown
99a97f4085 Update issue levels 2020-02-17 16:32:16 -05:00
Matthew Brown
196a0a5c4e Replace issue data array with object 2020-02-16 18:24:40 -05:00
Matthew Brown
d3bfb96431 Fix #2808 - improve yield type discernment 2020-02-15 10:47:07 -05:00
Matthew Brown
3feccc1f98 Fix tests 2020-02-14 22:24:39 -05:00
Matthew Brown
653353709a Use MethodIdentifier object instead of string 2020-02-14 20:54:26 -05:00
Matthew Brown
422bd25f04
Maybe fix indentation 2020-02-13 19:33:47 -05:00
Matthew Brown
3efe271819
Remove blank line 2020-02-13 18:36:37 -05:00
Matthew Brown
95e1bc0c48
Fix line breaks 2020-02-13 18:32:40 -05:00
Brown
b87161785d Be even more permissive 2020-02-13 17:58:15 -05:00
Brown
210d65d0d6 Add a few lowercase-string types 2020-02-13 17:52:23 -05:00
Brown
bc0ccbda99 Add better inference for lower-cased methods 2020-02-13 17:30:00 -05:00
Brown
1c42875179 Support lowercase-string and warn about unnecessary calls to strtolower 2020-02-13 16:38:58 -05:00
Matthew Brown
305372e0e1 Add docblock return type as --diff dependency 2020-02-13 10:39:04 -05:00
Philip Hofstetter
395cf587d3 add plugin hook to be called after every function call
compared to AfterFunctionCallAnalysisInterface which gets only called
after a call to a function declared within the project, a plugin
implementing AfterEveryFunctionCallAnalysisInterface will get called for
every function call, including calls of PHP builtins.

On the other hand, this interface doesn't allow modification of the code
nor tweaking the return type, but it's still useful for accounting
purposes and for depreacting calls to PHP builtins

this fixes #2804
2020-02-13 09:10:24 -05:00
Matthew Brown
7d88100ad3 Docblock-provided type is not inferred 2020-02-12 11:34:54 -05:00