Skip to content

Commit

Permalink
Refactors "substr" calls to improve code readability
Browse files Browse the repository at this point in the history
Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com>
  • Loading branch information
shdehnavi authored and skjnldsv committed Feb 23, 2024
1 parent a88c1bd commit 7bf31df
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
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

0 comments on commit 7bf31df

Please sign in to comment.