Skip to content

Commit 28cf922

Browse files
authored
Merge pull request #74 from WordPress/php-74-compat
Adds PHP 7.4 compatibility checking and fix violations
2 parents 4862079 + 31d0d80 commit 28cf922

File tree

5 files changed

+222
-3
lines changed

5 files changed

+222
-3
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"guzzlehttp/psr7": "^1.0 || ^2.0",
3535
"php-http/curl-client": "^2.0",
3636
"php-http/mock-client": "^1.0",
37+
"phpcompatibility/php-compatibility": "dev-develop",
3738
"phpstan/phpstan": "~2.1",
3839
"phpunit/phpunit": "^9.5 || ^10.0",
3940
"slevomat/coding-standard": "^8.20",

composer.lock

Lines changed: 191 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpcs.xml.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
<!-- Use PSR-12 standard -->
2222
<rule ref="PSR12"/>
2323

24+
<!-- Check PHP 7.4 compatibility -->
25+
<rule ref="PHPCompatibility">
26+
<!-- Exclude functions that are polyfilled in src/polyfills.php -->
27+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_is_listFound"/>
28+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_containsFound"/>
29+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_starts_withFound"/>
30+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_ends_withFound"/>
31+
</rule>
32+
2433
<!-- Enforce namespace best practices -->
2534
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse" />
2635
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash" />

src/Providers/Http/DTO/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function getUri(): string
114114
{
115115
// If GET request with data, append as query parameters
116116
if ($this->method === HttpMethodEnum::GET() && $this->data !== null && !empty($this->data)) {
117-
$separator = strpos($this->uri, '?') === false ? '?' : '&';
117+
$separator = str_contains($this->uri, '?') ? '&' : '?';
118118
return $this->uri . $separator . http_build_query($this->data);
119119
}
120120

src/polyfills.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ function str_starts_with(string $haystack, string $needle): bool
5757
}
5858
}
5959

60+
if (!function_exists('str_contains')) {
61+
/**
62+
* Checks if a string contains a given substring.
63+
*
64+
* @since n.e.x.t
65+
*
66+
* @param string $haystack The string to search in.
67+
* @param string $needle The substring to search for.
68+
* @return bool True if $haystack contains $needle, false otherwise.
69+
*/
70+
function str_contains(string $haystack, string $needle): bool
71+
{
72+
if ('' === $needle) {
73+
return true;
74+
}
75+
76+
return false !== strpos($haystack, $needle);
77+
}
78+
}
79+
6080
if (!function_exists('str_ends_with')) {
6181
/**
6282
* Checks if a string ends with a given substring.

0 commit comments

Comments
 (0)