Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
root@2fde6041ad38:/app# vendor/bin/psalm public/test.php Target PHP version: 8.1 (inferred from current PHP version) Scanning files... Analyzing files... E ERROR: UndefinedPropertyFetch - public/test.php:29:1 - Instance property ServiceB::$serviceAProperty is not defined (see https://psalm.dev/039) $serviceLocator->getService(ServiceB::class)->serviceAProperty; ERROR: InvalidScalarArgument - public/test.php:88:28 - Argument 1 of CallbackExecutor::execute expects callable(int):string, pure-Closure(string):float provided (see https://psalm.dev/012) $callbackExecutor->execute(fn(string $value) => (float) $value, 1); ------------------------------ 2 errors found ------------------------------ 3 other issues found. You can display them with --show-info=true ------------------------------ Psalm can automatically fix 1 of these issues. Run Psalm again with --alter --issues=MissingReturnType --dry-run to see what it can fix. ------------------------------ Checks took 0.49 seconds and used 75.842MB of memory Psalm was able to infer types for 98.6486% of the codebase
In theory, everything looks nice. There is only one small problem - PHP does not have built-in generic types. Although a few years ago there was the RFC, but it was not implemented. Fortunately, there are tools for static code analysis, such as Psalm or PHPStan, which, by reading appropriate annotations in the code, are able to imitate the generic types.
Related posts
- [Laravel] Maintenant que PHPStorm prend en charge le Psaume et le PHPSTAN, lequel utilisez-vous / recommandez-vous pour les projets Laravel?
- TIL how PHP type hinting works
- Valinor — Object mapper with strong type support and error handling
- Ask HN: Best PHP tools to improve code quality?
- PhpStorm 2022.1 EAP #3: Enhanced Array Shapes