Skip to content

Commit

Permalink
Change from str_contains to stripos
Browse files Browse the repository at this point in the history
  • Loading branch information
repat committed Jul 15, 2021
1 parent e0285f2 commit 3b53d22
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -95,6 +95,7 @@ $client->singleCall("GET", $guzzleParameterArray);

## Changelog

* 0.1.13 Change from [Laravels `str_contains`](https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Str.php#L181) to [PHPs `stripos()`](https://www.php.net/manual/de/function.stripos.php) because [it doesn't require `ext-mbstring`](https://github.com/repat/plentymarkets-rest-client/pull/16#issuecomment-880731813)
* 0.1.12 Remove `danielstjules/stringy` dependency, copy over [Laravels `str_contains`](https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Str.php#L181) instead
* 0.1.11 PHP 8 Support & wait in case of _short period read limit reached_ error (thx [fwehrhausen](https://github.com/repat/plentymarkets-rest-client/pull/15))
* 0.1.10 Allow dealing with Exceptions yourself by passing `true` as 3rd parameter
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -5,7 +5,7 @@
"keywords": ["plentymarkets", "pm", "rest", "api", "client", "sdk"],
"homepage": "https://github.com/repat/plentymarkets-rest-client",
"license": "MIT",
"version" : "0.1.12",
"version" : "0.1.13",
"authors": [
{
"name": "repat",
Expand Down
26 changes: 2 additions & 24 deletions src/PlentymarketsRestClient/PlentymarketsRestClient.php
Expand Up @@ -90,7 +90,7 @@ public function singleCall($method, $path, $params = [])
} catch (\Exception $e) {

// For a better Plentymarkets exception handling. Sometimes the limit is not correct
if ($this->str_contains($e->getMessage(), self::ERROR_SHORT_PERIOD_READ_LIMIT)) {
if (stripos($e->getMessage(), self::ERROR_SHORT_PERIOD_READ_LIMIT) !== false) {
sleep(self::WAIT_ERROR_SHORT_PERIOD_READ_LIMIT);
$this->singleCall($method, $path, $params);
// TODO possible handle recursion errors
Expand Down Expand Up @@ -172,7 +172,7 @@ private function readConfigFile($configFile)

private function correctURL($url)
{
if (! ($this->str_contains('https', $url))) {
if (stripos('https', $url) === false) {
$url = str_replace('http://', 'https://', $url);
}

Expand Down Expand Up @@ -234,26 +234,4 @@ private function handleThrottling(ResponseInterface $response, $prefix, $throttl

return 0;
}

/**
* Determine if a given string contains a given substring.
*
* NOTE could use native str_contains in PHP 8+
*
* @source https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Str.php#L181
*
* @param string $haystack
* @param string|string[] $needles
* @return bool
*/
private function str_contains($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ($needle !== '' && mb_strpos($haystack, $needle) !== false) {
return true;
}
}

return false;
}
}

0 comments on commit 3b53d22

Please sign in to comment.