Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build/composer-dependency-analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@
[ErrorType::UNUSED_DEPENDENCY],
)
->ignoreErrorsOnPackage('phpunit/phpunit', [ErrorType::DEV_DEPENDENCY_IN_PROD]) // prepared test tooling
->ignoreErrorsOnPackage('jetbrains/phpstorm-stubs', [ErrorType::PROD_DEPENDENCY_ONLY_IN_DEV]) // there is no direct usage, but we need newer version then required by ondrejmirtes/BetterReflection
->ignoreErrorsOnPath(__DIR__ . '/../tests', [ErrorType::UNKNOWN_CLASS, ErrorType::UNKNOWN_FUNCTION, ErrorType::SHADOW_DEPENDENCY]) // to be able to test invalid symbols
->ignoreUnknownClasses($unknownClasses);
14 changes: 11 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"hoa/compiler": "3.17.08.08",
"hoa/exception": "^1.0",
"hoa/file": "1.17.07.11",
"jetbrains/phpstorm-stubs": "dev-master#709e512210784a7c0a677b3a89d35def844a59b9",
"jetbrains/phpstorm-stubs": "dev-master#2da66a03e379335dba086b0d493c70185eb01ddd",
"nette/bootstrap": "^3.0",
"nette/di": "^3.1.10",
"nette/neon": "3.3.4",
Expand All @@ -35,7 +35,7 @@
"nette/utils": "^3.2.5",
"nikic/php-parser": "^5.8.0",
"ondram/ci-detector": "^4.0",
"ondrejmirtes/better-reflection": "6.70.0.3",
"ondrejmirtes/better-reflection": "dev-feat/versioned-extension-stubs as 6.70.0.4",
"ondrejmirtes/composer-attribute-collector": "^1.2.0",
"ondrejmirtes/php-merge": "^4.1",
"phpstan/php-8-stubs": "0.4.35",
Expand Down Expand Up @@ -80,6 +80,13 @@
"shipmonk/dead-code-detector": "^1.0.0",
"shipmonk/name-collision-detector": "^2.0"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/simPod/BetterReflection",
"no-api": true
}
],
"config": {
"platform": {
"php": "8.2.99"
Expand Down Expand Up @@ -136,7 +143,8 @@
"patches/ReflectionProperty.patch",
"patches/SessionHandler.patch",
"patches/xmlreader.patch",
"patches/dom_c.patch"
"patches/dom_c.patch",
"patches/conditional-function-throws.patch"
],
"nette/di": [
"patches/Resolver.patch"
Expand Down
63 changes: 45 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ parameters:
- ../stubs/iterable.stub
- ../stubs/ArrayObject.stub
- ../stubs/WeakReference.stub
- ../stubs/ext-ds.stub
- ../stubs/ImagickPixel.stub
- ../stubs/PDOStatement.stub
- ../stubs/date.stub
Expand Down
27 changes: 27 additions & 0 deletions patches/conditional-function-throws.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--- Core/Core.php
+++ Core/Core.php
@@ -660,8 +660,6 @@
* </p>
* @return bool This function returns false if wrong <i>error_type</i> is
* specified, true otherwise.
- * @throws \ValueError This function throws a ValueError if error_level is not one of E_USER_ERROR,
- * E_USER_WARNING, E_USER_NOTICE, E_USER_DEPRECATED.
*/
#[LanguageLevelTypeAware(['8.4' => 'true'], default: 'bool')]
function trigger_error(string $message, int $error_level = E_USER_NOTICE) {}
--- standard/standard_2.php
+++ standard/standard_2.php
@@ -337,13 +337,6 @@
* </p>
* @return string a string produced according to the formatting string
* format.
- * @throws \ValueError As of PHP 8.0.0, a ValueError is thrown if the number of arguments is zero.
- * Prior to PHP 8.0.0, a E_WARNING was emitted instead. As of PHP 8.0.0, a ValueError is thrown if
- * [width] is less than zero or bigger than PHP_INT_MAX. Prior to PHP 8.0.0, a E_WARNING was emitted
- * instead. As of PHP 8.0.0, a ValueError is thrown if [precision] is less than zero or bigger than
- * PHP_INT_MAX. Prior to PHP 8.0.0, a E_WARNING was emitted instead.
- * @throws \ArgumentCountError As of PHP 8.0.0, a ArgumentCountError is thrown when less arguments
- * are given than required. Prior to PHP 8.0.0, false was returned and a E_WARNING emitted instead.
*/
#[Pure]
function sprintf(
3 changes: 3 additions & 0 deletions src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use PHPStan\Internal\ArrayHelper;
use PHPStan\Internal\ComposerHelper;
use PHPStan\PhpDoc\StubFilesProvider;
use PHPStan\Reflection\BetterReflection\SourceStubber\ExtensionVersionProvider;
use PHPStan\ShouldNotHappenException;
use ReflectionClass;
use ReflectionException;
Expand Down Expand Up @@ -99,6 +100,7 @@ public function __construct(
private StubFilesProvider $stubFilesProvider,
private FileHelper $fileHelper,
private PackageDependencyResolver $packageDependencyResolver,
private ExtensionVersionProvider $extensionVersionProvider,
#[AutowiredParameter(ref: '%resultCachePath%')]
private string $cacheFilePath,
#[AutowiredParameter]
Expand Down Expand Up @@ -1525,6 +1527,7 @@ private function getMeta(array $allAnalysedFiles, ?array $projectConfigArray): a
'composerInstalled' => $this->getComposerInstalled(),
'executedFilesHashes' => $this->getExecutedFileHashes(),
'phpExtensions' => $extensions,
'extensionVersions' => $this->extensionVersionProvider->getExtensionVersions(),
'stubFiles' => $this->getStubFiles(),
'level' => $this->usedLevel,
];
Expand Down
19 changes: 17 additions & 2 deletions src/PhpDoc/DefaultStubFilesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPStan\File\FileHelper;
use PHPStan\Internal\ComposerHelper;
use function array_filter;
use function array_map;
use function array_values;
use function dirname;
use function str_contains;
Expand Down Expand Up @@ -48,9 +47,25 @@ public function getStubFiles(): array
return $this->cachedFiles;
}

$files = array_map(fn ($path) => $this->fileHelper->normalizePath($path), $this->stubFiles);
$files = [];
$extensions = $this->stubFilesExtensions->getAll();
foreach ($extensions as $extension) {
if (!$extension instanceof PredefinedStubFilesExtension) {
continue;
}

foreach ($extension->getFiles() as $extensionFile) {
$files[] = $this->fileHelper->normalizePath($extensionFile);
}
}
foreach ($this->stubFiles as $stubFile) {
$files[] = $this->fileHelper->normalizePath($stubFile);
}
foreach ($extensions as $extension) {
if ($extension instanceof PredefinedStubFilesExtension) {
continue;
}

foreach ($extension->getFiles() as $extensionFile) {
$files[] = $this->fileHelper->normalizePath($extensionFile);
}
Expand Down
26 changes: 26 additions & 0 deletions src/PhpDoc/ExtDsStubFilesExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types = 1);

namespace PHPStan\PhpDoc;

use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\Reflection\BetterReflection\SourceStubber\ExtensionVersionProvider;

#[AutowiredService]
final class ExtDsStubFilesExtension implements PredefinedStubFilesExtension
{

public function __construct(private ExtensionVersionProvider $extensionVersionProvider)
{
}

public function getFiles(): array
{
$version = $this->extensionVersionProvider->getExtensionVersions()['ds'] ?? null;
if ($version !== null && $version !== 1) {
return [];
}

return [__DIR__ . '/../../stubs/ext-ds.stub'];
}

}
9 changes: 9 additions & 0 deletions src/PhpDoc/PredefinedStubFilesExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types = 1);

namespace PHPStan\PhpDoc;

/** @internal */
interface PredefinedStubFilesExtension extends StubFilesExtension
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function __construct(
private Cache $cache,
private PhpVersion $phpVersion,
private PhpStormStubsSourceStubber $phpstormStubsSourceStubber,
private SourceStubber\ExtensionVersionProvider $extensionVersionProvider,
private ReflectionSourceStubber $reflectionSourceStubber,
private OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository,
private OptimizedDirectorySourceLocatorRepository $optimizedDirectorySourceLocatorRepository,
Expand Down Expand Up @@ -188,6 +189,7 @@ public function create(): SourceLocator
new PhpInternalSourceLocator($astPhp8Locator, $this->phpstormStubsSourceStubber),
$this->cache,
$this->phpVersion,
$this->extensionVersionProvider,
));

// Custom autoloaders registered *after* Composer's class loader are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPStan\Cache\Cache;
use PHPStan\Internal\ComposerHelper;
use PHPStan\Php\PhpVersion;
use PHPStan\Reflection\BetterReflection\SourceStubber\ExtensionVersionProvider;
use function array_key_exists;
use function is_array;
use function is_file;
Expand All @@ -34,8 +35,8 @@
* entry, and shared across a run's parallel workers through the arena.
*
* The stubber's output depends on the stubs package, the reflection library
* and the target PHP version (stub members are version-filtered), so all
* three are part of the cache key.
* and the target PHP and extension versions (stub members are version-filtered),
* so all four are part of the cache key.
*
* The exported blob contains the absolute path of the stub file, but the
* cache key deliberately contains no paths - the same entries are shared by
Expand All @@ -59,6 +60,7 @@ public function __construct(
private SourceLocator $inner,
private Cache $cache,
private PhpVersion $phpVersion,
private ExtensionVersionProvider $extensionVersionProvider,
)
{
}
Expand Down Expand Up @@ -162,10 +164,11 @@ public function locateIdentifiersByType(Reflector $reflector, IdentifierType $id
private function getVariableCacheKey(): string
{
return $this->variableCacheKey ??= sprintf(
'v2-%s-%s-%s',
'v3-%s-%s-%s-%s',
ComposerHelper::getBetterReflectionVersion(),
ComposerHelper::getPhpStormStubsVersion(),
$this->phpVersion->getVersionString(),
$this->extensionVersionProvider->getCacheKey(),
);
}

Expand Down
Loading
Loading