Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converts 'strpos()' calls to improve code readability. #4657

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/Controller/AttachmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getAll($cardId) {
* @throws \OCA\Deck\NotFoundException
*/
public function display($cardId, $attachmentId) {
if (strpos($attachmentId, ':') === false) {
if (!str_contains($attachmentId, ':')) {
$type = 'deck_file';
} else {
[$type, $attachmentId] = explode(':', $attachmentId);
Expand All @@ -76,7 +76,7 @@ public function create($cardId) {
* @NoAdminRequired
*/
public function update($cardId, $attachmentId) {
if (strpos($attachmentId, ':') === false) {
if (!str_contains($attachmentId, ':')) {
$type = 'deck_file';
} else {
[$type, $attachmentId] = explode(':', $attachmentId);
Expand All @@ -88,7 +88,7 @@ public function update($cardId, $attachmentId) {
* @NoAdminRequired
*/
public function delete($cardId, $attachmentId) {
if (strpos($attachmentId, ':') === false) {
if (!str_contains($attachmentId, ':')) {
$type = 'deck_file';
} else {
[$type, $attachmentId] = explode(':', $attachmentId);
Expand All @@ -100,7 +100,7 @@ public function delete($cardId, $attachmentId) {
* @NoAdminRequired
*/
public function restore($cardId, $attachmentId) {
if (strpos($attachmentId, ':') === false) {
if (!str_contains($attachmentId, ':')) {
$type = 'deck_file';
} else {
[$type, $attachmentId] = explode(':', $attachmentId);
Expand Down
6 changes: 3 additions & 3 deletions lib/Db/RelationalEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function jsonSerialize(): array {
$reflection = new \ReflectionClass($this);
$json = [];
foreach ($properties as $property => $value) {
if (strpos($property, '_') !== 0 && $reflection->hasProperty($property)) {
if (!str_starts_with($property, '_') && $reflection->hasProperty($property)) {
$propertyReflection = $reflection->getProperty($property);
if (!$propertyReflection->isPrivate() && !in_array($property, $this->_resolvedProperties, true)) {
$json[$property] = $this->getter($property);
Expand Down Expand Up @@ -129,15 +129,15 @@ public function resolveRelation($property, $resolver) {

public function __call(string $methodName, array $args) {
$attr = lcfirst(substr($methodName, 7));
if (array_key_exists($attr, $this->_resolvedProperties) && strpos($methodName, 'resolve') === 0) {
if (array_key_exists($attr, $this->_resolvedProperties) && str_starts_with($methodName, 'resolve')) {
if ($this->_resolvedProperties[$attr] !== null) {
return $this->_resolvedProperties[$attr];
}
return $this->getter($attr);
}

$attr = lcfirst(substr($methodName, 3));
if (array_key_exists($attr, $this->_resolvedProperties) && strpos($methodName, 'set') === 0) {
if (array_key_exists($attr, $this->_resolvedProperties) && str_starts_with($methodName, 'set')) {
if (!is_scalar($args[0])) {
$args[0] = $args[0]['primaryKey'];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Listeners/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function handle(Event $event): void {
Util::addStyle('deck', 'deck');

$pathInfo = $this->request->getPathInfo();
if (strpos($pathInfo, '/apps/calendar') === 0) {
if (str_starts_with($pathInfo, '/apps/calendar')) {
Util::addScript('deck', 'deck-calendar');
}

if (strpos($pathInfo, '/call/') === 0 || strpos($pathInfo, '/apps/spreed') === 0) {
if (str_starts_with($pathInfo, '/call/') || str_starts_with($pathInfo, '/apps/spreed')) {
Util::addScript('deck', 'deck-talk');
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Listeners/ResourceAdditionalScriptsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function handle(Event $event): void {
return;
}

if (strpos($this->request->getPathInfo(), '/call/') === 0) {
if (str_starts_with($this->request->getPathInfo(), '/call/')) {
// Talk integration has its own entrypoint which already includes collections handling
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Middleware/ExceptionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function afterException($controller, $methodName, \Exception $exception)
], $exception->getStatus());
}

if (strpos(get_class($controller), 'OCA\\Deck\\Controller\\') === 0) {
if (str_starts_with(get_class($controller), 'OCA\\Deck\\Controller\\')) {
$response = [
'status' => 500,
'message' => $exceptionMessage,
Expand Down
4 changes: 2 additions & 2 deletions lib/Search/FilterStringParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FilterStringParser {
public function __construct(IL10N $l10n) {
$this->l10n = $l10n;
}

public function parse(?string $filter): SearchQuery {
$query = new SearchQuery();
if (empty($filter)) {
Expand Down Expand Up @@ -71,7 +71,7 @@ public function parse(?string $filter): SearchQuery {
}

private function parseFilterToken(SearchQuery $query, string $token): bool {
if (strpos($token, ':') === false) {
if (!str_contains($token, ':')) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Validators/BaseValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function validate($data) {
// The format for specifying validation rules and parameters follows an
// easy {rule}:{parameters} formatting convention. For instance the
// rule "Max:3" states that the value may only be three letters.
if (strpos($rule, ':') !== false) {
if (str_contains($rule, ':')) {
[$rule, $parameter] = explode(':', $rule, 2);
if (!$this->{$rule}($value, $parameter)) {
throw new BadRequestException(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Activity/ActivityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testGetActivityFormatOwn() {
->willReturn($this->l10n);

foreach ($managerClass->getConstants() as $constant => $value) {
if (strpos($constant, 'SUBJECT') === 0) {
if (str_starts_with($constant, 'SUBJECT')) {
$format = $this->activityManager->getActivityFormat('cz', $value, [], false);
if ($format !== '') {
$this->assertStringContainsString('{user}', $format);
Expand Down