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

4578 Commits

Author SHA1 Message Date
Bruce Weirdan
5dfd157d72
Merge pull request #6420 from orklah/ternary-override-type
Ternary override type when reassigning
2021-09-04 21:58:32 +03:00
Bruce Weirdan
b710aab148
Merge pull request #6419 from TysonAndre/in_array-fix 2021-09-04 21:56:36 +03:00
Bruce Weirdan
3a3fde332e
Merge pull request #6392 from orklah/control-action-test 2021-09-04 21:38:08 +03:00
orklah
e2b594820e fix test 2021-09-04 20:27:25 +02:00
orklah
0825f220fe allow ternary to override previous type when reassigning 2021-09-04 20:22:06 +02:00
Tyson Andre
58e7ae1809 Also support non-literal types in strict in_array() check
Modified approach to #6396 by orklah

Fixes #6333

Co-Authored-By: orklah <ronan_morin@hotmail.com>
2021-09-04 12:34:49 -04:00
orklah
ea50e5db4d add test 2021-09-04 14:19:49 +02:00
orklah
861d2187dd fix tests 2021-09-04 14:17:55 +02:00
orklah
de27693015 change test to show while loop with truthy value is still inferred 2021-09-04 14:10:12 +02:00
orklah
e99c1951ae Make Psalm understand infinite while loop in control actions 2021-09-02 22:28:01 +02:00
Bruce Weirdan
a655ca81c1
Merge pull request #6391 from ro0NL/6388 2021-09-02 23:23:32 +03:00
Roland Franssen :)
9a6ae5a27a test 2021-09-02 20:53:23 +02:00
orklah
58e578e6a7 fix Generator giving templates to Iterator 2021-09-02 20:12:32 +02:00
Bruce Weirdan
eb973ab2e1
Merge pull request #6335 from boesing/bugfix/recursive-class-aliases 2021-08-31 23:51:19 +03:00
Bruce Weirdan
b713140cc1
Merge pull request #6326 from piporoid/issue/2164
Prevent @property annotations on class properties
2021-08-31 23:46:56 +03:00
Bruce Weirdan
cbcc38aab8
Merge pull request #6339 from niconoe-/allow-object-on-array_walk 2021-08-31 23:45:10 +03:00
Bruce Weirdan
103b2b7244
Warn about array_walk_recursive over objects 2021-08-31 23:18:20 +03:00
Bruce Weirdan
624246b996
Merge pull request #6376 from orklah/use-variable-in-backtick 2021-08-29 04:39:13 +03:00
orklah
10c20dc8f3 mark variable used in backticks as used 2021-08-29 00:26:52 +02:00
Bruce Weirdan
b370ce92aa
Report RawObjectIteration when array_walk is used on objects 2021-08-20 01:43:49 +03:00
Bruce Weirdan
9222b24ea1
Merge pull request #6321 from orklah/analyze-dynamic-classConstFetch 2021-08-20 01:06:56 +03:00
orklah
dbf3512b70 introduce $definite_class flag and use it to avoid using final keyword for simple inference 2021-08-19 23:19:59 +02:00
Bruce Weirdan
3cb28e6399
Merge pull request #6344 from orklah/vendor-suppressions
don't report UnusedSuppressions in non project dirs
2021-08-19 20:53:21 +03:00
orklah
6cf7660ad8 fix CS 2021-08-19 19:34:30 +02:00
orklah
7fd0d5f28e create real path for Psalm to stop ignoring suppressions 2021-08-19 19:31:58 +02:00
Maximilian Bösing
d4559f5ba3
qa: add failing test regarding recursive alias resolving
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2021-08-18 16:18:44 +02:00
Benjamin Morel
621c4dd8d1 Enforce class-string in is_subclass_of() 2021-08-17 23:14:11 +02:00
Bruce Weirdan
e5b797c764
Merge pull request #6327 from boesing/bugfix/class-alias 2021-08-17 23:35:25 +03:00
Maximilian Bösing
990723ce64
qa: rework unit test to use already available project_initializer
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2021-08-17 21:46:00 +02:00
Barney Laurance
88276d7f1e Fix error message for call to internal method from root namespace 2021-08-17 18:54:57 +01:00
orklah
1bf7447685 small refactor, add LiteralClassString, remove alter code blocks 2021-08-17 18:51:59 +02:00
Maximilian Bösing
7ab5d29e08
qa: add unit test to verify aliased interface is properly detected
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2021-08-17 18:40:18 +02:00
piporoid
1df5f3012a Prevent @property annotations on class properties 2021-08-17 23:40:26 +09:00
orklah
9264ea5cbb Allow type inference on dynamic ClassConstFetch 2021-08-16 21:20:20 +02:00
Bruce Weirdan
a9ead63ae1
Revert "Assertions for Integer Range" 2021-08-14 18:06:41 +03:00
Bruce Weirdan
7ff2a660dd
Merge pull request #6233 from supersmile2009/fix-in-array-assert 2021-08-13 01:39:31 +03:00
Bruce Weirdan
a4b6fbcbdf
Simplified InArrayTest a bit 2021-08-13 01:27:28 +03:00
Bruce Weirdan
6294e06955
Improve constant array inference
This fixes int offset inference and adds handling for array unpacks in
constant arrays. Mostly it's copy/pasted from `ArrayAnalyzer` with
further adjustments.

Fixes vimeo/psalm#6263
Fixes vimeo/psalm#6289
2021-08-12 20:39:21 +03:00
Bruce Weirdan
868a1672c1
Merge pull request #6253 from orklah/unusedSuppress 2021-08-09 23:34:14 +03:00
Bruce Weirdan
94f034b7ad
Merge pull request #6272 from orklah/sealed-array-combination 2021-08-09 23:33:00 +03:00
orklah
9ca771286f fix test 2021-08-09 21:18:19 +02:00
orklah
e688781383 seal the result of two sealed KeyedArrays 2021-08-09 20:43:17 +02:00
Bruce Weirdan
8c531fec4b
Tweaks
Changed the format of the historical callmap to be plain signature list,
as it isn't really a delta file and renamed the file to not be confused
with deltas.

Added a test to ensure entries in main callmap have history.
2021-08-08 18:43:42 +03:00
bjscharp
07d48d779a Merge branch 'master' into callmap-delta-inconsistencies 2021-08-08 10:41:42 +02:00
bjscharp
96056d329f Add simple test to verify outout of getCallMap method
Convert deltafile format to new style proposed by weirdan
Modify CallMapTest to use new format
Modify InternalCallMapHandler to use new format
Move assertions to base testcase
2021-08-08 10:39:54 +02:00
orklah
570aa1bb8e fix test? 2021-08-07 10:18:06 +02:00
orklah
b194291bb3 try to fix offsets 2021-08-07 00:08:19 +02:00
Maximilian Bösing
9d59fbe6bb
feature: introduce literal float methods to Union type
- Added `Psalm\Type\Union#isSingleFloatLiteral`
- Added `Psalm\Type\Union#getSingleFloatLiteral`
- Added `Psalm\Type\Union#hasLiteralFloat`

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2021-08-06 21:05:26 +02:00
bjscharp
d1d9e3763c Removed unused test dependencies 2021-08-06 07:45:17 +02:00
bjscharp
a01b92de8a Split duplicate add/remove check off into seperate tests to deal with several extra error paths 2021-08-06 07:33:37 +02:00
bjscharp
f39c462138 Add missing bcadd function to 8.0 delta file.
To prevent similar errors, add baseline file with signatures pre-7.1, to help verify delta files are correct.
Modify test to use this to detect missing 'old' entries
2021-08-05 23:21:41 +02:00
orklah
10049450f8 fix tests for the last time............................................... maybe? 2021-08-05 21:48:37 +02:00
orklah
ba2f623754 fix unused variables 2021-08-05 21:32:32 +02:00
orklah
50fd9065de fix tests 2021-08-05 21:15:04 +02:00
orklah
3fe678b914 ignore UnnecessaryVarAnnotation 2021-08-05 21:05:44 +02:00
bjscharp
ac5ea252ff Added test to detect problems and inconsistencies in CallMap files
- Fixed inconsistencies in callmap delta files (mainly 8.0)
- Added several missing changes in the bc_* functions
- Added several missing changes in the mb_* functions
- Added several missing changes in the xml_parser_* functions
- Fixed several issues with sodium_ functions
- Removed all but one of the date_* functions. All were marked as having lost the option to return false, despite this only being true for date_format
2021-08-05 19:07:31 +02:00
Alexandr Zolotukhin
3d61f6ca65 Add more tests 2021-08-05 16:42:52 +03:00
Alexandr Zolotukhin
c51f0f4fbf Add tests with needle/haystack value of union types which intersect partially 2021-08-03 21:09:59 +03:00
Alexandr Zolotukhin
586e8a157e Fix tests with loose types. Fix return type in the reconciler. 2021-08-03 19:34:35 +03:00
Alexandr Zolotukhin
e278b4fd93 Add failing test cases 2021-08-03 17:29:28 +03:00
Bruce Weirdan
caaff6e3b4
Merge pull request #6210 from orklah/int-range3 2021-08-01 16:37:15 +03:00
Bruce Weirdan
3a1714e732
Merge pull request #6215 from weirdan/fix-6211
Use fully-qualified name for virtual class strings
2021-08-01 16:36:25 +03:00
Matthew Brown
a205a23ccb Fix #6212 - remove untested code, add test for reasonable behaviour 2021-07-31 19:50:56 -04:00
Bruce Weirdan
e4ead74879
Use fully-qualified name for virtual class strings
Fixes vimeo/psalm#6211
2021-08-01 02:22:16 +03:00
orklah
d4bf17f323 fix test 2021-07-31 15:47:12 +02:00
orklah
128a811174 add internal assertions for superior and inferior 2021-07-31 15:47:12 +02:00
orklah
ba9f7d09ac fix CS 2021-07-30 22:22:38 +02:00
orklah
1e3e6a85e4 introduce basic integer range 2021-07-30 21:44:51 +02:00
Bruce Weirdan
9414b11c2f
Merge pull request #6204 from orklah/class-string-attributes 2021-07-29 22:35:42 +03:00
orklah
6fc55d7bff add test 2021-07-29 20:41:08 +02:00
Jack Robertson
f0193f20fa Consider print, and conditionally exit / die impure 2021-07-27 13:26:54 +01:00
Bruce Weirdan
358f83d66b
Merge pull request #6181 from Jack97/date-time-interface-type-reconciliation 2021-07-26 16:28:10 +03:00
Jack Robertson
c8574a6347 Simplify FQNs 2021-07-26 13:56:15 +01:00
Jack Robertson
8bec5fc743 Add expected behaviour tests 2021-07-26 08:50:12 +01:00
Bruce Weirdan
82dfbbc12e
Merge pull request #6167 from orklah/non-div-with-numeric-and-int 2021-07-25 13:56:48 +03:00
orklah
55245cf558 Arithmetic operation between numeric and int or float gives int|float 2021-07-25 12:29:11 +02:00
Bruce Weirdan
783dc610df
Merge pull request #6172 from Jack97/malformed-parentheses 2021-07-25 13:08:23 +03:00
Jack Robertson
3a18ec0d51 Add expected behaviour tests 2021-07-25 10:42:40 +01:00
Bruce Weirdan
aa23aa5387
Merge pull request #6166 from orklah/StringIncrementOnNumericString 2021-07-24 23:27:17 +03:00
orklah
9189fa1745 add tests and code for handling LiteralString that are Numeric 2021-07-24 21:21:50 +02:00
Jack Robertson
3eea15e840 Add failing test 2021-07-24 16:02:13 +01:00
orklah
c225281d22 add test 2021-07-23 21:22:00 +02:00
Bruce Weirdan
198fdf876e
Merge pull request #6142 from orklah/trigger_error 2021-07-23 09:22:55 +03:00
Matthew Brown
43cff22b25 Add support for native PHP readonly 2021-07-21 13:29:07 -04:00
Bruce Weirdan
052c7478cc
Unary plus and minus mark operand as used
Fixes vimeo/psalm#6145
2021-07-21 01:15:51 +03:00
orklah
cefa9b919e change wording 2021-07-20 23:55:49 +02:00
orklah
58dd3f6f94 change wording 2021-07-20 23:53:04 +02:00
orklah
acfdb82856 Basic implementation 2021-07-20 23:34:38 +02:00
Bruce Weirdan
0317f1dbec
Merge pull request #6130 from weirdan/forbid-dynamic-access-to-static-props 2021-07-19 16:11:29 +03:00
Bruce Weirdan
d992331125
Expand magic properties
Fixes vimeo/psalm#4344
Fixes vimeo/psalm#5663
Fixes vimeo/psalm#5639
Fixes vimeo/psalm#5955
Fixes vimeo/psalm#3272
2021-07-18 23:43:33 +03:00
Bruce Weirdan
a180dc6099
Flag staticness mismatch
This handles two new cases:
1. Accessing static property with `->` (produces notices and warnings: https://3v4l.org/TiGan)
2. Accessing non-static property with `::` (causes fatal error: https://3v4l.org/IdYSh)

Fixes vimeo/psalm#6117
2021-07-18 02:51:33 +03:00
Bruce Weirdan
53ae7764e9
Merge pull request #6129 from orklah/unused-global 2021-07-18 02:33:50 +03:00
orklah
d1a4975e3d remove test no longer applicable 2021-07-17 23:20:13 +02:00
orklah
79d0647d19 fix issue when setting a value to a global is considered unused 2021-07-17 22:00:54 +02:00
Grégoire Paris
26f8e5b333
Add negated identity with false case
This is the opposite of === true and works the same.
2021-07-17 03:20:23 +03:00
Bruce Weirdan
c9f52c449b
Merge pull request #6127 from weirdan/deprecated-properties
Check deprecated properties on $this->prop reads
2021-07-17 01:43:08 +03:00
Matthew Brown
88c4e2468e
Support interface-string<Foo> as temporary alias of class-string<Foo> (#6106) 2021-07-16 18:38:39 -04:00
Bruce Weirdan
af5cdb4dd4
Check deprecated properties on $this->prop reads
Fixes vimeo/psalm#6118
2021-07-17 01:20:35 +03:00
Bruce Weirdan
4a516005a3
Allow 0 for all bitmask types
Fixes vimeo/psalm#6119
2021-07-16 23:20:33 +03:00
orklah
0bd8b03f7a Fix usage of gettype in a switch with closed resource 2021-07-14 12:49:46 +02:00
Ruslan Karimov
8a08489dcc Merge branch 'master' into fix-5957
# Conflicts:
#	tests/UnusedVariableTest.php
2021-07-13 10:15:35 +05:00
Ruslan Karimov
cfaca07c6d added dataflow to stringy bitwise op, bitwise not op (fix 5957) 2021-07-13 10:05:21 +05:00
Bruce Weirdan
6729f4db01
Merge pull request #6083 from orklah/falsable-argument 2021-07-13 02:13:39 +03:00
orklah
688367de38 Always emit InvalidArgument when the parameter is always false and not accepted 2021-07-13 00:06:36 +02:00
Matthew Brown
f2bc6913db
Fix #6061 — delay analysis of array value except when unpacking (#6081) 2021-07-12 17:05:33 -04:00
Matthew Brown
acc7ee261c
Fix #6066 - introduce more robust system for capturing template constraints (#6072)
* Fix #6066 - add better system for capturing template constraints

* Fix comment
2021-07-11 12:03:21 -04:00
Bruce Weirdan
83bf9b8ed9
Merge pull request #5608 from paxal/patch/preg_replace_callback
Allow to use string key for preg_replace_callback callable argument
2021-07-11 04:55:03 +03:00
Fran Moreno
decb397b8e
Add ReflectionProperty::getType() and hasType() 2021-07-10 13:05:57 +02:00
ElisDN
61b78e117f Fix negative numbers 2021-07-08 19:17:31 +03:00
Bruce Weirdan
c27b51b91f
Merge pull request #6040 from j4nr6n/update_datetime_format 2021-07-04 08:54:58 +03:00
Justin
780c0307e7
Test should fail on 8.0, but not on 7.4 2021-07-03 05:01:10 -04:00
Justin
f7a2aaef6e
Update DateTime and DateTimeImmutable signatures
`DateTime::format` and `DateTimeImmutable::format` will always
return a string starting in PHP 8.0.
2021-07-03 04:29:54 -04:00
orklah
f8644fb508 Improve resolution of __METHOD__ and __FUNCTION__ 2021-07-03 10:01:53 +02:00
Bruce Weirdan
6db79be207
Keep generic part of shape on array_map return type
Fixes vimeo/psalm#6038
2021-07-03 06:33:37 +03:00
Bruce Weirdan
76be96ce53
Drop FakeFileProvider from tests folder
And use Psalm\Internal\Provider\FakeFileProvider
2021-07-02 03:57:57 +03:00
Bruce Weirdan
4b31058234
Separate memory limit formatting from retrieval
This addresses https://github.com/vimeo/psalm/pull/6030#issuecomment-872611832

Previously PHP would allow to set memory limit to be below current
memory usage, and the test changed in this PR abused that. As we
actually don't need to test `ini_get()` value decoding was split into
its own method, and we're testing that decoding instead.
2021-07-02 02:59:43 +03:00
Bruce Weirdan
248a07fd35
Ship FakeFileProvider even with dist dev releases
Refs psalm/psalm.dev#60
2021-07-02 00:26:20 +03:00
Matt Brown
667dcc2e49 No false-positives for tainting through array keys 2021-06-29 17:05:39 -04:00
Ruslan Karimov
79b61c3b61 Added support for self & static keywords in array_reduce callables 2021-06-29 22:27:50 +05:00
Barney Laurance
eff9acbd9a
Remove unecassary concatentation of string literals 2021-06-27 00:08:03 +01:00
Barney Laurance
0722401aaf Trim code snippets on both sides when comparing current issues against baseline
Should fix issue #5979

We could also trim code issues when writing to baseline, but I think
that's a minor BC break, so probably shouldn't happen until Psalm 9.
2021-06-26 22:37:29 +01:00
Bruce Weirdan
6d4262edbd
Mark return values in as throw argument as used (#5989)
Fixes vimeo/psalm#5975
2021-06-25 09:11:27 -04:00
Oliver Hader
38d3b15f8d
[BUGFIX] Specialize TaintSink in IncludeAnalyzer (#5986)
* [TEST] Assert more details in TaintTest

* [TEST] Add test for multiple tainted includes

* [BUGFIX] Specialize TaintSink in IncludeAnalyzer

Fixes: #5986
2021-06-23 08:27:03 -04:00
Bruce Weirdan
f24f361a95
Add documentation and schema entry for inferPropertyTypesFromConstructor
Fixes vimeo/psalm#5974
2021-06-22 21:20:10 +03:00
Matt Brown
d8f4eb2d6d Restrict type of implode to prevent Array-to-string conversion; 2021-06-21 19:55:27 -04:00
orklah
79478a60b1
Allow class constant as offset key (#5943)
* allow class-constant as an array offset when the type match

* remove object with __toString as a possible offset as it's not valid
2021-06-17 18:15:57 -04:00
orklah
872f1c232c
allow Psalter to fix RedundantCast (#5948)
* allow Psalter to fix RedundantCast

* fix test
2021-06-17 18:15:45 -04:00
Bruce Weirdan
e552925af6
Emit separate type of issue when foreach value is unused (#5932)
* Emit separate type of issue when foreach value is unused

Fixes vimeo/psalm#5929

* Fixed var name case sensitivity
2021-06-17 00:40:24 -04:00
orklah
cfa5492286
Remove redundant namespaced phpdoc (#5936)
* remove array-key from generated phpdoc

* remove mixed value too

* fix tests

* fix mixed suppression

* revert back to array to prevent breaking refactoring
2021-06-16 11:16:20 -04:00
Matt Brown
9dde8eed9d Add support for literal-int annotations as well 2021-06-14 23:24:09 -04:00
Matt Brown
c3fdfc5795 Support literal ints in encapsed strings 2021-06-14 16:30:45 -04:00
Matt Brown
3140654a44 Experiment with implode literal tracking 2021-06-14 16:03:37 -04:00
Matt Brown
5ae8b2a23f Add preliminary support for literal-string 2021-06-14 15:30:25 -04:00
Bruce Weirdan
24d45a50de
Merge pull request #5924 from BafS/fix-type-error-patch-1 2021-06-13 21:19:43 +03:00
Bruce Weirdan
a97bc06e6b
Test for boundary conditions 2021-06-13 13:40:54 +03:00
BafS
d395e00f18
Add assertion 2021-06-13 12:07:34 +02:00
Matt Brown
b678461f5c Improve detection of fluent methods 2021-06-12 17:09:42 -04:00
Matt Brown
23b7ff86b7 Mark interface methods as unused even when inherited 2021-06-12 16:13:29 -04:00
BafS
dde0f1fb06
Fix Uncaught TypeError with some shifts 2021-06-11 20:03:23 +02:00
Matt Brown
06b89aa00a Fix end-to-end tests 2021-06-10 18:07:41 -04:00
Matt Brown
4a9f35f0a8 Update ReportOutputTest.php 2021-06-10 17:59:41 -04:00
Matt Brown
f2f5f1eaa2 Revert fix and tests 2021-06-10 17:44:34 -04:00
Matt Brown
47bf5ed567 Fix #5918 - add new issue to detect unquoted strings 2021-06-10 17:43:04 -04:00
Matt Brown
e661c5fb55 Fix erroneous use when comparing methods 2021-06-10 14:39:01 -04:00
Matthew Brown
6d09418a23
Detect unused return values (#5917)
* Detect unused return values

* Allow static-returning instance methods (presumed to be fluent)

* Make $is_used the default for Codebase::methodExists
2021-06-10 14:18:15 -04:00
Matt Brown
5c1d8489da Improve test cases 2021-06-10 12:57:13 -04:00
Matt Brown
f5bc841295 Prevent nested literal coercion 2021-06-09 16:01:45 -04:00
Matthew Brown
d12cf88e83 Add back supported for templated index assignment 2021-06-09 12:55:37 -04:00
Matthew Brown
0a7d254689 Fix #5911 - improve non-terminating switch type inference 2021-06-09 09:06:23 -04:00
Bruce Weirdan
6abce3525a
Enforce use sort (#5900) 2021-06-07 22:55:21 -04:00
Bruce Weirdan
5bfb841072
Prevent crashes when class constant references missing class (#5902)
Fixes vimeo/psalm#5861
2021-06-07 13:20:07 -04:00
Bruce Weirdan
689315b05f
Fix sscanf() signature (#5901)
Fixes vimeo/psalm#5870
2021-06-07 13:19:17 -04:00
Bruce Weirdan
86050df4d0
Formally deprecate allowCoercionFromStringToClassConst (#5897)
* Mark allowCoercionFromStringToClassConst as deprecated in xml schema

* Emit deprecation warning for `allowCoercionFromStringToClassConst`
2021-06-07 10:46:26 -04:00
Andrey Klimenko
3ad3375777
Fix generic destruction in assertion (#5888) 2021-06-04 15:33:37 -04:00
Oliver Hader
e457a7d5af
[FEATURE] Allow plugins to declare their custom scanner or analyzer (#5883)
* [FEATURE] Allow plugins to declare their custom scanner or analyzer

Related: #5882

* [TEST] Check plugin declaring own scanner/analyzer

* [TASK] Document plugins declaring scanner or analyzer

* [TEST] Clean up code

* [!!!][TASK] Extend Psalm\Plugin\RegistrationInterface

* add method `addFileTypeScanner(string $fileExtension, string $className): void`
* add method `addFileTypeAnalyzer(string $fileExtension, string $className): void`

* [TASK] Ignore IntelliJ/PhpStorm workspace folder in VCS

* [TASK] Remove superfluous class import
2021-06-04 15:32:53 -04:00
Matt Brown
b33f87f68d Treat all assignment operations as equivalent binary ops 2021-06-04 14:39:38 -04:00
Matt Brown
be254efec6 Break out tests for readonly properties 2021-06-04 13:37:03 -04:00
Andrey Klimenko
e5e397a6c5
Type negation in generic context (#5879)
* Type negation in generic context

* Fix cs
2021-06-03 01:06:25 -04:00
Matt Brown
f3fc112bae Fix #4523 - fix short-circuiting for properties and method calls 2021-06-01 16:06:12 -04:00
Bruce Weirdan
448534fd7c
Cli command classes (#5858)
* Move psalm entry-point to a Cli command class

* Moved psalter to the CLI command class

* Moved psalm-language-server to the CLI command class

* Moved psalm-refactor to the CLI command class

* Moved psalm_plugin to the CLI command class

* Use CLI commands directly and deprecate trampolines

* Require CLI commands directly and don't use trampolines

* Announce isAbsolutePath() removal

* Deprecate \Psalm\requireAutoloaders() function

* Deprecate \Psalm\getVendorDir() function

* Deprecate Psalm\getArguments() function

* Deprecate \Psalm\getPathsToCheck() function

* Deprecate \Psalm\getPsalmHelpText() function

* Deprecate \Psalm\initialiseConfig() function

* Deprecate Psalm\update_config_file() function

* Deprecate \Psalm\get_path_to_config() function

* Deprecate Psalm\getMemoryLimitInBytes() function

* CS fix

* Untangle Psalm entrypoint

* Untangle Psalter entrypoint

* Drop command_functions.php references

* Adjust phar build
2021-05-31 22:23:54 -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
3bcfd2e726
allow psalter to add literal string/int in psalm phpdoc (#5844)
* allow psalter to add literal string/int in psalm phpdoc

* fix CS
2021-05-28 09:46:11 -04:00
Bruce Weirdan
0c77ccc238
Check whether constructor is internal on new call (#5843)
Fixes vimeo/psalm#5841
2021-05-28 09:44:07 -04:00
Oliver Hader
b259296457
[BUGFIX] Continue processing psalm-flow graph after first taint sink (#5832)
Related: #5830
2021-05-26 16:04:22 -04:00
Oliver Hader
4898cd262e
[TASK] Enrich taint details for outputting core stubs (#5827)
Affects `printf`, `print_r`, `var_dump`, `var_export`
2021-05-24 16:42:18 -04:00
Matt Brown
38c452ae58 Add example given in ticket and ensure that works too 2021-05-24 00:09:51 -04:00
Matt Brown
8f333337cb Fix #5804 - don’t choke on conditional return types when converting to callables 2021-05-23 21:41:07 -04:00
orklah
de1bb954cf
Handle the case where a switch return on each case (#5819)
* Handle the case where a switch return on each case

* introduce a "hybrid" case exit type for cases where there's both "none" and something else
2021-05-23 16:24:29 -04:00
Matt Brown
7354ec9903 Fix #5298 - improve handling of method that may write properties 2021-05-23 16:22:52 -04:00
orklah
350df114f3
Transform bad offsets (#5817)
* Transform bad offset access

* fix build
2021-05-23 14:43:30 -04:00
Matt Brown
d1262b0bec Fix #5799 — improve expansion of templated types 2021-05-23 14:39:59 -04:00
Matt Brown
938afc5aea Allow union of 0|positive-int to bypass PossiblyUndefinedIntArrayOffset error 2021-05-23 13:59:40 -04:00
orklah
c69cf9a849
Allow empty-string in first position of an type (#5814) 2021-05-22 12:36:02 -04:00
Matt Brown
6a61298074 Fix #5810 - detect properties that are never read 2021-05-21 09:25:57 -04:00
orklah
4d6be66d98
Prioritize TCallableString handling to avoid simpler checks for TLowercaseString vs TString (#5811) 2021-05-21 07:44:26 -04:00
Matt Brown
4b17cc9a4b Fix #5809 - remove unnecessary issue suppression 2021-05-21 07:35:01 -04:00
Matt Brown
964c91c502 Fix skipped test 2021-05-20 10:57:25 -04:00
Matt Brown
3a811f1fb5 Fix/suppress failures 2021-05-19 15:30:36 -04:00
Matt Brown
ccd50fdb34 Fix ##5795 - array casts should always be lists 2021-05-19 15:17:50 -04:00
orklah
f62b83a190
Assert intersection type when two variables are compared (#5774) 2021-05-18 16:14:58 -04:00
Matt Brown
3c43bc1522 Fix #5789 - prevent incorrect return type inference when all cases return 2021-05-18 08:52:41 -04:00
pawel-slowik
d82f02879c
Don't migrate virtual nodes (#5780)
* Add a failing test for issue #5002

* Don't try to migrate virtual nodes

Fixes #5002
2021-05-17 22:21:32 -04:00
Matt Brown
787c0f30d6 Fix #5784 - only real-asserted variables from context knowledge
Any assertions added in the addNestedAssertions method should not illegitimise current knowledge
2021-05-17 15:11:27 -05:00
Matt Brown
836587ec1d Fix combination of end states with never 2021-05-17 12:35:27 -05:00
orklah
ff0c1ce567
update hardcoded Psalm version (#5783)
* change hardcoded Psalm version to something more recent

* change hardcoded Psalm version to something more recent
2021-05-17 08:27:08 -05:00
Matt Brown
9635ca620c Correctly interpret continue 2 in nested loops 2021-05-17 08:26:38 -05:00
orklah
4c4d574bed
better inference of string increment (#5777)
* better inference of string increment

* fix combination
2021-05-17 07:44:53 -05:00
Matt Brown
f6bdeb6234 Fix switch-with-continue bug 2021-05-17 07:27:58 -05:00
orklah
6501ca7b95
Redundant cast to Int preserve type (#5773)
* Redundant cast to Int preserve type

* add test
2021-05-15 07:19:18 -04:00
Matt Brown
1195335078 Fix #5768 - call methods with proper params 2021-05-14 22:50:11 -04:00
orklah
55079e92fe
Mixed contains everything (#5763) 2021-05-14 20:23:54 -04:00
olsavmic
4fb2b65164
Fix ArrayFillReturnTypeProvider - consider second param (#5770)
Add test

Fix
2021-05-14 20:12:39 -04:00
Matt Brown
c4aea7c82c Fix #5434 - prevent crash with class-string-map 2021-05-14 19:44:11 -04:00
orklah
1bb4a05725
NullsafeMethodCall makes the variable not null for the rest of the scope (#5771) 2021-05-14 19:21:01 -04:00
orklah
0b96f40198
quote offset value (#5760) 2021-05-14 17:19:23 -04:00
Matthew Brown
5e8219b613 Fix #5327 - add check to prevent OOMing on very large conditionals 2021-05-14 14:53:53 -04:00
Matthew Brown
18931295c4 Fix #5073 — don’t crash when templates cannot be resolved 2021-05-13 16:55:22 -04:00
Matthew Brown
2ebf97b4cb Fix #4910 - don’t allow array_merge to create massive keyed arrays 2021-05-13 16:27:05 -04:00
Matthew Brown
78ed9404cb Fix #4107 - resolve reference to static in class constant 2021-05-13 12:49:33 -04:00
Matthew Brown
cc7ff94f7c Prevent crash when method being called does not exist in reflection
Crash seen when running this test in PHP 7.4 because the method does not exist, but the call map includes it in 8.0
2021-05-13 12:40:39 -04:00
Matthew Brown
4873f53f69 Fix issue when two continue/break statements write same variable 2021-05-13 09:39:25 -04:00
orklah
1a59e81808
allow scalar values in return to be accepted, even when the branch has no inferred types (#5749) 2021-05-12 18:47:05 -04:00
orklah
ab1732de66
combining never/empty twice gives never (#5756) 2021-05-12 18:46:37 -04:00
orklah
72022139fa
improve array_splice inference (#5738) 2021-05-10 11:45:52 -04:00
Matthew Brown
859b4a2caa Fix #5725 – don’t transform non-docblock types unnecessarily 2021-05-09 12:03:42 -04:00
Vincent Langlet
587b144f0e
Check for ParamName even for method with only one param (#5732)
* Check for ParamName even for method with only one param

* Fix tests
2021-05-08 19:33:48 -04:00
Bruce Weirdan
aa854ae338
Link to SARIF JSON schema (#5718)
Fixes vimeo/psalm#5716
2021-05-05 21:47:36 -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
58c8e75db3
Suppress issues emitted by MethodComparator at class level (#5711)
Fixes vimeo/psalm#5698
2021-05-05 21:46:29 -04:00
Bruce Weirdan
9e19653a72
Infer never return type (#5710)
* Allow __toString to return never

Fixes vimeo/psalm#5653

* Push $return_is_exit down

* Produce unique control actions

* Test suggesting `@return never`
2021-05-05 01:22:29 -04:00
Matt Brown
ed43c739e3 Prevent another unsafe template situation, skipping key-of tests for now 2021-05-05 01:06:53 -04:00
Matt Brown
ba90267ea7 Fix bad subtyping rule 2021-05-05 00:42:06 -04:00
Bruce Weirdan
27ea40eda0
Fix notice for certain invalid docblocks (#5709)
Fixes vimeo/psalm#5680
2021-05-03 22:28:17 -04:00
Bruce Weirdan
0189420814
Inherit class-level suppressions when checking methods (#5708)
Fixes vimeo/psalm#5687
May fix vimeo/psalm#3357
2021-05-03 22:26:56 -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
Matt Brown
d93c30d997 Fix Never test for latest PHP Parser 2021-05-03 16:59:24 -04:00
Matt Brown
eb71506a59 Fix #5697 - don’t consider docblocks when checking for invariant properties 2021-05-02 10:45:55 -04:00
Matt Brown
12844621b4 Fix #5693 - revert fix for #2048
The original fix was just a bit too narrow, and led to this bug
2021-05-01 21:13:42 -04:00
Matt Brown
0f7aaa5405 Fix #5696 - combinations of scalars should remove empty-scalar 2021-05-01 20:13:49 -04:00
Matt Brown
3a87f18b5a Fix #5685 - properly negate complex conditionals 2021-05-01 20:00:01 -04:00
Vincent Langlet
fb5c5a9c59
Fix array<empty, empty> not in array{foo?: mixed}<string, mixed> (#5677)
* Fix array<empty, empty> not in array{foo?: mixed}<string, mixed>

* Add tests
2021-04-30 09:00:49 -04:00
Matt Brown
123a9bc703 Add type-accepts-type unit test 2021-04-27 11:26:27 -04:00
Matt Brown
698adeff07 Rename incorrectly-named test 2021-04-25 18:26:00 -04:00
Matt Brown
4f5c205c57 Improve error message for #5489 2021-04-25 16:02:00 -04:00
Bruce Weirdan
933822e400 Do not consider isset checks on static properties as redundant (#5525)
* Do not consider isset checks on static properties as redundant

Unlike normal properties, static properties do not have a prescribed
initialization sequence, so they can always be uninitialized (or unset).
Thus `isset()` checks on them are never redundant.

Fixes vimeo/psalm#5489

* Fix issue with nullable is_static
2021-04-25 15:53:07 -04:00
Matthew Brown
85a0ef0456
Revert "Do not consider isset checks on static properties as redundant (#5525)" (#5670)
This reverts commit cd002e6a87.
2021-04-25 15:46:13 -04:00
Matt Brown
83f08bc1b8 Fix property tests 2021-04-25 15:22:32 -04:00
Matt Brown
67c5dc3c79 Fix #5517 - don’t let a variable’s by-refness be overwritten by a @var docblock 2021-04-25 15:11:23 -04:00
Matt Brown
7b7354efa3 Fix #5518 - add type for property with variable name 2021-04-25 14:49:43 -04:00
Matt Brown
daa40281df Add slashes 2021-04-25 13:32:58 -04:00
Matt Brown
2fa55d147a Allow parent class to call child protected method 2021-04-25 12:44:53 -04:00
Matt Brown
64fdac33e8 Fix #5641 - types should always be comparable to themselves 2021-04-25 10:45:43 -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
642f2f435c Fix #5640 - improve handling of assignments in conditional 2021-04-18 16:16:54 -04:00
Bruce Weirdan
93946d0827
Forbid rejecting named arguments when parent allows them (#5627)
Fixes vimeo/psalm#5622
2021-04-15 06:55:13 -04:00
Matt Brown
012dafad79 Fix #5383 - prevent unsound use of new static for generics 2021-04-10 13:16:19 -04:00
orklah
bb88cff28a
Int and Float can be reconciled with Numeric (#5611) 2021-04-09 23:59:59 -04:00
3b3065c881
Allow variable keys with array_key_exists (#5606)
* Allow variable keys with array_key_exists

* Switch to elseif
2021-04-09 11:29:45 -04:00
AndrolGenhald
518d0af895
Strict int/float comparison for conditional types, improve range return type (#5601) 2021-04-09 11:28:48 -04:00
Cyril PASCAL
c45e47d8ad Allow to use string key for preg_replace_callback callable argument 2021-04-09 15:33:16 +02:00
orklah
5f4a21190f
Numeric can be Falsy (#5598) 2021-04-07 22:02:13 -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
Matt Brown
a469c82653 Fix #5587 - detect final class calls when routed through parent 2021-04-06 12:35:09 -04:00
Matt Brown
7080bc3bff Fix #5578 - variables always set in conditionals should be combined 2021-04-06 11:11:40 -04:00
Matt Brown
517b2030c9 Fix #5545 - throwing uses method 2021-04-04 21:17:12 -04:00
Bruce Weirdan
f07b6e675e
Support array of objects in array_column() (#5567)
Fixes vimeo/psalm#5460
2021-04-04 00:01:01 -04:00
Bruce Weirdan
34cb21c7fc
Report cases where object is coerced into object with properties (#5566)
Fixes vimeo/psalm#5565
2021-04-04 00:00:31 -04:00
Bruce Weirdan
106c7db5d1
Provide more detailed return type for get_object_vars() (#5557)
Handle keyed objects and named objects, including support for property
visibility.
2021-04-02 15:39:43 -04:00
Valentin Udaltsov
31096d9361
Marked iterator_to_array as an impure function (#5532) 2021-04-02 15:38:15 -04:00
AndrolGenhald
d022910599
ConcatAnalyzer improvements and non-falsy-string fixes. (#5544)
* ConcatAnalyzer improvements.

Deduplicate code.
Improve type inference.
Allow literal type inference when only one side has multiple types (fixes #5483).
Fix invalid type inference with negative int as right operand.

* Fix inference to be lowercase-string when concatenating int.

* Fix TNonEmptyLowercaseString to not be subtype of TNonFalsyString.

'0' is a non-empty-lowercase-string that is falsy.

* Fix other issues with non-falsy-string.

* Nest ands and ors

Co-authored-by: Matthew Brown <github@muglug.com>
2021-03-31 23:16:21 -04:00
Matt Brown
fe97aa0722 Fix #5542 - nullsafe method calls are assumed used 2021-03-31 10:08:52 -04:00
Matt Brown
150dd00060 Fix #5540 - function is used inside throw expression 2021-03-31 10:03:25 -04:00
Bruce Weirdan
cd002e6a87
Do not consider isset checks on static properties as redundant (#5525)
* Do not consider isset checks on static properties as redundant

Unlike normal properties, static properties do not have a prescribed
initialization sequence, so they can always be uninitialized (or unset).
Thus `isset()` checks on them are never redundant.

Fixes vimeo/psalm#5489

* Fix issue with nullable is_static
2021-03-30 11:56:08 -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
orklah
adc5368b97
fix Int overflow for pow (#5510) 2021-03-29 15:09:44 -04:00
Matt Brown
17e147935a Fix #5506 – make array_values and iterator_to_array respect nested templates 2021-03-29 09:37:51 -04:00
Bruce Weirdan
d57dde0d15
Allow phantom classes in instanceof expression (#5498)
Fixes vimeo/psalm#5481
2021-03-29 00:11:45 -04:00
Bruce Weirdan
ec7de89f0c
Do not let string subtypes subsume class-strings (#5497)
Previously, Psalm would treat unions like `class-string|numeric-string`
as `numeric-string`, while the only case when string should subsume
`class-string` is when we're combining `class-string` with non-specific
`string`.

Fixes vimeo/psalm#5491
2021-03-28 23:12:23 -04:00
Matt Brown
9a714b759e Fix #5496 - ensure params extended in properties are properly fleshed out 2021-03-28 23:10:38 -04:00
Matt Brown
f41deeab0a Taint through reset call 2021-03-28 13:14:35 -04:00
Matt Brown
93743d1465 Also add better message for MixedArgumentTypeCoercion 2021-03-28 11:32:38 -04:00
Matt Brown
54ac13b190 Allow nested template unwrapping inside reset, end
Fixes #5208
2021-03-28 09:52:23 -04:00
Matt Brown
c64e879178 Only check param-out when no exception is thrown 2021-03-27 09:50:20 -04:00
orklah
12cd9590c8
allow $var::class on templates (#5484) 2021-03-26 21:21:38 -04:00
sji
19554de6f6
Add @ignore-var and @psalm-ignore-var (#5488)
* add `@ignore-var` and `@psalm-ignore-var`

* Change two words

Co-authored-by: Matthew Brown <github@muglug.com>
2021-03-26 21:20:23 -04:00
Saif Eddin Gmati
9f74676524
allow dismissing return value of pure functions with by-reference arguments (#5463) 2021-03-25 09:05:59 -04:00
Matt Brown
929f931c14 Taint mixed keys too 2021-03-24 16:42:30 -04:00
Jean-Nicolas
30f64b79de
Checks the intersection type if the magic method does not exist (#5473) 2021-03-24 15:34:05 -04:00
Matt Brown
10ccbdd8be Add tainting for array keys
Fixes #5470
2021-03-24 15:32:56 -04:00
Saif Eddin Gmati
477ae33cd6
allow dismissing return value of no-return pure functions (#5461) 2021-03-23 19:34:12 -04:00
Matt Brown
a96645d2e3 Fix many uses of offsets 2021-03-23 01:30:51 -04:00
Matt Brown
bf578d1024 Fix potential crash when calling magic setter 2021-03-22 23:08:38 -04:00
AndrolGenhald
de5a031088
Improve @no-named-arguments support and variadics. (#5455)
* Improve @no-named-arguments support and variadics.

Handling of argument unpacking and variadics still needs a pretty big makeover, but this is a good start.

Fixes #5420
Improves #5453 (iterable works, array still causes issues)

* Remove unneeded imports.
2021-03-22 19:58:22 -04:00
Matt Brown
ae1fd44b13 Resolve build issues 2021-03-22 19:37:49 -04:00
Sergey Yakimov
fb94db9b1f
Add proper handling of unpacked arguments with string keys (#5446)
* Add proper handling of unpacked arguments with string keys

* Fix undefined array key error

* Fix missed named arguments handling

* Fix false-positive on variadic parameter

* Add tests
2021-03-22 09:08:05 -04:00
Matt Brown
44c6d3035b Add more mixed origin information 2021-03-20 21:45:38 -04:00
Matt Brown
d1740394aa Detect mixed echo argument when unused variable detection is turned on 2021-03-20 20:53:51 -04:00
Samuel Mortenson
e07337650b
Make taint source keys unique to the added taints. (#5444) 2021-03-20 15:42:24 -04:00
AndrolGenhald
0579c1109b
Fix bugs with array spread operator (fixes #5421) (#5433) 2021-03-19 22:43:58 -04:00
Samuel Mortenson
4aabb411a8
Added event to prevent tainting. (#5398)
* Added event to prevent tainting.

* Remove optional codebase parameter.

* Removed falsy check for codebase.

* Use two separate hooks for adding and removing taints

* Add slashes

* Update add/remove taint test name.

* Cleaned up SafeArrayKeyChecker example plugin.

* Added more AddRemoveTaintsEvent calls to codebase.

* Fix type check error with $added_taints param.

* Added AddRemoveTaintsEvent to remaining classes.

* Fix post-merge error.

* Add comma

* Remove $int_offset that never existed

Co-authored-by: Matt Brown <github@muglug.com>
2021-03-19 22:41:41 -04:00
AndrolGenhald
843305c8e0
Support template property invariance (fixes #5371) (#5414)
* Support property invariance with templates.

* Fix false positive NonInvariantDocblockPropertyType with grandchild.

* Redo templated property invariance check to fix issues.

* Add template covariant test.

* Fix property invariance false positive with template-covariant.
2021-03-19 21:55:50 -04:00
AndrolGenhald
17f23ccb30
Fix false-positive with non-empty object like array (fixes #5436) (#5437) 2021-03-19 21:54:01 -04:00
AndrolGenhald
b859fba52d
Fix array spread false negative that crashes (fixes #5431, reverts #2852) (#5432) 2021-03-19 21:51:36 -04:00
AndrolGenhald
d4590711d6
Fix object-like array keys when combining string and automatic keys (fixes #5427). (#5428)
* Fix object-like array keys (fixes #5427).

* Fix incorrect return types for tests.

* Fix false positive list with literal int key.
2021-03-19 21:44:44 -04:00
Matt Brown
42d3bceb4e Use more accurate return type 2021-03-18 15:19:29 -04:00
Matt Brown
04f3e29f94 Expand documentation method return type to ensure we’re giving a fair shot 2021-03-18 11:07:02 -04:00
AndrolGenhald
45694d37d4
Fix composer major.minor version detection (fixes #5415) (#5416)
* Fix composer major.minor version detection (fixes #5415)

* Add PHP 8 polyfill dependency.

* Fix version check.
2021-03-18 09:42:01 -04:00
Matt Brown
95287d2a41 Fix directory separators 2021-03-18 09:37:31 -04:00
Matt Brown
d19088bb10 Add better origins for calls 2021-03-17 19:37:21 -04:00
Matt Brown
3046468d1e Add hints for MixedAssignment issues 2021-03-17 01:10:42 -04:00
Bruce Weirdan
97fe86c4e1
Fix BC break introduced in 4.6.3 (#5410)
Fixes vimeo/psalm#5405

Requires new patch release.

This PR reverts changes to the signature of `IssueBuffer::finish()` and
introduces separate method to be used to capture `$_SERVER`
2021-03-16 19:28:18 -04:00
Matt Brown
9d979e3467 Fix #5406 - track more changes to assertion type 2021-03-16 16:33:09 -04:00
orklah
2777b62d0b
String can be reconciled with Scalar (#5402) 2021-03-16 13:46:23 -04:00
orklah
ff5a6cb297
iterator_to_array must always return array-key (#5400) 2021-03-16 13:45:34 -04:00
orklah
1a3ff5676a
fix stub for array_combine + remove false in PHP8 + improve tests (#5395) 2021-03-16 13:43:49 -04:00
AndrolGenhald
9d840ee87b
Disable property invariance checks for properties with templates (#5380)
* Disable property invariance checks for templates

Property invariance checks were already disabled for template
properties, this also disabled the checks for arrays, lists,
class-string-maps, and iterables that contain templates.

Partially fixes #5371

* CS fixes

* Fix and simplify hasTemplate.

Add hasTemplate to TypeNode and simplify implementation with getChildNodes.

* Revert hasTemplate change and add containsTemplate.

* Check class-string too.
2021-03-16 13:43:30 -04:00
Bruce Weirdan
ae247d09a3
Don't mark promoted properties as unused params (#5404)
If anything, they should be marked as unused properties.

Fixes vimeo/psalm#4964
2021-03-16 13:41:43 -04:00
orklah
dd4d970a37
makes array_combine return non-empty-array for most cases (#5393)
* makes array_combine return non-empty-array for most cases

* Add back newline

Co-authored-by: Matthew Brown <github@muglug.com>
2021-03-14 21:18:19 -04:00
orklah
90fd1c5d1f
fix usage of callable with array_map (#5373) 2021-03-12 14:05:22 -05:00
orklah
cddef00692
fix int overflow (#5369) 2021-03-12 13:24:00 -05:00
Bruce Weirdan
205fdd197e
Wrap entrypoints into IIFE to protect their variables (#5366)
* Wrap entrypoints into IIFE to protect their variables

Fixes vimeo/psalm#5359

* Add tests for Psalm variable isolation

* Capture environment before registering autoloader
2021-03-11 00:14:22 -05:00
orklah
0a4ad5733b
add stubs for min/max (#5353) 2021-03-11 00:13:17 -05:00
Bruce Weirdan
4f8ba04236
Provide more specific explode() return type (#5350)
Fixes vimeo/psalm#5347

`explode()` now omits `false` from the return type  when separator is a
definitely non-empty string.
2021-03-11 00:09:15 -05:00
Bruce Weirdan
8be77aaa2e
Track variable usage in bool to int casts (#5349)
Fixes vimeo/psalm#4956
2021-03-11 00:08:32 -05:00
Bruce Weirdan
71a0457284
Emit ImplicitToStringCast in more places (#5344)
* Emit ImplicitToStringCast in more places

Fixes vimeo/psalm#5320

`to_string_cast` is set on successful comparison, thus it needs to
always bubble up (it will be ignored in UnionTypeComparator if some part
does not match).

* Fix implicit casts

* Fix handling of string method references in self-out context
2021-03-11 00:07:39 -05:00
Bruce Weirdan
7138678c63
Allow undefined variable detection in arrow functions (#5343)
Previously Psalm would assume that any variable it sees in the arrow
function body is defined (and mixed, if it's not available in the outer
scope). This prevented undefined variable detection. Dropping that
assumption allows it to work.

Fixes vimeo/psalm#5331
2021-03-11 00:06:23 -05: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
Bruce Weirdan
beca4a127f
Suppress test issues with Symony functions used with ::class constant (#5335)
These appeared in symfony/symfony#40203
2021-03-06 15:29:15 -05:00
Matt Brown
96e0743892 Fix #5325 – remove all memoised methods when calling a method with property mutations 2021-03-05 00:39:25 -05:00
Matt Brown
4c65d3b424 Fix #5310 - allow iterable coercion from generic object 2021-03-03 00:13:00 -05:00
Bruce Weirdan
841efbdfaf
Make WeakMap generic (#5313) 2021-03-02 22:25:19 -05:00
404db2bb1a
Fix JSON reports with long UTF8 strings (#5300)
* Fix JSON reports with long UTF8 strings

* CS fix

* UTF8-safe snippets
2021-03-01 11:23:21 -05:00
Matt Brown
8b5898029d Add more tests for robustness 2021-02-28 10:36:18 -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
Matt Brown
7db742dee3 Fix #5295 - offer static methods for completion too in instance mode 2021-02-27 11:36:19 -05:00
Matt Brown
44f8d71e72 Fix #5290 - improve inference of nested class-string template types 2021-02-27 01:00:05 -05:00
Matt Brown
98eb40c4ca Improve unwrapping inference in nested templates
Ref #5290
2021-02-27 00:22:31 -05:00
Matt Brown
92c12d5a38 Separate out some nested template tests 2021-02-26 16:05:46 -05:00
Matt Brown
474ebf912e Fix #5229 - new SomeTemplatedClass should expand out params even if none passed 2021-02-25 21:20:05 -05:00
Matt Brown
d4841993b2 Fix #5279 - don’t convert get_class($templated) into dependent type 2021-02-25 18:43:04 -05:00
Matt Brown
924f6b6f94 Propagate mutation removal up the context parent tree
Fixes #5231
2021-02-25 18:11:58 -05:00
elnoro
fff32d0443
added test for multiline templates (#5282) 2021-02-25 17:42:20 -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
f8cbb229f6 Fix #5236 - improve reconciliation of interfaces when unioned with class 2021-02-24 00:05:12 -05:00
Matt Brown
fe9eb6d91e Make test reconciler names better 2021-02-23 22:37:26 -05:00
Matt Brown
cafbdb6831 Fix #5264 - use accurate static type when calling parent method in trait 2021-02-23 20:48:22 -05:00
Matt Brown
def7326ae1 Remove static from return type when final
Fixes #5244
2021-02-23 19:06:45 -05:00
Matt Brown
3106635953 Fix inference of conditional types when wildcard constant given 2021-02-20 12:21:52 -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
686f9fcaaa Don’t throw an exceptin when parsing invalid type 2021-02-16 20:24:16 -05:00
Matt Brown
196f24aac3 Prevent TypeParseException when dealing with nested template in assertion 2021-02-16 20:06:15 -05:00
orklah
7b24552534
Fix not always positive bit operations (#5233)
* Fix not always positive bit operations

* Fix not always positive bit operations

* add test
2021-02-15 23:10:42 -05:00
Matt Brown
77feecb370 Apply the partial diff hack earlier 2021-02-15 15:32:35 -05:00
Matt Brown
a115d311b6 Fix small things 2021-02-15 11:31:34 -05:00
Matt Brown
e60c333f2d Fix completion of Foo:: before an if statement 2021-02-15 11:12:04 -05:00
Matt Brown
b7792ab0b4 Fix static method call completion with variable assignment after 2021-02-15 00:45:39 -05:00
Matt Brown
bd6efd7cf2 Improve completion for namespaced classes
cc @joehoyle - this mainly allows us to get a correct list when the user starts typing Foo (without the new before it) inside a namespace
2021-02-14 23:25:13 -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
Matt Brown
f738e19b04 Fix dupe keys 2021-02-14 20:23:40 -05:00
Matt Brown
1d5020f59f Only match functions where the first character has the same case as stub
cc @joehoyle - this prevents seeing lots of date_* functions when writing Date
2021-02-14 20:08:31 -05:00
Matt Brown
8834a54934 Fix #5219 - invalidate cache for changed params 2021-02-14 12:07:15 -05:00
Vincent Langlet
a80d5b736b
Rename stub to avoid phpstorm conflict (#5213) 2021-02-13 18:42:34 -05:00
Matt Brown
6fb7423c68 Fix #5211 - prevent infinite loop in template inference 2021-02-13 16:16:58 -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
Alberto Piai
144bb37f76
Fix array_key_exists() with all int literal keys (#5197)
When checking code like the following:

```
<?php

function checkNegated(string $key): void {
    $arr = [
        0 => "foo",
        1 => "bar",
    ];

    if (!array_key_exists($key, $arr)) {
        printf("not found\n");
    }
}

function check(string $key): void {
    $arr = [
        0 => "foo",
        1 => "bar",
    ];

    if (array_key_exists($key, $arr)) {
        printf("found\n");
    }
}
```

the `if` in `checkNegated` would cause:

```
ERROR: RedundantCondition - 9:10 - Type string for $key is never =int(0)
```

This happens when the array keys are all int literals, but the "needle"
is a string.

`array_key_exists()` uses a loose equality comparison, but the generated
assertions for this specific case
(`AssertionFinder::getArrayKeyExistsAssertions`) was generating strict
equality clauses. This commit fixes it by changing the generated clause
from `=` to `~`.
2021-02-12 17:00:38 -05:00
Joe Hoyle
4077de2c93
Add completions for functions (#5128)
* Add completions for functions

Provide autocompletions in the LSP for all global functions and functions from namespaces used in the current context.

* Uncomment code

* PHPCS

* Simplify functions map

Co-authored-by: Matthew Brown <github@muglug.com>

* Switch to storing lowercase function string in array key

* Fix spacing

Co-authored-by: Matthew Brown <github@muglug.com>
2021-02-12 16:59:47 -05:00
Matt Brown
fa337375ae Fix #5198 - allow is_array check on templated 2021-02-12 12:32:24 -05:00
Matt Brown
257a1ca672 Fix #5194 - don’t warn when redefining core class properties 2021-02-11 14:12:25 -05:00
Matt Brown
044602a244 Fix #5196 - fix type before assigning default property values 2021-02-11 09:38:04 -05:00
Matt Brown
2b9d307cab Fix #5184 - remove this vars from parent context where possible 2021-02-09 10:23:22 -05:00
Matt Brown
03b54e369b Fix test 2021-02-09 01:37:56 -05:00
Matt Brown
ad0b575080 Better fix for #5180 2021-02-08 23:31:49 -05:00
Matt Brown
9b8fdf154d Revert "Allow refinement of $this properties based on subclass"
This reverts commit 1d5d2403e2.
2021-02-08 22:50:50 -05:00
Matt Brown
1d5d2403e2 Allow refinement of $this properties based on subclass
Fixes #5180
2021-02-08 22:46:32 -05:00
Barney Laurance
509aadc08a
Remove all (but one) properity declarations that needed NonInvariantDocblockPropertyType suppressed (#5174)
The remaining property
\Psalm\Internal\Analyzer\NamespaceAnalyzer::$source seems a bit harder
to fix
2021-02-08 09:36:42 -05:00
Matt Brown
876a772edc Fix #5176 - substitute in actual argument when instance type found 2021-02-08 09:29:41 -05:00
Matt Brown
3be1bb7342 Limited fix for #5028 2021-02-07 22:56:37 -05:00
Bruce Weirdan
e3d73a3166
Allow suppressing thrown interfaces and their descendants (#5178)
Fixes vimeo/psalm#5177
2021-02-07 21:08:29 -05:00
Matt Brown
8b5e0fc754 Fix #5172 - prevent calling function with implicitly-broader type 2021-02-07 11:07:22 -05:00
Matt Brown
4d76f7545c Allow property type invariance on templated properties
This is a bit of a hack – the comparison should be similar to the ones done in MethodComparator, but this avoids false-positives for now
2021-02-07 01:45:48 -05:00
Matt Brown
f2d202e2bb Add less severe issue for docblock property type invariance cc @bdsl
This is less likely to break everything
2021-02-07 00:52:29 -05:00
Bruce Weirdan
04bb2b1182
Prevent invalid Traversable implementation (#5171)
* Prevent invalid Traversable implementation

Fixes vimeo/psalm#5167

* Document new issue

* CS fix
2021-02-06 22:10:05 -05:00
Bruce Weirdan
b72c5a0fa2
Mark variables in throw arguments as used (#5166)
Fixes vimeo/psalm#5164
2021-02-06 22:07:01 -05:00
Saif Eddin Gmati
d740c1679c
allow libraries to provide psalm plugins (#5165) 2021-02-06 22:06:00 -05:00
orklah
343d020408
improve psalter capacities for anonymous class extending real classes (#5146) 2021-02-04 09:59:38 -05:00
Matt Brown
ff325b3e70 Fix #5141 - combine numeric-string and non-empty-string to non-empty-string 2021-02-03 17:40:41 -05:00
Matt Brown
a0420fb704 Add non-falsy-string to allow more accurate checks 2021-02-03 17:19:48 -05:00
Matt Brown
03665b9646 Revert "Correct Psalm’s concept of string emptiness"
This reverts commit 331ce8ead4.

It was too hasty
2021-02-03 01:09:58 -05:00
Matt Brown
331ce8ead4 Correct Psalm’s concept of string emptiness
It contrasted with PHP’s idea
2021-02-02 23:07:51 -05:00
Matt Brown
0eed186edf Fix #5140 - always replace closure return types, whether or not a matching input type is present 2021-02-01 21:40:30 -05:00
Matt Brown
0f2a07a9a3 Fix #5137 – support @psalm-flow in methods 2021-01-31 22:40:48 -05:00
Matt Brown
c1d868f950 Fix #5127 - delay transformation of base classes based on inheritance until later 2021-01-31 12:33:07 -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
Joe Hoyle
a3dcc52e9a
Track references on global variables (#5122)
* Track references on global variables

Add global type references to the type map, and fix up unused detection on global variables.

* Add null assertions

* PHPCS
2021-01-28 18:58:02 -05:00
Joe Hoyle
5759472168
Add constant fetch to reference map (#5115)
* Add constant fetch to reference map

To support showing constant types on hover of constant references, we need to add them to the ref map.

* Fix root constants

* PHPCBF
2021-01-28 11:18:28 -05:00
Matt Brown
359a0166e3 Fix #4631 - prevent reusing named params 2021-01-27 22:53:55 -05:00
Matt Brown
4807d38507 Fix using std library functions 2021-01-27 22:28:33 -05:00
Matt Brown
dd11e541a7 Fix #4010 – don’t create interface intersections unless there’s no overlap 2021-01-27 12:48:32 -05:00
Matt Brown
3c58220f3a Fix #5097 - memoise more things during null coalesce 2021-01-26 23:10:57 -05:00
Matt Brown
76269658ca Fix #5107 - treat function-bound templated parameters the same
Previously they were treated differently depending on whether or not they were inside a method
2021-01-26 22:43:42 -05:00
Joe Hoyle
c946242683
Completions for array keys and type literals (#5105)
* Add completions for known array keys

* Use dynamic gap value

* Provide completions for known type contexts

* Fix formatting

* Remove trailing comma

* PHPCS fixes

* Remove support for literal floats

* Fix test for floats
2021-01-26 21:34:46 -05:00
Matt Brown
62a5a74640 Fix #5108 - prevent crash on 0 type 2021-01-26 14:06:43 -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
Bruce Weirdan
3209ef76fe
Remove ReflectionType::getName(), move ReflectionType::isBuiltin() (#5090)
* Remove ReflectionType::getName(), move ReflectionType::isBuiltin()

* `ReflectionType::getName()` was never there: https://3v4l.org/1iZt4
* `ReflectionType::isBuiltin()` was moved to
`ReflectionNamedType::isBuiltin()` in PHP 8

Fixes vimeo/psalm#5089

* Fix test

* Mark test as php 8.0 only
2021-01-24 13:31:10 -05:00
Bruce Weirdan
0489dd1fd8
Use separate exit code to indicate Psalm finding issues (#5087)
* Use separate exit code to indicate Psalm finding issues

This will allow to distinguish successful run that found some issues
from crashes.

* Fix e2e test expectations

* Documented exit statuses
2021-01-24 13:30:35 -05:00
Joe Hoyle
531cd36767
Support completions on class references (#5085)
* Support compleitions on class references

This provides completions on class references (as opposed to initiated objects via the type map), so you can do `MyClass::` and get completitions for static methods and constants etc.

* Only provide completions for references that don't exist
2021-01-24 13:29:21 -05:00
orklah
b61831345c
only transform a Keyed array into callable-array if there's two elements (#5086)
* only transform a Keyed array into callable-array if there's two elements in array

* add tests
2021-01-22 16:14:29 -05:00
Joe Hoyle
ba43e6d0f3
Remove file map cache when re-analyzing files (#5084)
* Remove file map cache when re-analyzing files

When the project is re-analyzed under the single thread condition (not using a process pool), the filemaps are not cleared before re-analyzing files. This means that file maps only get appended to. If you delete the contents of a file via the LSP, the file map will still be populated with all the old values for example.

In doing this I had to write a few more tests to check my assumptions too, so adding those additional tests.

* Rename test

* Formatting

* Formatting again!
2021-01-22 16:05:28 -05:00
Adrien LUCAS
6f1f680b2d
Add option to dump taint graph (#5080)
* Add option to dump taint graph

* Fix types

* Simplify types

Co-authored-by: Matthew Brown <github@muglug.com>
2021-01-22 16:04:15 -05:00
Matt Brown
6f30399189 Fix #5070 – fix static return type inference in static methods 2021-01-22 09:58:09 -05:00
Matthew Brown
28d2795e59 Fix #5078 - when unpacking with missing array item, Use the param’s default type if param has one 2021-01-22 00:20:51 -05:00
Bruce Weirdan
d659957b88
Resolve class aliases when accessing properties (#5068)
* Resolve class aliases when accessing properties

* Moved Properties::getClasslikeStorage() to ClassLikes::getStorageFor()
2021-01-21 19:38:17 -05:00
Bruce Weirdan
d296c4bb9a
Add missing dataflow population in array spreads (#5059)
Fixes vimeo/psalm#5057
2021-01-20 17:42:11 -05:00
81b75a7884
Check iterator types on yield from (#5042)
* Check iterator types on yield from

* Switch to NodeAbstract

* Make Foo iterable
2021-01-20 17:41:15 -05:00
Matt Brown
f1107ab4d9 Fix #5049 - assertion of !empty on bool makes true 2021-01-19 17:19:47 -05:00
Matt Brown
2f58c6afc8 Fix #5020 - remove previous catch var assertions when assigning inside catch 2021-01-17 14:28:28 -05:00
Matt Brown
bca58863ad Fix #5017 - handle combining literal and non-empty strings 2021-01-17 12:22:29 -05:00
Matt Brown
4378bec917 Fix #5025 - prevent crash in assert function during reflection 2021-01-17 12:08:19 -05:00