1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00
Commit Graph

363 Commits

Author SHA1 Message Date
Kamil Tekiela
098238ff7f Create test for count_chars 2021-12-08 22:57:32 +00:00
marcosh
9c4187fd2f fix abs tests 2021-12-07 12:00:52 +01:00
ralila
8fb2e0f885 Handle some partials 2021-12-04 21:55:53 +01:00
ralila
245920e53c Import instead of using fqn 2021-12-03 20:11:20 +01:00
orklah
a7e9eea0ca
flag usage of get_class outside class without args (#7043) 2021-12-02 00:38:45 +02:00
ralila
9a7d0809d2 Restrict tests with PREG_UNMATCHED_AS_NULL to PHP >= 7.2 2021-11-30 03:29:41 +01:00
ralila
c29e943244 Add some tests 2021-11-30 03:19:27 +01:00
ralila
e5c1a35e31 Adjust tests 2021-11-29 14:24:15 +01:00
Bruce Weirdan
f5b71a3a5f
Infer mb_strtolower() result as string when encoding is specified
`mb_strtolower()` may return characters we generally consider uppercase
when it's given the encoding argument. This PR makes Psalm to err on the
side of caution and treat the return type as `string` rather than
`lowercase-string` in this case

Refs vimeo/psalm#6908
2021-11-14 03:57:10 +02:00
sasezaki
e3c6464a91 accept ::class constant strings for literal argument 2021-11-03 13:44:14 +09:00
orklah
ce87fc4882 fix is_a when used with Stringable classes 2021-10-28 20:08:43 +02:00
orklah
fb8b07613d Allow sending possibly_undefined inputs to optional params 2021-10-10 12:44:04 +02:00
orklah
682784c886 array_is_list on empty array returns true 2021-10-08 17:05:35 +02:00
orklah
f641d9e95a assert that some type is a list 2021-10-02 10:02:22 +02:00
orklah
4c6f43884c fix test 2021-09-29 22:55:01 +02:00
orklah
2a2e7c5e32 prevent object leaking that lead to changes in callmap 2021-09-29 22:27:34 +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
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
orklah
0bd8b03f7a Fix usage of gettype in a switch with closed resource 2021-07-14 12:49:46 +02:00
orklah
688367de38 Always emit InvalidArgument when the parameter is always false and not accepted 2021-07-13 00:06:36 +02: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
Bruce Weirdan
689315b05f
Fix sscanf() signature (#5901)
Fixes vimeo/psalm#5870
2021-06-07 13:19:17 -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
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
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
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
Marco Pivetta
a53cc23809
#4997 added more precise type inference for count() returning 0 or positive-int on known arrays (#4999)
* #4997 added more precise stub for `count()` returning `0` or `positive-int` on known types

* #4997 updated `count()` to support `\SimpleXmlElement` and `\ResourceBundle` counting, as well as handling hardcoded 2-element-arrays cases

This patch:

 * adds support for `count(\SimpleXmlElement)` (https://www.php.net/manual/en/simplexmlelement.count.php)
 * adds support for `count(\ResourceBundle)` (https://www.php.net/manual/en/resourcebundle.count.php)
 * removes usage of global constants from stub (not supported - see https://www.php.net/manual/en/function.count.php)
 * adds support for identifying fixed-element-count arrays, for example `count(callable&array)`, which is always `2`

* #4997 adapted `FunctionCallReturnTypeFetcher` to infer `TPositiveInt` for `count(TNonEmptyArray)` and `count(TNonEmptyList)`

* The `FunctionCallReturnTypeFetcher` is responsible for defining the precise type of a `\count(T)`
expression when given a `T`, so we baked the whole type resolution for `positive-int`, `0` and
`positive-int|0` directly in there.

While this complicates things, it is also true that it is not possible right now (for the stubs)
to provide the level of detail around `count()` that is required by the type inference system
for such a complex function with so many different semantics.
2021-01-13 09:48:38 -05:00
Matt Brown
05e319a6ed Fix #4827 - don’t eradicate double after int check 2020-12-14 23:08:07 -05:00
orklah
5222cadfb3
Check from_docblock property to emit the right issue (#4736) 2020-11-29 21:40:13 -05:00
Matt Brown
0c477da310 Fix test failures 2020-11-25 20:05:09 -05:00
Marcus Bointon
e172e88274
Fix preg_match_all stub (#4325)
* preg_match_all can return false

* Test for preg_match_all returning false

* Fix test

* Add @psalm-ignore-falsable-return
2020-10-14 19:59:07 -04:00
Matt Brown
864a7bbb4c Add better support for get_debug_type 2020-10-14 17:30:08 -04:00
Matt Brown
bb7d7132f7 Do arithmetic for preg_split arguments 2020-10-12 20:26:02 -04:00
Matt Brown
464795d86c Fix #4309 - improve reuse of callmap callable inference 2020-10-12 13:46:43 -04:00
Matt Brown
f83b50460a Add better return type for preg_split 2020-10-12 13:04:28 -04:00
Matt Brown
d8a74ca383 4.x - Prevent passing empty array to max or min 2020-10-12 12:09:12 -04:00
Matt Brown
7e65355513 4.x - detect falty !is_resource checks 2020-10-12 09:57:11 -04:00
Brown
56bae3b587 Add check for strpos dictionaries
Ref #4070
2020-09-13 21:42:44 -04:00
orklah
ead107fa9e
More return types (#4173)
* add native return types

* redundant phpdoc
2020-09-12 11:24:05 -04:00
Brown
eda426a594 Improve unique issue solution 2020-09-10 22:54:30 -04:00
Brown
aaede393d4 Fix #4070 - prevent literal strpos argument 2020-09-10 18:28:34 -04:00
Matthew Brown
3605eeee04 Support analysing preg_match_all args in reverse to infer matches type 2020-09-04 20:33:02 -04:00
Brown
d3d8c4ed87 Hard code possible bit-shift values 2020-09-04 18:31:50 -04:00
Brown
4d82d3ddad Fix #4128 - improve understanding of preg_match_all 2020-09-04 18:10:14 -04:00
Brown
92239add4d Add some backwards-incompatible changes for 4.x 2020-08-30 11:44:14 -04:00
Brown
c13b0efd49 Improve understanding of negated count queries 2020-08-30 11:32:01 -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
Bauke van der Woude
7ac6d2e5a4
Fix hash_*() signatures (#4014)
Functions can return false when an invalid algorithm is supplied
2020-08-18 09:35:31 -04:00
Matthew Brown
5c20a5295e Improve solution to #3964 2020-08-16 13:03:30 -04:00
Brown
ad1920c3a2 Fix #3910 - improve handling of fgetcsv 2020-07-30 14:21:55 -04:00
jarstelfox
3096afed99
Fix echo false issue (#3751)
* Echo: add failing test case

echo false; is a noop, not an issue

* Echo: Fix failing test case
2020-07-05 08:55:42 -04:00
Brown
9aa0aca949 Fix handling of coerced callmap args 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
orklah
72435757ea
Add false to possible parse_url return types (#3359) (#3445)
* Add false to possible parse_url return types (#3359)

* fix test
2020-05-24 09:19:58 -04:00
Brown
111303d913 Add non-empty-lowercase-string type 2020-05-15 10:18:05 -04:00
Brown
291018034b Remove unnecessary PHP code 2020-05-11 11:36:50 -04:00
Fabien Villepinte
5087feff79
Fix #2845 - FunctionReturnTypeProvider for sscanf (#3233)
Co-authored-by: Fabien Villepinte <fabien.villepinte@displayce.com>
2020-04-26 17:36:44 -04:00
still-dreaming-1
16fa208a60
Made compact's return array key type more specific (#3209) 2020-04-21 20:18:11 -04:00
Brown
2e4aaac5bb Add better inference for date calls 2020-04-14 21:07:44 -04:00
Brown
fea1310d67 Fix #3092 - round always returns a float 2020-04-09 23:31:26 -04:00
Brown
69045daea9 Convert a bunch of custom-handled functions to conditional stubbed ones 2020-04-07 16:48:29 -04:00
Brown
40345dd29c Remove json_encode test that no longer works 2020-04-04 18:02:28 -04:00
Brown
1bf1a6e46b Accept partial match of template type 2020-04-04 17:14:33 -04:00
Brown
1b01d7b356 Fix tests 2020-04-04 11:51:24 -04:00
Pavel Batečko
48af534270
Improve parse_url() return type (#2955) 2020-03-18 15:17:24 -04:00
Matthew Brown
0022de1f13 Fix #946 - allow too many arguments when one of union agrees 2020-03-15 13:44:00 -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
Thomas Gerbet
b40403d7b0 \sodium_memzero() sets to null the value of the given reference
While it is not mentionned in PHP manual \sodium_memzero() always sets
the given parameter to null [0].

[0] cb933d63c2/ext/sodium/libsodium.c (L512)
2020-03-03 19:34:20 -05:00
Matthew Brown
9bdca3c706 Forbid array<mixed, ...> 2020-02-21 01:26:51 -05:00
Brown
3d6c63bc08 Break apart FunctionCallTest 2020-01-31 13:58:02 -05:00
Matthew Brown
ce0298acc4 Fix #2704 - array_merge should ignore possibly-false issues where applicable 2020-01-29 21:09:33 -05:00
Matthew Brown
10221f474f Fix test 2020-01-27 23:52:06 -05:00
Matthew Brown
82bb3b90f0 Add @return to test 2020-01-27 23:38:31 -05:00
Brown
faf6afdce8 Support call_user_func evaluation
Fixes #726
2020-01-24 13:34:50 -05:00
Matthew Brown
24e1d5446c Fix #2642 - merging two explicit lists is still a list 2020-01-17 09:31:08 -05:00
Brown
1b551b805b Fix #2627 - infer arrow function effects for array_filter 2020-01-15 11:40:49 -05:00
Brown
eb7c3dcc11 Fix #2611 - fix combination of inferred closure return types 2020-01-13 10:23:58 -05:00
Matthew Brown
bd846123ce Fix #2560 - handle special case of array_filter on single-element array 2020-01-11 11:54:29 -05:00
Matthew Brown
40406c7ff0 Fix #2576 - remove literal key values if array_filter has no args 2020-01-11 11:48:22 -05:00
Pavel Batečko
702ca34c41 Improve array function types (#2566)
* Improve sorting function out types

* Improve return types of array_diff_assoc(), array_intersect_assoc()

* Fix versionCompareAsCallable test
2020-01-07 11:40:23 -05:00
Bruce Weirdan
7d3dd47efa Added support for preg_grep (#2523) 2019-12-29 11:05:08 -05:00
Valentin Udaltsov
006f788d6a Added array_fill_keys support (#2512)
* Added array_fill_keys support

* Removed unnecessary array_fill_keys phpdoc
2019-12-27 13:30:42 +00:00
Matthew Brown
456aa1c569 Fix #2468 - add support for zipping arrays 2019-12-18 18:14:02 +00:00
Matthew Brown
1d0ac3df29 Fix #2472 - array_map should retain non-emptiness when passed string callables 2019-12-15 14:06:12 -05:00
Matthew Brown
432c291dd7 Fix #2440 - add support for uasort 2019-12-08 21:30:19 -05:00
Valentin Udaltsov
4a742f9940 Added array_key_first and array_key_last stubs (#2381) 2019-11-27 10:59:12 -05:00
Matthew Brown
113bf921f6 Add support for arrow function inference 2019-11-27 10:12:59 -05:00
Pavel Batečko
4e594e0a65 Improve array function list handling (#2377)
* array_column() returns a list unless the 3rd arg is passed

* array_pad() return type provider

* array_chunk() return type provider

* array_map() preserve list types
2019-11-26 14:48:49 -05:00
Brown
5e17a9af10 Fix #2348 - ensure all functions and methods return some type 2019-11-14 14:44:29 -05:00
Joram Schrijver
c97ba8f713 Implement type-checking and forbidding for print (#2314)
* Add type-checking for print

* Allow print to be forbidden
2019-11-08 07:01:34 -05:00
Brown
e7330afe8b Fix #2295 - support special case of array_shift on known offset type 2019-11-04 09:21:13 -05:00
Pavel Batečko
b229ac875d Improve return types of explode() with limit (#2286) 2019-11-02 10:10:38 +01:00
Matthew Brown
05ace25817 Fix #2246 - fix return type of array_slice to be a list 2019-10-20 16:19:01 -04:00
Matthew Brown
b476761109 Fix #2235 - improve behaviour of array_merge on lists 2019-10-20 15:47:00 -04:00
lhchavez
216f991b0c Normalize stringified type names (#2239)
This change makes stringified types more normalized. Concretely it sorts
all union types, reconciled types, and sorts the keys within object-like
types.
2019-10-17 01:14:33 -04:00
Matthew Brown
1a1b3a10a9 Fix #2225 - iterator_to_array can return a list 2019-10-10 23:47:11 -04:00