update: strpos and substr functions

- strpos and substr functions calls that can be replaced with the str_* functions calls (introduced in PHP 8.0).
This commit is contained in:
HDVinnie
2020-12-30 22:55:44 -05:00
parent a2c6e8c5f1
commit 90b3880dab
6 changed files with 18 additions and 18 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ class CasinoBot
public function replaceVars($output)
{
$output = \str_replace(['{me}', '{command}'], [$this->bot->name, $this->bot->command], $output);
if (\strpos($output, '{bots}') !== false) {
if (str_contains($output, '{bots}')) {
$botHelp = '';
$bots = Bot::where('active', '=', 1)->where('id', '!=', $this->bot->id)->orderBy('position', 'asc')->get();
foreach ($bots as $bot) {
+1 -1
View File
@@ -71,7 +71,7 @@ class NerdBot
public function replaceVars($output)
{
$output = \str_replace(['{me}', '{command}'], [$this->bot->name, $this->bot->command], $output);
if (\strpos($output, '{bots}') !== false) {
if (str_contains($output, '{bots}')) {
$botHelp = '';
$bots = Bot::where('active', '=', 1)->where('id', '!=', $this->bot->id)->orderBy('position', 'asc')->get();
foreach ($bots as $bot) {
+1 -1
View File
@@ -62,7 +62,7 @@ class SystemBot
public function replaceVars($output)
{
$output = \str_replace(['{me}', '{command}'], [$this->bot->name, $this->bot->command], $output);
if (\strpos($output, '{bots}') !== false) {
if (str_contains($output, '{bots}')) {
$botHelp = '';
$bots = Bot::where('active', '=', 1)->where('id', '!=', $this->bot->id)->orderBy('position', 'asc')->get();
foreach ($bots as $bot) {
+1 -1
View File
@@ -27,7 +27,7 @@ class LanguageCensor
protected static function isSpecial($c)
{
return \strpos(self::SPECIAL_CHARS, $c) !== false;
return str_contains(self::SPECIAL_CHARS, $c);
}
protected static function matchWordIndexes($string, $word)
+6 -6
View File
@@ -153,7 +153,7 @@ class Markdown
continue;
}
if (\strpos($line, "\t") !== false) {
if (str_contains($line, "\t")) {
$parts = \explode("\t", $line);
$line = $parts[0];
@@ -746,7 +746,7 @@ class Markdown
return;
}
if (\strpos($Block['element']['text'], '|') !== false && \rtrim($Line['text'], ' -:|') === '') {
if (str_contains($Block['element']['text'], '|') && \rtrim($Line['text'], ' -:|') === '') {
$alignments = [];
$divider = $Line['text'];
@@ -1018,7 +1018,7 @@ class Markdown
protected function inlineEmailTag($Excerpt)
{
if (\strpos($Excerpt['text'], '>') !== false && \preg_match('#^<((mailto:)?\S+?@\S+?)>#i', $Excerpt['text'], $matches)) {
if (str_contains($Excerpt['text'], '>') && \preg_match('#^<((mailto:)?\S+?@\S+?)>#i', $Excerpt['text'], $matches)) {
$url = $matches[1];
if (! isset($matches[2])) {
@@ -1169,7 +1169,7 @@ class Markdown
protected function inlineMarkup($Excerpt)
{
if ($this->markupEscaped || $this->safeMode || \strpos($Excerpt['text'], '>') === false) {
if ($this->markupEscaped || $this->safeMode || !str_contains($Excerpt['text'], '>')) {
return;
}
@@ -1255,7 +1255,7 @@ class Markdown
protected function inlineUrlTag($Excerpt)
{
if (\strpos($Excerpt['text'], '>') !== false && \preg_match('#^<(\w+:\/{2}[^ >]+)>#i', $Excerpt['text'], $matches)) {
if (str_contains($Excerpt['text'], '>') && \preg_match('#^<(\w+:\/{2}[^ >]+)>#i', $Excerpt['text'], $matches)) {
$url = $matches[1];
return [
@@ -1345,7 +1345,7 @@ class Markdown
$trimmedMarkup = \trim($markup);
if (! \in_array('', $lines, true) && \strpos($trimmedMarkup, '<p>') === 0) {
if (! \in_array('', $lines, true) && str_starts_with($trimmedMarkup, '<p>')) {
$markup = $trimmedMarkup;
$markup = \substr($markup, 3);
+8 -8
View File
@@ -164,7 +164,7 @@ class ChatController extends Controller
$target = null;
$runbot = null;
$trip = 'msg';
if ($message && \strpos($message, '/'.$trip) === 0) {
if ($message && str_starts_with($message, '/'.$trip)) {
$which = 'skip';
$command = @\explode(' ', $message);
if (\array_key_exists(1, $command)) {
@@ -178,7 +178,7 @@ class ChatController extends Controller
}
$trip = 'gift';
if ($message && \strpos($message, '/'.$trip) === 0) {
if ($message && str_starts_with($message, '/'.$trip)) {
$which = 'echo';
$target = 'system';
$message = '/bot gift'.\substr($message, \strlen($trip) + 1, \strlen($message));
@@ -188,21 +188,21 @@ class ChatController extends Controller
}
if ($which == null) {
foreach ($bots as $bot) {
if ($message && \strpos($message, '/'.$bot->command) === 0) {
if ($message && str_starts_with($message, '/'.$bot->command)) {
$which = 'echo';
} elseif ($message && \strpos($message, '!'.$bot->command) === 0) {
} elseif ($message && str_starts_with($message, '!'.$bot->command)) {
$which = 'public';
} elseif ($message && \strpos($message, '@'.$bot->command) === 0) {
} elseif ($message && str_starts_with($message, '@'.$bot->command)) {
$message = \substr($message, 1 + \strlen($bot->command), \strlen($message));
$which = 'private';
} elseif ($message && $receiverId == 1 && $bot->id == $botId) {
if (\strpos($message, '/'.$bot->command) === 0) {
if (str_starts_with($message, '/'.$bot->command)) {
$message = \substr($message, 1 + \strlen($bot->command), \strlen($message));
}
if ($message && \strpos($message, '!'.$bot->command) === 0) {
if ($message && str_starts_with($message, '!'.$bot->command)) {
$message = \substr($message, 1 + \strlen($bot->command), \strlen($message));
}
if ($message && \strpos($message, '@'.$bot->command) === 0) {
if ($message && str_starts_with($message, '@'.$bot->command)) {
$message = \substr($message, 1 + \strlen($bot->command), \strlen($message));
}
$which = 'message';