Skip to content

Commit

Permalink
Merge pull request #38602 from fsamapoor/replace_strpos_calls_in_core
Browse files Browse the repository at this point in the history
Refactors "strpos" calls in /core to improve code readability.
  • Loading branch information
Fenn-CS committed Jun 4, 2023
2 parents 0357e58 + a1ef028 commit cf75c2e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions core/Controller/ClientFlowLoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ public function apptokenRedirect(string $stateToken, string $user, string $passw
private function getServerPath(): string {
$serverPostfix = '';

if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
if (str_contains($this->request->getRequestUri(), '/index.php')) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
} elseif (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
} elseif (str_contains($this->request->getRequestUri(), '/login/flow')) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
}

Expand Down
4 changes: 2 additions & 2 deletions core/Controller/ClientFlowLoginV2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ private function loginTokenForbiddenResponse(): StandaloneTemplateResponse {
private function getServerPath(): string {
$serverPostfix = '';

if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
if (str_contains($this->request->getRequestUri(), '/index.php')) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
} elseif (strpos($this->request->getRequestUri(), '/login/v2') !== false) {
} elseif (str_contains($this->request->getRequestUri(), '/login/v2')) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/v2'));
}

Expand Down
2 changes: 1 addition & 1 deletion core/Controller/CssController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getCss(string $fileName, string $appName): Response {
private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile {
$encoding = $this->request->getHeader('Accept-Encoding');

if (strpos($encoding, 'gzip') !== false) {
if (str_contains($encoding, 'gzip')) {
try {
$gzip = true;
return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz
Expand Down
2 changes: 1 addition & 1 deletion core/Controller/JsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getJs(string $fileName, string $appName): Response {
private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile {
$encoding = $this->request->getHeader('Accept-Encoding');

if (strpos($encoding, 'gzip') !== false) {
if (str_contains($encoding, 'gzip')) {
try {
$gzip = true;
return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz
Expand Down
2 changes: 1 addition & 1 deletion core/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private function generateRedirect(?string $redirectUrl): RedirectResponse {
$location = $this->urlGenerator->getAbsoluteURL($redirectUrl);
// Deny the redirect if the URL contains a @
// This prevents unvalidated redirects like ?redirect_url=:user@domain.com
if (strpos($location, '@') === false) {
if (!str_contains($location, '@')) {
return new RedirectResponse($location);
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/Controller/NavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ private function generateETag(array $navigation): string {
*/
private function rewriteToAbsoluteUrls(array $navigation): array {
foreach ($navigation as &$entry) {
if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) {
if (!str_starts_with($entry['href'], $this->urlGenerator->getBaseUrl())) {
$entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']);
}
if (0 !== strpos($entry['icon'], $this->urlGenerator->getBaseUrl())) {
if (!str_starts_with($entry['icon'], $this->urlGenerator->getBaseUrl())) {
$entry['icon'] = $this->urlGenerator->getAbsoluteURL($entry['icon']);
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/ajax/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
use OC\Repair\Events\RepairWarningEvent;
use OCP\L10N\IFactory;

if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
@set_time_limit(0);
}

Expand Down

0 comments on commit cf75c2e

Please sign in to comment.