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

Refactor "substr" calls in dav app to improve code readability #39214

Merged
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
2 changes: 1 addition & 1 deletion apps/dav/lib/BulkUpload/MultipartRequestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function parseBoundaryFromHeaders(string $contentType): string {
$boundaryValue = trim($boundaryValue);

// Remove potential quotes around boundary value.
if (substr($boundaryValue, 0, 1) === '"' && substr($boundaryValue, -1) === '"') {
if (str_starts_with($boundaryValue, '"') && str_ends_with($boundaryValue, '"')) {
$boundaryValue = substr($boundaryValue, 1, -1);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/BirthdayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ private function isGloballyEnabled():bool {
* @return string|null
*/
private function principalToUserId(string $userPrincipal):?string {
if (substr($userPrincipal, 0, 17) === 'principals/users/') {
if (str_starts_with($userPrincipal, 'principals/users/')) {
return substr($userPrincipal, 17);
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/FakeLockerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function validateTokens(RequestInterface $request, &$conditions) {
if (isset($fileCondition['tokens'])) {
foreach ($fileCondition['tokens'] as &$token) {
if (isset($token['token'])) {
if (substr($token['token'], 0, 16) === 'opaquelocktoken:') {
if (str_starts_with($token['token'], 'opaquelocktoken:')) {
$token['validToken'] = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function getSharePermissions($user) {
$mountpoint = $this->info->getMountPoint();
if (!($mountpoint instanceof MoveableMount)) {
$mountpointpath = $mountpoint->getMountPoint();
if (substr($mountpointpath, -1) === '/') {
if (str_ends_with($mountpointpath, '/')) {
$mountpointpath = substr($mountpointpath, 0, -1);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/Principal.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public function findByUri($uri, $principalPrefix) {
return $this->principalPrefix . '/' . $user->getUID();
}
}
if (substr($uri, 0, 10) === 'principal:') {
if (str_starts_with($uri, 'principal:')) {
$principal = substr($uri, 10);
$principal = $this->getPrincipalByPath($principal);
if ($principal !== null) {
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/DAV/CustomPropertiesBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function propFind($path, PropFind $propFind) {

// substr of calendars/ => path is inside the CalDAV component
// two '/' => this a calendar (no calendar-home nor calendar object)
if (substr($path, 0, 10) === 'calendars/' && substr_count($path, '/') === 2) {
if (str_starts_with($path, 'calendars/') && substr_count($path, '/') === 2) {
$allRequestedProps = $propFind->getRequestedProperties();
$customPropertiesForShares = [
'{DAV:}displayname',
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Connector/Sabre/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ private function listPartFiles(\OC\Files\View $userView = null, $path = '') {
$realPath = $storage->getSourcePath($internalPath);
$dh = opendir($realPath);
while (($file = readdir($dh)) !== false) {
if (substr($file, strlen($file) - 5, 5) === '.part') {
if (str_ends_with($file, '.part')) {
$files[] = $file;
}
}
Expand Down
Loading