Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update master #8024

Merged
merged 142 commits into from May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
87d9a01
Add configuration for maximum size of shaped array
danog Jan 19, 2022
e198012
Fix #3036: make argument $read of internal PHP function stream_socket…
Feb 22, 2022
b43c4af
Cast the read streams to an array while looping over as it can be NULL.
Feb 22, 2022
9a95ba9
Also update the historical CallMap to be aligned with latest changes …
Feb 22, 2022
9666b90
Register openssl_sign function to impure functions
samsonasik Mar 2, 2022
e1997c9
Merge pull request #7746 from samsonasik/patch-1
orklah Mar 2, 2022
8fc41e6
update phpredis stubs
kkmuffme Mar 4, 2022
d24b32b
Merge pull request #7752 from kkmuffme/patch-1
orklah Mar 4, 2022
a57bb1f
fix #7747: DateInterval::createFromDateString can be false
Ne-Lexa Mar 5, 2022
ff195e7
Allow null to ArrayAccess::offsetSet $offset param
franmomu Mar 6, 2022
d48965d
add failing test
mtk3d Mar 6, 2022
88d49b9
provide array column type for null column
mtk3d Mar 6, 2022
70abbbe
refactor array column test
mtk3d Mar 6, 2022
56e65fd
skip creating unnecessary union
mtk3d Mar 6, 2022
7a43baa
fixed return type in the historical callmap
Ne-Lexa Mar 6, 2022
a134b25
Merge pull request #7758 from Ne-Lexa/fix-dateinterfal-false
orklah Mar 6, 2022
d53f57b
wrap row in union again
mtk3d Mar 6, 2022
19ac150
Merge pull request #7759 from franmomu/fix_array_access_offsetset
orklah Mar 6, 2022
483d359
check is value for sure is null
mtk3d Mar 7, 2022
cd1b155
test if the type of second argument is not uncertain
mtk3d Mar 7, 2022
769e316
Merge pull request #7760 from mtk3d/fix/array_column_type_inference
orklah Mar 7, 2022
2a9ea7e
Support Stringable before PhpToken autoloading
muglug Mar 7, 2022
510456c
Improve scoping a bit more
muglug Mar 7, 2022
0dc4354
Replace changes in the CallMap for stream_select by a stub.
Mar 11, 2022
cf1f375
Remove useless array casting as CallMap for stream_select is reset.
Mar 11, 2022
a7e98f4
Forbid any non literal int in int range (except min and max named obj…
fluffycondor Mar 11, 2022
9beb0a6
Forbid min bound greater than max bound in int range
fluffycondor Mar 11, 2022
6bc90fa
Fix error messages
fluffycondor Mar 11, 2022
cb52314
Make error message more verbose
fluffycondor Mar 11, 2022
7240f01
Code style
fluffycondor Mar 11, 2022
c1ad5f6
Merge pull request #7775 from fluffycondor/improve-int-range-parsing
orklah Mar 12, 2022
7cfb601
Merge pull request #7718 from niconoe-/fix-3036
orklah Mar 13, 2022
0ab9470
#7784 PDOStatement::fetchAll() has incorrect type
jack-worman Mar 14, 2022
88f9e19
#7784 PDOStatement::fetchAll() has incorrect type
jack-worman Mar 14, 2022
08d4d79
More attribute fixes.
AndrolGenhald Mar 14, 2022
05d253b
Merge pull request #7785 from hc-jworman/#7784_PDOStatement_fetchAll(…
orklah Mar 14, 2022
11f51f4
Use key-of instead of literal int union.
AndrolGenhald Mar 14, 2022
32f10c3
Merge pull request #7788 from AndrolGenhald/attribute-analysis-improv…
orklah Mar 14, 2022
d4170fe
Add documentation for maxStringLength and maxShapedArraySize configs
danog Mar 15, 2022
b00d9e9
Add test case reproducing issue #7771
ohader Mar 15, 2022
2b37536
Avoid json_encode when serializing non-UTF8 literals
ohader Mar 15, 2022
e7ec124
Add documentation for maxStringLength and maxShapedArraySize configs
danog Mar 15, 2022
ebffd52
Merge pull request #7433 from zoonru/maximum_shaped_array_size
orklah Mar 15, 2022
9e4e468
Adjust test case format
ohader Mar 16, 2022
80f972c
Merge pull request #7791 from ohader/issue-7771-4x
orklah Mar 16, 2022
0b39384
Add return shape for Throwable::getTrace
ciaranmcnulty Mar 17, 2022
ca185d7
Update Throwable::getTrace in stubs
ciaranmcnulty Mar 17, 2022
70166bd
Fix disabling of appveyor auto build
gndk Mar 18, 2022
b4ae3a9
Merge pull request #7798 from ciaranmcnulty/get-trace-stubs
orklah Mar 18, 2022
c749811
Merge pull request #7801 from gndk/fix-appveyor-disable
orklah Mar 18, 2022
9c91912
Fix ftp_fget/_fput/_nb_fget/_nb_fput arg types
mrardon Mar 28, 2022
05a3806
Merge pull request #7824 from mrardon/fix-ftp-args
orklah Mar 29, 2022
0bdf942
Fix namespaced min/max int range keyword issue introduced in #7775.
AndrolGenhald Mar 30, 2022
1fc5c1c
Merge pull request #7829 from AndrolGenhald/bugfix/int-range-namespac…
orklah Mar 31, 2022
a696e55
Treat readline functions as impure
mstilkerich Apr 1, 2022
c209c66
Merge pull request #7828 from mstilkerich/impure_readline
orklah Apr 1, 2022
e87c25c
Second attempt of #7835
ThomasLandauer Apr 2, 2022
3729c0d
Sort types when intersection is used
VincentLanglet Apr 2, 2022
590ac22
Use another strategy
VincentLanglet Apr 3, 2022
587039f
Fixing CS
ThomasLandauer Apr 3, 2022
ab26e6b
Merge pull request #7837 from ThomasLandauer/pr-7835
orklah Apr 3, 2022
f4f1a26
Document `@psalm-yield`
jrmajor Apr 7, 2022
e1fe116
Remove documented annotations from wall of shame
jrmajor Apr 7, 2022
23ad8d6
Fix typos
jrmajor Apr 7, 2022
ab1ae8f
Merge pull request #7849 from jrmajor/docs
orklah Apr 7, 2022
ce25b39
Document `@psalm-ignore-variable-*`
jrmajor Apr 7, 2022
eeb12bc
Merge pull request #7851 from jrmajor/docs/ignore-var
orklah Apr 9, 2022
48bc030
Add test
VincentLanglet Apr 9, 2022
6d0cc07
Merge pull request #7838 from VincentLanglet/sortTypes
orklah Apr 10, 2022
e7c2c77
Disable filepath formatting as a link for Drone CI's output
white43 Apr 11, 2022
c6d7bc0
Improve Throwable::getTrace() return type
hirokinoue Apr 12, 2022
f04945c
Merge pull request #7864 from hirokinoue/precise-get-trace
orklah Apr 12, 2022
161a8ae
Fix openssl_csr_export() signature
mpesari Apr 13, 2022
bbfcf02
Merge pull request #7866 from mpesari/4.x
orklah Apr 13, 2022
338faa9
Merge pull request #7861 from white43/drone-ci-output
orklah Apr 13, 2022
23c3d87
don't emit issues when doing arithmetics on float templates
hirokinoue Apr 15, 2022
a99532d
code format
hirokinoue Apr 15, 2022
b132c3b
fix error message
hirokinoue Apr 15, 2022
a525342
add test case
hirokinoue Apr 15, 2022
1dc2b3b
cache statements even without persistent parser cache
vognev Apr 18, 2022
6afdb0d
better type safety and inference
vognev Apr 18, 2022
55a45a9
Merge pull request #7876 from vognev/feature/vendor-cache
orklah Apr 18, 2022
2724c1d
Merge pull request #7872 from hirokinoue/float-template-arithmetics-4.x
orklah Apr 19, 2022
b2d357f
Fix return type of `ldap_search`
paulfedorow Apr 23, 2022
37c53ee
handle the non-empty case for sort()
hirokinoue Apr 23, 2022
63faa0c
test the correct function
hirokinoue Apr 23, 2022
3a6ebbb
add test case for sort()
hirokinoue Apr 23, 2022
e91e33c
Merge pull request #7894 from paulfedorow/ldap-search-callmap-fix-4.x
orklah Apr 24, 2022
cb10e84
improve LSP
ging-dev Apr 25, 2022
70b44d5
Alter order of baseline option operations to allow updating custom ba…
M1ke Apr 26, 2022
5c8f40c
Merge pull request #7904 from M1ke/4.x-update-baseline-custom
orklah Apr 26, 2022
038947e
Merge pull request #7887 from ging-dev/lsp-fixes
orklah Apr 26, 2022
fe0470a
Remove latest PHPUnit from 4.x projects
muglug Apr 27, 2022
9c153de
Fix LSP api discrepancies
muglug Apr 27, 2022
0770f01
improve syntax
hirokinoue Apr 28, 2022
1605b18
handle the non-empty case for rsort()
hirokinoue Apr 28, 2022
db565f1
add test case for rsort()
hirokinoue Apr 28, 2022
95b5e8c
handle the non-empty case for shuffle()
hirokinoue Apr 28, 2022
c7b9e1e
add test case for shuffle()
hirokinoue Apr 28, 2022
37bf36d
handle the non-empty case for uasort()
hirokinoue Apr 28, 2022
d4470cc
add test case for uasort()
hirokinoue Apr 28, 2022
8c64bdd
handle the non-empty case for uksort()
hirokinoue Apr 28, 2022
139948e
add test case for uksort()
hirokinoue Apr 28, 2022
2b34b12
handle the non-empty case for usort()
hirokinoue Apr 28, 2022
4bb5c38
add test case for usort()
hirokinoue Apr 28, 2022
f1fe6ff
Merge pull request #7908 from hirokinoue/fix-sort-assert-annotation
orklah Apr 28, 2022
9b2cf43
fix small error in plugins_type_system.md
mathroc May 2, 2022
90d2b3c
Merge pull request #7914 from mathroc/patch-2
orklah May 8, 2022
6f3ceea
Remove several unused use statements
theodorejb May 9, 2022
4eef964
Infer object shape when array or scalar is cast to object
theodorejb May 9, 2022
3c837e5
fix missing is_a() parameter type
staabm May 12, 2022
b37da4a
Merge pull request #7951 from staabm/patch-4
orklah May 12, 2022
3929d73
Merge pull request #7935 from theodorejb/improve-object-casts
orklah May 14, 2022
e700524
add test case for implode()
hirokinoue May 14, 2022
91640e7
improve @return annotation of implode()
hirokinoue May 14, 2022
4fc34d9
improve @return annotation of join()
hirokinoue May 14, 2022
894e4e4
Merge pull request #7967 from hirokinoue/fix_return_type
orklah May 17, 2022
f86b599
bugfix/#7912: Added stub for the APCu extension
KevinVanSonsbeek May 17, 2022
22080a1
bugfix/#7912: Added extension_loaded check for apcu and load internal…
KevinVanSonsbeek May 17, 2022
23eff58
bugfix/#7912: Add Iterator implements to stub
KevinVanSonsbeek May 17, 2022
5c1d95b
Merge pull request #7982 from KevinVanSonsbeek/bugfix/#7912-class-APC…
orklah May 18, 2022
afed93b
Fix conflict of option -c with shell completion
GromNaN May 19, 2022
50fb396
Merge pull request #7988 from GromNaN/completion
orklah May 20, 2022
e2aafde
Improve array_unique callmap stubs
mathroc May 17, 2022
4ce8a06
Merge pull request #7981 from mathroc/callmap/array_unique-improvements
orklah May 23, 2022
c1cef60
change cache hash type for better performance
kkmuffme May 22, 2022
acffb85
debug CI
kkmuffme May 24, 2022
ee6c105
Merge pull request #7997 from kkmuffme/change-cache-hash-type-for-bet…
orklah May 24, 2022
ed0db0f
igbinary_serialize code was missing in file
kkmuffme May 25, 2022
5d8b5d1
micro-optimize condition
kkmuffme May 25, 2022
06178d0
only load files once
kkmuffme May 25, 2022
278e877
dont strolower filename, since file names on linux are case sensitive
kkmuffme May 25, 2022
48db4f2
Merge pull request #8009 from kkmuffme/microoptimize-phpversion-check…
weirdan May 26, 2022
d94f56a
Merge pull request #8007 from kkmuffme/add-missing-igbinary-serialize…
orklah May 26, 2022
06d8e3e
Merge pull request #8011 from kkmuffme/performance-only-load-files-once
orklah May 26, 2022
e0acf22
Merge branch '4.x' into update-master
weirdan May 28, 2022
ff50516
Post-merge fixes
weirdan May 28, 2022
de49946
Update empty list/array notation
weirdan May 28, 2022
242ee34
CS fix
weirdan May 28, 2022
5d21ff9
Suppress false posisitives
weirdan May 28, 2022
fce4272
PHP 7.4 fixes
weirdan May 28, 2022
9784fe4
Use lowest supported PHP version for shepherd run
weirdan May 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/shepherd.yml
Expand Up @@ -8,6 +8,9 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Expand Up @@ -36,8 +36,7 @@
"sebastian/diff": "^4.0",
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0 || ^6.0",
"symfony/filesystem": "^5.4 || ^6.0",
"symfony/polyfill-php80": "^1.25",
"webmozart/path-util": "^2.3"
"symfony/polyfill-php80": "^1.25"
},
"provide": {
"psalm/psalm": "self.version"
Expand Down
4 changes: 3 additions & 1 deletion dictionaries/CallMap.php
Expand Up @@ -418,7 +418,9 @@
'array_uintersect_assoc\'1' => ['associative-array', 'array'=>'array', 'rest'=>'array', 'arr3'=>'array', 'arg4'=>'array|callable', '...rest='=>'array|callable(mixed,mixed):int'],
'array_uintersect_uassoc' => ['associative-array', 'array'=>'array', 'rest'=>'array', 'data_compare_func'=>'callable(mixed,mixed):int', 'key_compare_func'=>'callable(mixed,mixed):int'],
'array_uintersect_uassoc\'1' => ['associative-array', 'array'=>'array', 'rest'=>'array', 'arr3'=>'array', 'arg4'=>'array|callable(mixed,mixed):int', 'arg5'=>'array|callable(mixed,mixed):int', '...rest='=>'array|callable(mixed,mixed):int'],
'array_unique' => ['associative-array', 'array'=>'array', 'flags='=>'int'],
'array_unique' => ['array', 'array'=>'array', 'flags='=>'0'],
'array_unique\'1' => ['array<int|float|string|null>', 'array'=>'array<int|float|string|null>', 'flags='=>'1'],
'array_unique\'2' => ['array<int|float|string|bool|\Stringable|null>', 'array'=>'array<int|float|string|bool|\Stringable|null>', 'flags='=>'2|5'],
'array_unshift' => ['int', '&rw_array'=>'array', 'values'=>'mixed', '...vars='=>'mixed'],
'array_values' => ['list<mixed>', 'array'=>'array'],
'array_walk' => ['bool', '&rw_array'=>'array', 'callback'=>'callable', 'arg='=>'mixed'],
Expand Down
4 changes: 3 additions & 1 deletion dictionaries/CallMap_historical.php
Expand Up @@ -9561,7 +9561,9 @@
'array_uintersect_assoc\'1' => ['associative-array', 'array'=>'array', 'rest'=>'array', 'arr3'=>'array', 'arg4'=>'array|callable', '...rest='=>'array|callable(mixed,mixed):int'],
'array_uintersect_uassoc' => ['associative-array', 'array'=>'array', 'rest'=>'array', 'data_compare_func'=>'callable(mixed,mixed):int', 'key_compare_func'=>'callable(mixed,mixed):int'],
'array_uintersect_uassoc\'1' => ['associative-array', 'array'=>'array', 'rest'=>'array', 'arr3'=>'array', 'arg4'=>'array|callable(mixed,mixed):int', 'arg5'=>'array|callable(mixed,mixed):int', '...rest='=>'array|callable(mixed,mixed):int'],
'array_unique' => ['associative-array', 'array'=>'array', 'flags='=>'int'],
'array_unique' => ['array', 'array'=>'array', 'flags='=>'0'],
'array_unique\'1' => ['array<int|float|string|null>', 'array'=>'array<int|float|string|null>', 'flags='=>'1'],
'array_unique\'2' => ['array<int|float|string|bool|\Stringable|null>', 'array'=>'array<int|float|string|bool|\Stringable|null>', 'flags='=>'2|5'],
'array_unshift' => ['int', '&rw_array'=>'array', 'values'=>'mixed', '...vars='=>'mixed'],
'array_values' => ['list<mixed>', 'array'=>'array'],
'array_walk' => ['bool', '&rw_array'=>'array', 'callback'=>'callable', 'arg='=>'mixed'],
Expand Down
5 changes: 5 additions & 0 deletions src/Psalm/Config.php
Expand Up @@ -2130,6 +2130,11 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null):
$this->internal_stubs[] = $ext_phpredis_path;
}

if (extension_loaded('apcu')) {
$ext_apcu_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'ext-apcu.phpstub';
$this->internal_stubs[] = $ext_apcu_path;
}

foreach ($this->internal_stubs as $stub_path) {
if (!file_exists($stub_path)) {
throw new UnexpectedValueException('Cannot locate ' . $stub_path);
Expand Down
57 changes: 42 additions & 15 deletions src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php
Expand Up @@ -192,22 +192,42 @@ public static function analyze(
}

if ($stmt instanceof PhpParser\Node\Expr\Cast\Object_) {
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) {
$context->inside_general_use = $was_inside_general_use;

if (!self::checkExprGeneralUse($statements_analyzer, $stmt, $context)) {
return false;
}
$context->inside_general_use = $was_inside_general_use;

$type = new Union([new TNamedObject('stdClass')]);
$permissible_atomic_types = [];
$all_permissible = false;

$maybe_type = $statements_analyzer->node_data->getType($stmt->expr);
if ($stmt_expr_type = $statements_analyzer->node_data->getType($stmt->expr)) {
if ($stmt_expr_type->isObjectType()) {
self::handleRedundantCast($stmt_expr_type, $statements_analyzer, $stmt);
}

$all_permissible = true;

foreach ($stmt_expr_type->getAtomicTypes() as $type) {
if ($type instanceof Scalar) {
$objWithProps = new TObjectWithProperties(['scalar' => new Union([$type])]);
$permissible_atomic_types[] = $objWithProps;
} elseif ($type instanceof TKeyedArray) {
$permissible_atomic_types[] = new TObjectWithProperties($type->properties);
} else {
$all_permissible = false;
break;
}
}
}

if ($permissible_atomic_types && $all_permissible) {
$type = TypeCombiner::combine($permissible_atomic_types);
} else {
$type = Type::getObject();
}

if ($statements_analyzer->data_flow_graph instanceof VariableUseGraph
) {
$type->parent_nodes = $maybe_type->parent_nodes ?? [];
$type->parent_nodes = $stmt_expr_type->parent_nodes ?? [];
}

$statements_analyzer->node_data->setType($stmt, $type);
Expand All @@ -216,14 +236,9 @@ public static function analyze(
}

if ($stmt instanceof PhpParser\Node\Expr\Cast\Array_) {
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) {
$context->inside_general_use = $was_inside_general_use;

if (!self::checkExprGeneralUse($statements_analyzer, $stmt, $context)) {
return false;
}
$context->inside_general_use = $was_inside_general_use;

$permissible_atomic_types = [];
$all_permissible = false;
Expand Down Expand Up @@ -466,6 +481,18 @@ public static function castStringAttempt(
return $str_type;
}

private static function checkExprGeneralUse(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Expr\Cast $stmt,
Context $context
): bool {
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;
$retVal = ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context);
$context->inside_general_use = $was_inside_general_use;
return $retVal;
}

private static function handleRedundantCast(
Union $maybe_type,
StatementsAnalyzer $statements_analyzer,
Expand Down
5 changes: 0 additions & 5 deletions src/Psalm/Internal/Cli/Plugin.php
Expand Up @@ -9,7 +9,6 @@
use Psalm\Internal\PluginManager\Command\ShowCommand;
use Psalm\Internal\PluginManager\PluginListFactory;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;

use function dirname;
use function getcwd;
Expand Down Expand Up @@ -44,10 +43,6 @@ public static function run(): void
new DisableCommand($plugin_list_factory),
]);

$app->getDefinition()->addOption(
new InputOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to Psalm config file')
);

$app->setDefaultCommand('show');
$app->run();
}
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Internal/Codebase/Reflection.php
Expand Up @@ -419,6 +419,7 @@ public function registerFunction(string $function_id): ?bool
return null;
}

/** @psalm-suppress UndefinedClass,TypeDoesNotContainType 7.4 has no ReflectionUnionType */
public static function getPsalmTypeFromReflectionType(?ReflectionType $reflection_type = null): Union
{
if (!$reflection_type) {
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/LanguageServer/LanguageServer.php
Expand Up @@ -418,7 +418,7 @@ public function emitIssues(array $uris): void
} else {
// the Diagnostic constructor only takes `int` for the code, but the property can be
// `int` or `string`, so we set the property directly because we want to use a `string`
/** @psalm-suppress InvalidPropertyAssignmentValue */
/** @psalm-suppress InvalidPropertyAssignmentValue */
$diagnostic->code = $code;
}

Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/LanguageServer/Server/TextDocument.php
Expand Up @@ -380,7 +380,6 @@ public function codeAction(TextDocumentIdentifier $textDocument, Range $range):
$indentation = $matches[1] ?? '';
}


/**
* Suppress Psalm because ther are bugs in how
* LanguageServer's signature of WorkspaceEdit is declared:
Expand Down
2 changes: 2 additions & 0 deletions src/Psalm/Internal/PluginManager/Command/DisableCommand.php
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use UnexpectedValueException;
Expand Down Expand Up @@ -41,6 +42,7 @@ protected function configure(): void
InputArgument::REQUIRED,
'Plugin name (fully qualified class name or composer package name)'
)
->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to Psalm config file')
->addUsage('vendor/plugin-package-name [-c path/to/psalm.xml]');
$this->addUsage('\'Plugin\Class\Name\' [-c path/to/psalm.xml]');
}
Expand Down
2 changes: 2 additions & 0 deletions src/Psalm/Internal/PluginManager/Command/EnableCommand.php
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use UnexpectedValueException;
Expand Down Expand Up @@ -41,6 +42,7 @@ protected function configure(): void
InputArgument::REQUIRED,
'Plugin name (fully qualified class name or composer package name)'
)
->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to Psalm config file')
->addUsage('vendor/plugin-package-name [-c path/to/psalm.xml]');
$this->addUsage('\'Plugin\Class\Name\' [-c path/to/psalm.xml]');
}
Expand Down
2 changes: 2 additions & 0 deletions src/Psalm/Internal/PluginManager/Command/ShowCommand.php
Expand Up @@ -5,6 +5,7 @@
use Psalm\Internal\PluginManager\PluginListFactory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use UnexpectedValueException;
Expand Down Expand Up @@ -37,6 +38,7 @@ protected function configure(): void
$this
->setName('show')
->setDescription('Lists enabled and available plugins')
->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to Psalm config file')
->addUsage('[-c path/to/psalm.xml]');
}

Expand Down
12 changes: 9 additions & 3 deletions src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php
Expand Up @@ -13,17 +13,18 @@
use function file_put_contents;
use function filemtime;
use function get_class;
use function hash;
use function igbinary_serialize;
use function igbinary_unserialize;
use function is_dir;
use function mkdir;
use function serialize;
use function sha1;
use function strtolower;
use function unlink;
use function unserialize;

use const DIRECTORY_SEPARATOR;
use const PHP_VERSION_ID;

/**
* @internal
Expand Down Expand Up @@ -111,7 +112,8 @@ public function getLatestFromCache(

private function getCacheHash(?string $file_path, ?string $file_contents): string
{
return sha1(($file_path ? $file_contents : '') . $this->modified_timestamps);
$data = ($file_path ? $file_contents : '') . $this->modified_timestamps;
return PHP_VERSION_ID >= 8_01_00 ? hash('xxh128', $data) : hash('md4', $data);
}

/**
Expand Down Expand Up @@ -161,9 +163,13 @@ private function getCacheLocationForClass(
mkdir($parser_cache_directory, 0777, true);
}

$data = $file_path ? strtolower($file_path) . ' ' : '';
$data .= $fq_classlike_name_lc;
$file_path_sha = PHP_VERSION_ID >= 8_01_00 ? hash('xxh128', $data) : hash('md4', $data);

return $parser_cache_directory
. DIRECTORY_SEPARATOR
. sha1(($file_path ? strtolower($file_path) . ' ' : '') . $fq_classlike_name_lc)
. $file_path_sha
. ($this->config->use_igbinary ? '-igbinary' : '');
}
}
11 changes: 5 additions & 6 deletions src/Psalm/Internal/Provider/FakeFileProvider.php
Expand Up @@ -4,7 +4,6 @@

use function microtime;
use function strpos;
use function strtolower;

/**
* @internal
Expand All @@ -28,8 +27,8 @@ public function fileExists(string $file_path): bool

public function getContents(string $file_path, bool $go_to_source = false): string
{
if (!$go_to_source && isset($this->temp_files[strtolower($file_path)])) {
return $this->temp_files[strtolower($file_path)];
if (!$go_to_source && isset($this->temp_files[$file_path])) {
return $this->temp_files[$file_path];
}

return $this->fake_files[$file_path] ?? parent::getContents($file_path);
Expand All @@ -42,8 +41,8 @@ public function setContents(string $file_path, string $file_contents): void

public function setOpenContents(string $file_path, string $file_contents): void
{
if (isset($this->fake_files[strtolower($file_path)])) {
$this->fake_files[strtolower($file_path)] = $file_contents;
if (isset($this->fake_files[$file_path])) {
$this->fake_files[$file_path] = $file_contents;
}
}

Expand All @@ -69,7 +68,7 @@ public function getFilesInDir(string $dir_path, array $file_extensions, callable
$file_paths = parent::getFilesInDir($dir_path, $file_extensions, $filter);

foreach ($this->fake_files as $file_path => $_) {
if (strpos(strtolower($file_path), strtolower($dir_path)) === 0) {
if (strpos($file_path, $dir_path) === 0) {
$file_paths[] = $file_path;
}
}
Expand Down