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

557 Commits

Author SHA1 Message Date
Brown
4026b717b9 Allow function manipulators to work in threaded mode 2020-08-23 18:05:48 -04:00
Matthew Brown
ef0486ce35 Add some pure annotations 2020-08-23 13:52:31 -04:00
Matthew Brown
06c231fbba glob is impure 2020-08-23 13:41:43 -04:00
Matthew Brown
f6135bcefc Add more impure functions 2020-08-23 13:15:27 -04:00
Bruce Weirdan
1cf5153700
Test parallelization (#4045)
* Run tests in random order

Being able to run tests in any order is a pre-requisite for being able
to run them in parallel.

* Reset type coverage between tests, fix affected tests

* Reset parser and lexer between test runs and on php version change

Previously lexer was reset, but parser kept the reference to the old
one, and reference to the parser was kept by StatementsProvider. This
resulted in order-dependent tests - if the parser was first initialized
with phpVersion set to 7.4 then arrow functions worked fine, but were
failing when the parser was initially constructed with settings for 7.3

This can be demonstrated on current master by upgrading to
nikic/php-parser:4.9 and running:

```
vendor/bin/phpunit --no-coverage --filter="inferredArgArrowFunction" tests/ClosureTest.php
```

Now all tests using PHP 7.4 features must set the PHP version
accordingly.

* Marked more tests using 7.4 syntax

* Reset newline-between-annotation flag between tests

* Resolve real paths before passing them to checkPaths

When checkPaths is called from psalm.php the paths are resolved, so we
just mimicking SUT behaviour here.

* Restore newline-between-annotations in DocCommentTest

* Tweak Appveyor caches

* Tweak TravisCI caches

* Tweak CircleCI caches

* Run tests in parallel

Use `vendor/bin/paratest` instead of `vendor/bin/phpunit`

* Use default paratest runner on Windows

WrapperRunner is not supported on Windows.

* TRAVIS_TAG could be empty

* Restore appveyor conditional caching
2020-08-23 10:32:07 -04:00
SignpostMarv
9822043ca4
flag class_exists as impure per vimeo/psalm#3975 (#4004)
`class_exists()` interacts with PHP's autoloader feature, which allows
user-defined behaviour to take place when PHP tries to load a given
class or interface.
2020-08-17 15:48:48 -04:00
Gabriel Ostrolucký
81a117be85
Mark fgets impure (#4006)
This function is used to skip line of text
2020-08-17 15:48:28 -04:00
Matthew Brown
73321339a3 Bump nikic/php-parser 2020-08-09 16:23:43 -04:00
ygottschalk
f831ebdbcf
narrowed reset and end return type (#3950)
* narrowed `reset` return type
BUT psalm seems to ignore the stub

* narrowed `reset` and `end` return type, this time for real

* fixed UnusedVariable Issue

* fixed RedundantCondition Issue
caused by `end`s return type being more precise

* Improve solution slightly

Co-authored-by: Matthew Brown <github@muglug.com>
2020-08-07 12:23:20 -04:00
Brown
bcf0df4170 Fix a bug with lowercase-string unions 2020-08-05 20:05:57 -04:00
Brown
488a899823 Fix Psalm issues 2020-08-05 19:49:09 -04:00
Brown
c0b0036109 Fix #3934 - prevent unsafe use of new static 2020-08-05 19:39:27 -04:00
Daniel Melchior
fa73c7c9d9
Fix #3757 - allow multiple mixins (#3772) 2020-08-05 15:49:19 -04:00
SignpostMarv
06d4b9d6dd
mark bcscale as impure, re: vimeo/psalm#3918 (#3926) 2020-08-03 10:15:59 -04:00
Brown
6919e88423 Add performance logging under a --debug-performance flag 2020-07-30 15:30:19 -04:00
Grégoire Paris
2f673fbbd7
Detect redundant identity with true (#3893)
Using === true on a known boolean results in the same boolean.
2020-07-25 17:27:45 -04:00
Brown
92fe9898a1 Fix #3879 - ensure interface templates are extended where nececssary 2020-07-24 11:29:36 -04:00
Barney Laurance
ff432ff73d
Simplify error messages and implementation for internal errors (#3881)
* Use more consistent language for Internal errors

There's no meaningful distinction between something being internal and
being 'marked as internal'.

* Rename property psalm_internal to internal in all storage classes

This property holds metadata that can be set using either @internal
or @psalm-internal in docblocks

* Change types of internal properties in storage from ?string to string

Simpler type is easier to handle. Non-internal methods can be considered
to be internal to the entire universe of PHP code, i.e. that code whose
namespace starts with the empty string. It's not a special case.
2020-07-24 09:32:54 -04:00
Barney Laurance
3bc91b9944
Fix multiple issues with @internal and @psalm-internal (#3841)
* Add passing tests for property fetch on an @internal class

I'm trying to work out why the equivilent InvalidCodeParse test is
failing for PsalmInternal

* Treat all properties of a psalm-internal class as psalm-internal

* Remove all $internal properties from storage - use psalm_internal instead

@internal can be represented as internal to the namespace root, avoiding
the need to check for both properties in storage later.

* Raise InternalClass issue when an internal class is used with e.g. instanceOf

* fix docs and tests

* Add return type declartion to code example in doc

* Don't allow class psalm-internal to overide a tighter method psalm-internal

* Break up long line

* Code style - move && from EOL to SOL

* Restore misplaced &&

* Fix code style

* Fix namespace fetching so it works

Co-authored-by: Matthew Brown <github@muglug.com>
2020-07-22 19:27:35 -04:00
Brown
76bd5b6278 Refactor type comparison 2020-07-21 19:40:35 -04:00
Tyson Andre
060ae61f31
Remove an if statement that repeats the previous if statement (#3840)
They're the exact same variables.
2020-07-17 19:46:06 -04:00
Tyson Andre
f17a4911d5
Add more impure functions (#3814) 2020-07-14 17:14:09 -04:00
Brown
cf67b9eef1 Fix #435 - add psalter fix for MissingPropertyType 2020-07-08 12:03:12 -04:00
Tyson Andre
cda6bd0553
Fix "Could not get class storage" from cache (#3769)
Fixes #3671

This is better than an uncaught exception, at least, and I can detect
new issues if the constructor body changes
2020-07-07 17:10:51 -04:00
Brown
7c7ebd068f Make invalidation more robust 2020-07-03 12:59:07 -04:00
Olle Härstedt
d8e8ce428e
Add new annotation: @psalm-self-out (#3650)
* Add new config: sealAllMethods

* Add some more tests

* Fix codesniffer issue with preg_quote

* Fix missing method in test

* New tag @self-out (WIP)

* Add self_out_type to method storage

* Add some notes

* More work on self-out (WIP)

* More work on self-out (WIP)

* Use psalm-self-out instead of self-out

* Remove extra file

* Cleanup

* Wrap around try-catch - how to check if a method has/should have storage?

* New method hasStorage()

* Fix indentation

* Fix some errors

* Fix indentation

* Cast storage type to type

* Add proper use-statement in method storage

* Correct test class name

* Allow self_out to be null

* method_id can be string (why, when?)

Co-authored-by: Olle <noemail>
2020-07-01 18:10:24 -04:00
Brown
17558a5c0e Fix #3676 - add multiline output for TaintedInput issues 2020-06-30 13:17:51 -04:00
Brown
e56483bb54 Fix #3711 - generalize call of specialized class without specializations 2020-06-29 17:42:01 -04:00
Brown
bcd7478352 Reduce memory footprint a little 2020-06-25 19:12:30 -04:00
Brown
f458959af5 Add param type 2020-06-25 01:40:19 -04:00
Brown
d7f1bde6da Refactor taint acccess checks 2020-06-25 01:32:57 -04:00
Brown
b8ebed0b85 Add a bit more accuracy 2020-06-25 01:00:11 -04:00
Brown
e26922010a Improve accuracy of array nesting checks 2020-06-25 00:50:52 -04:00
Brown
de85e7c539 Fix blips 2020-06-24 13:19:14 -04:00
Brown
9aa0aca949 Fix handling of coerced callmap args 2020-06-24 11:51:31 -04:00
Brown
c29b3744ec Change storage of out types 2020-06-24 11:51:31 -04:00
Brown
9b860214d5 Fix #3639 - allow coerced types to count when picking callmap options 2020-06-22 20:24:34 -04:00
Brown
dddc159694 Add explicit path object 2020-06-22 02:10:03 -04:00
Brown
36f1630e03 Add more steps for clearer output 2020-06-22 01:08:58 -04:00
Brown
02e8313c39 Allow taintedness to propagate to some stubbed methods 2020-06-21 18:07:39 -04:00
Brown
fbe3433edd Use escape terminology 2020-06-21 11:43:08 -04:00
Brown
2ccec821f8 Fix #3624 - inherit magic property annotations from traits 2020-06-20 16:53:17 -04:00
Brown
8f2e28c36b Improve tainting of specializable classes 2020-06-19 01:22:51 -04:00
Brown
49f0592794 Improve tracking of array taints 2020-06-18 18:48:19 -04:00
Brown
7fc1f50f54 Fix potential nullref 2020-06-17 16:40:35 -04:00
Brown
4870774ea4 Allow falsable issues on DateInterval::$days 2020-06-17 16:28:26 -04:00
Brown
56ef220e49 Fix bugs in taint specialisation 2020-06-15 18:34:56 -04:00
Matthew Brown
081a284759 Fix #3567 - remember which variables a callable sets byref in use 2020-06-14 11:58:50 -04:00
Matthew Brown
a49a0e5650 Fix #3551 - count method can be impure 2020-06-14 11:06:53 -04:00
Matthew Brown
427f470806 Fix #3586 - ensure templated trait params more accurate 2020-06-13 16:37:39 -04:00
Gabriel Ostrolucký
8ca7a88c41
Mark fgetcsv impure (#3582)
fgetcsv standalone is used to skip current row for consecutive reads
2020-06-13 00:32:00 -04:00
Bruce Weirdan
a99f92ae3a
Fix vimeo/psalm#3572 (#3575)
session_decode has side effects
2020-06-13 00:28:56 -04:00
Brown
16189782ab Inherit whether methods are sealed from parent
Ref #3561
2020-06-11 11:28:41 -04:00
Matthew Brown
739d23e5f0 Use alias 2020-06-06 23:27:25 -04:00
Brown
d04e21ee5a Define mixin declaring classname 2020-05-26 23:32:07 -04:00
Brown
7e7456c863 Make taint checks more thorough 2020-05-25 17:10:53 -04:00
Brown
118b700436 Simplify sink mapping for internal calls 2020-05-25 13:10:06 -04:00
Brown
ee493909d7 Fix bugs 2020-05-23 00:08:16 -04:00
Brown
dc73e25157 Detect taints in include calls 2020-05-22 23:53:37 -04:00
Brown
e82c317d53 Adjust tolerances 2020-05-22 21:37:18 -04:00
Brown
bbc30a1747 Only recreate taints if non-null 2020-05-22 16:55:36 -04:00
Brown
8632cdb3cd Improve taint tracking during scanning phase 2020-05-22 12:33:48 -04:00
Brown
63c3678ae5 Improve property location resolution 2020-05-22 12:33:38 -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
b62f646388 Fix #3391 - move_uploaded_file mutates 2020-05-18 16:26:08 -04:00
Brown
111303d913 Add non-empty-lowercase-string type 2020-05-15 10:18:05 -04:00
Brown
0086eb25a2 Remove duplicate types with @psalm-import-type 2020-05-15 00:16:20 -04:00
Brown
9f3f7bb946 Consolidate ThreadData types 2020-05-14 23:44:22 -04:00
Brown
2af0a17d03 Fix #3236 - allow use-checking of more methods starting with __ 2020-05-12 22:39:26 -04:00
Brown
3e58163180 Prevent empty function id
Ref #3354
2020-05-12 12:54:06 -04:00
Brown
8f2f2617d4 Improve refactor 2020-05-10 22:45:01 -04:00
Brown
5f4d162dd5 Break out type expander into separate class 2020-05-10 22:39:18 -04:00
Matthew Brown
733da0e539 Fix #3311 - don’t erroneously mark a class as undefined
As they can sometimes only be obvious once an autoloader has been registered
2020-05-10 15:55:44 -04:00
Brown
28349c6423 Remove mixin_fqcln hack 2020-05-10 09:04:30 -04:00
Brown
aceaf6c356 Fix #3217 - don’t override abstract return type with parent one 2020-05-02 21:57:53 -04:00
Brown
132b5c9358 Fix #3263 - inherit magic properties when using @mixin 2020-05-02 19:57:38 -04:00
Matthew Brown
da5e8a4324 Increase type coverage for projects that use assert after mixed 2020-05-02 14:55:30 -04:00
Brown
8f57d0c738 Fix #3204 - normalise function ids where possible 2020-04-20 21:38:35 -04:00
Brown
6b42efed3f Fix #3150 - only inherit docblock return when same type is returned 2020-04-20 09:22:58 -04:00
Brown
6fc18af42e Fix #3163 - map object-like arrays too 2020-04-19 18:46:24 -04:00
Brown
286c396498 Fix #3185 - allow ignore_user_abort calls 2020-04-19 13:19:18 -04:00
Brown
2188b6736f Fix #3162
Descend into inherited templates to prevent function-defined templates mapping inappopriately
2020-04-19 12:19:39 -04:00
Brown
7af771a006 Fix #3132 - resolve array access in constant properly 2020-04-18 12:39:00 -04:00
Bruce Weirdan
0161f25ef6
Bump callmap version to 7.4 (#3094)
The content of the callmap corresponds to 7.4, but internally the
version was set to 7.3. This caused 7.4 delta to be ignored, and 7.4
types to be used for 7.3.
2020-04-08 01:04:34 -04:00
Brown
5db9f0e8c0 Fix #2722 - change behaviour to inherit params to match just on position
And not name + position
2020-04-08 00:54:17 -04:00
Brown
067104e170 Fix #3084 - keep track of upper and lower bounds of inferred template types 2020-04-07 00:13:56 -04:00
Matthew Brown
f0b4533ba4 Use same sort order regardless of OS 2020-04-05 00:37:46 -04:00
Matthew Brown
05f7c9757a Write debug to stdout 2020-04-05 00:28:55 -04:00
Brown
c6afa0fef6 Be more explicit about references 2020-04-04 21:48:14 -04:00
Brown
003212fa15 Make sure to record class references even when we don’t know whether the class exists 2020-04-04 21:47:35 -04:00
Brown
81534bbe18 Fix possibly null issue 2020-04-04 18:57:33 -04:00
Brown
2930eb3f99 Prevent storing references to classes from within those classes 2020-04-04 18:42:14 -04:00
Brown
72104a52ad Improve file invalidation when using --diff mode 2020-04-02 17:18:04 -04:00
Brown
943d10854d Clear existing issues before re-adding 2020-04-01 15:30:35 -04:00
Brown
04a49102ec Small test improvements 2020-04-01 12:56:32 -04:00
Brown
d5f43e52e7 Fix coercion 2020-03-31 16:57:08 -04:00
Brown
191a3febac Return all cached errors not in analyzed files 2020-03-31 16:56:22 -04:00
Brown
cc38f25ed7 Don’t remove non-method issues 2020-03-31 16:33:05 -04:00
Brown
da729cfbc6 Don’t check params when mutations are being collected 2020-03-31 15:49:43 -04:00
Brown
687ce87995 Ensure issues from unused classes & params is always saved to cache 2020-03-31 09:56:27 -04:00
Matthew Brown
39f7296670 Fix #2191 - allow inheritance from stub-only files 2020-03-29 00:13:01 -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
75432536f7 Add slashes 2020-03-26 14:43:48 -04:00
Brown
820bd95d8b Fix existing issue check 2020-03-26 14:25:11 -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
Brown
a83651050c Seal objectlike arrays inferred from constants 2020-03-23 16:28:20 -04:00
Matthew Brown
cbf139952c Fix #2989 - delay @mixin hydration until parent methods inherited 2020-03-18 21:38:53 -04:00
Matthew Brown
311bd19a6a Fix #2983 - inherited lists should have their template types localised 2020-03-18 16:23:09 -04:00
Matthew Brown
50eb12e562 Fix implementation kink 2020-03-15 16:14:09 -04:00
Matthew Brown
3339c12179 Temp, slightly hacky fix 2020-03-15 16:00:15 -04:00
Matthew Brown
532ce576cc Fix #2974 - interpret interfaces a little better 2020-03-15 15:49:13 -04:00
Matthew Brown
43189b3d55 Allow types to be traversed 2020-03-14 23:54:51 -04:00
Matthew Brown
321f1a5e2f Cache trait nodes 2020-03-11 22:14:21 -04:00
Brown
1399b139fc Fix #2951 - use reflection to identify trait when there’s more than one per file 2020-03-09 16:41:46 -04:00
Brown
40a7a1156f Fix #2930 2020-03-09 09:45:35 -04:00
Matthew Brown
17afeae851 Fix support for bitwise or in constant expressions 2020-03-09 00:54:26 -04:00
Matthew Brown
0e60a1a223 Revert erroneous line 2020-03-06 19:31:39 -05:00
Matthew Brown
b999037263 Fix #2928 - properly expand out skipped template inheritance 2020-03-06 19:24:47 -05:00
Matthew Brown
766effb0db Improve accuracy of diff generation 2020-03-06 13:48:59 -05:00
Matthew Brown
f3d7ed6de7 Remove var_dump 2020-03-06 13:15:52 -05:00
Matthew Brown
7f9e6b893e Increase processor consumption 2020-03-06 13:13:18 -05:00
Matthew Brown
dc74f2b4de Add specific cast 2020-03-06 13:05:55 -05:00
Matthew Brown
10b807b4f6 Fix reference generation from methods in --diff mode 2020-03-06 13:02:34 -05:00
Philip Hofstetter
ab9c82e251 mark ftp_close as impure
in theory, all ftp_* functions are impure, but not marking them
encourages the good practice of checking the return value.

However, ftp_close(), while it's possible for it to fail, what good
would checking the return type do? How is one supposed to handle the
failure to close a stream in a way that affects future program flow?
2020-03-05 15:37:08 -05:00
Matthew Brown
0f5b0fd65d Fix location of traits 2020-03-02 23:07:21 -05:00
Matthew Brown
2cf2ead43b Remove stray comma 2020-03-02 22:30:06 -05:00
Matthew Brown
c0c878cc9d Don’t cache all traits 2020-03-02 22:27:54 -05:00
Brown
93d2d4d1a7 Add slash 2020-03-02 16:02:45 -05:00
Brown
86d52bbf4f Remove unused code 2020-03-02 15:49:05 -05:00
Brown
ceebc9e81d Only invalidate methods that call a removed trait 2020-03-02 15:26:57 -05:00
Brown
61ecd2a5fe Limit constructor check invalidation 2020-03-02 11:20:52 -05:00
Brown
548d9fca2c Add references to property-defining classes 2020-02-26 16:49:14 -05:00
Brown
712806b452 Fix #2874 - understand doubly-inherited interface templates 2020-02-24 17:58:44 -05:00
Matthew Brown
d3f8e80c4a Move reference map generation into separate file 2020-02-23 14:53:31 -05:00
Brown
7d99a15072 Fix #2805 - forbid passing in mutable class to mutation-free context 2020-02-21 18:25:35 -05:00
Matthew Brown
196a0a5c4e Replace issue data array with object 2020-02-16 18:24:40 -05:00
Matthew Brown
bacc7f254c Remove unnecessary extension check 2020-02-15 10:42:29 -05:00
Matthew Brown
d0d0c019cd Fix aliasing 2020-02-14 22:39:07 -05:00
Matthew Brown
653353709a Use MethodIdentifier object instead of string 2020-02-14 20:54:26 -05:00
Matthew Brown
477d38e6eb
Suppress issue 2020-02-13 18:20:24 -05:00
Brown
210d65d0d6 Add a few lowercase-string types 2020-02-13 17:52:23 -05:00
Brown
8989737e51 Fix #2775 - use lowercase strings in a couple more places 2020-02-13 17:44:16 -05:00
Brown
1c42875179 Support lowercase-string and warn about unnecessary calls to strtolower 2020-02-13 16:38:58 -05:00
Brown
f141f7c526 Improve --diff checks by including trait-using classes in dependents 2020-02-11 16:39:33 -05:00
Matthew Brown
bbdb1254ad Add line break 2020-02-05 08:51:11 -05:00
Lars Moelleken
759cfe4555 add more impure function calls 2020-02-05 08:51:11 -05:00
Brown
4c83ca75b3 Fix #2738 - clear out property issues when modifying constructors 2020-02-03 16:43:25 -05:00