From cddeb038c375f27f7c2bd3d18ea34408a9125861 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 12 Nov 2024 18:01:53 -0800 Subject: [PATCH] Add further PHPStan stubs for WordPress polyfills. --- composer.json | 2 +- composer.lock | 6 +++--- php-tools/lint/phpstan-stubs.php | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 3ecde99..6a5f4e0 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ }, "config": { "platform": { - "php": "7.2" + "php": "7.2.34" }, "allow-plugins": { "composer/installers": true diff --git a/composer.lock b/composer.lock index ff5109a..411227a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2fbeb7ede1b2e452efa78071ce4eb1c9", + "content-hash": "29eb23bc347800025fbb956df5c5e898", "packages": [ { "name": "composer/installers", @@ -216,9 +216,9 @@ "platform": { "php": ">=7.2" }, - "platform-dev": {}, + "platform-dev": [], "platform-overrides": { - "php": "7.2" + "php": "7.2.34" }, "plugin-api-version": "2.6.0" } diff --git a/php-tools/lint/phpstan-stubs.php b/php-tools/lint/phpstan-stubs.php index d94dc73..a919368 100644 --- a/php-tools/lint/phpstan-stubs.php +++ b/php-tools/lint/phpstan-stubs.php @@ -17,3 +17,25 @@ function str_starts_with( $haystack, $needle ) { return 0 === strpos( $haystack, $needle ); } } + +if ( ! function_exists( 'str_ends_with' ) ) { + function str_ends_with( $haystack, $needle ) { + if ( '' === $haystack ) { + return '' === $needle; + } + + $len = strlen( $needle ); + + return substr( $haystack, -$len, $len ) === $needle; + } +} + +if ( ! function_exists( 'str_contains' ) ) { + function str_contains( $haystack, $needle ) { + if ( '' === $needle ) { + return true; + } + + return false !== strpos( $haystack, $needle ); + } +}