Skip to content

Commit 7f71b46

Browse files
authored
Merge pull request #57882 from nextcloud/useStrictComparisonOperator
2 parents e140081 + 0803350 commit 7f71b46

9 files changed

Lines changed: 39 additions & 39 deletions

File tree

lib/private/Archive/TAR.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ private function getHeader(string $file): ?array {
121121
$this->cachedHeaders = $this->tar->listContent();
122122
}
123123
foreach ($this->cachedHeaders as $header) {
124-
if ($file == $header['filename']
125-
|| $file . '/' == $header['filename']
126-
|| '/' . $file . '/' == $header['filename']
127-
|| '/' . $file == $header['filename']
124+
if ($file === $header['filename']
125+
|| $file . '/' === $header['filename']
126+
|| '/' . $file . '/' === $header['filename']
127+
|| '/' . $file === $header['filename']
128128
) {
129129
return $header;
130130
}
@@ -158,10 +158,10 @@ public function getFolder(string $path): array {
158158
$folderContent = [];
159159
$pathLength = strlen($path);
160160
foreach ($files as $file) {
161-
if ($file[0] == '/') {
161+
if ($file[0] === '/') {
162162
$file = substr($file, 1);
163163
}
164-
if (substr($file, 0, $pathLength) == $path && $file != $path) {
164+
if (substr($file, 0, $pathLength) === $path && $file !== $path) {
165165
$result = substr($file, $pathLength);
166166
if ($pos = strpos($result, '/')) {
167167
$result = substr($result, 0, $pos + 1);
@@ -250,12 +250,12 @@ public function fileExists(string $path): bool {
250250
$folderPath = rtrim($path, '/') . '/';
251251
$pathLength = strlen($folderPath);
252252
foreach ($files as $file) {
253-
if (strlen($file) > $pathLength && substr($file, 0, $pathLength) == $folderPath) {
253+
if (strlen($file) > $pathLength && substr($file, 0, $pathLength) === $folderPath) {
254254
return true;
255255
}
256256
}
257257
}
258-
if ($path[0] != '/') { //not all programs agree on the use of a leading /
258+
if ($path[0] !== '/') { //not all programs agree on the use of a leading /
259259
return $this->fileExists('/' . $path);
260260
} else {
261261
return false;
@@ -296,10 +296,10 @@ public function getStream(string $path, string $mode) {
296296
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
297297
if ($this->fileExists($path)) {
298298
$this->extractFile($path, $tmpFile);
299-
} elseif ($mode == 'r' || $mode == 'rb') {
299+
} elseif ($mode === 'r' || $mode === 'rb') {
300300
return false;
301301
}
302-
if ($mode == 'r' || $mode == 'rb') {
302+
if ($mode === 'r' || $mode === 'rb') {
303303
return fopen($tmpFile, $mode);
304304
} else {
305305
$handle = fopen($tmpFile, $mode);

lib/private/Archive/ZIP.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function getFolder(string $path): array {
9292
$folderContent = [];
9393
$pathLength = strlen($path);
9494
foreach ($files as $file) {
95-
if (substr($file, 0, $pathLength) == $path && $file != $path) {
95+
if (substr($file, 0, $pathLength) === $path && $file !== $path) {
9696
if (strrpos(substr($file, 0, -1), '/') <= $pathLength) {
9797
$folderContent[] = substr($file, $pathLength);
9898
}
@@ -220,7 +220,7 @@ public function writeBack(string $tmpFile, string $path): void {
220220
}
221221

222222
private function stripPath(string $path): string {
223-
if (!$path || $path[0] == '/') {
223+
if (!$path || $path[0] === '/') {
224224
return substr($path, 1);
225225
} else {
226226
return $path;

lib/private/Files/Cache/Wrapper/CacheJail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected function formatCacheEntry($entry) {
104104
* @return ICacheEntry|false
105105
*/
106106
public function get($file) {
107-
if (is_string($file) || $file == '') {
107+
if (is_string($file) || $file === '') {
108108
$file = $this->getSourcePath($file);
109109
}
110110
return parent::get($file);

lib/private/Files/Node/LazyFolder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function getPermissions() {
258258
*/
259259
public function isReadable() {
260260
if (isset($this->data['permissions'])) {
261-
return ($this->data['permissions'] & Constants::PERMISSION_READ) == Constants::PERMISSION_READ;
261+
return ($this->data['permissions'] & Constants::PERMISSION_READ) === Constants::PERMISSION_READ;
262262
}
263263
return $this->__call(__FUNCTION__, func_get_args());
264264
}
@@ -268,7 +268,7 @@ public function isReadable() {
268268
*/
269269
public function isUpdateable() {
270270
if (isset($this->data['permissions'])) {
271-
return ($this->data['permissions'] & Constants::PERMISSION_UPDATE) == Constants::PERMISSION_UPDATE;
271+
return ($this->data['permissions'] & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE;
272272
}
273273
return $this->__call(__FUNCTION__, func_get_args());
274274
}
@@ -278,7 +278,7 @@ public function isUpdateable() {
278278
*/
279279
public function isDeletable() {
280280
if (isset($this->data['permissions'])) {
281-
return ($this->data['permissions'] & Constants::PERMISSION_DELETE) == Constants::PERMISSION_DELETE;
281+
return ($this->data['permissions'] & Constants::PERMISSION_DELETE) === Constants::PERMISSION_DELETE;
282282
}
283283
return $this->__call(__FUNCTION__, func_get_args());
284284
}
@@ -288,7 +288,7 @@ public function isDeletable() {
288288
*/
289289
public function isShareable() {
290290
if (isset($this->data['permissions'])) {
291-
return ($this->data['permissions'] & Constants::PERMISSION_SHARE) == Constants::PERMISSION_SHARE;
291+
return ($this->data['permissions'] & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE;
292292
}
293293
return $this->__call(__FUNCTION__, func_get_args());
294294
}

lib/private/Files/Search/QueryOptimizer/PathPrefixOptimizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function processOperator(ISearchOperator &$operator) {
4040
}
4141

4242
private function isPathPrefixOperator(ISearchOperator $operator): bool {
43-
if ($operator instanceof ISearchBinaryOperator && $operator->getType() === ISearchBinaryOperator::OPERATOR_OR && count($operator->getArguments()) == 2) {
43+
if ($operator instanceof ISearchBinaryOperator && $operator->getType() === ISearchBinaryOperator::OPERATOR_OR && count($operator->getArguments()) === 2) {
4444
$a = $operator->getArguments()[0];
4545
$b = $operator->getArguments()[1];
4646
if ($this->operatorPairIsPathPrefix($a, $b) || $this->operatorPairIsPathPrefix($b, $a)) {

lib/private/Files/Storage/Common.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,15 @@ public function getETag(string $path): string|false {
391391
* @return string cleaned path
392392
*/
393393
public function cleanPath(string $path): string {
394-
if (strlen($path) == 0 || $path[0] != '/') {
394+
if (strlen($path) === 0 || $path[0] !== '/') {
395395
$path = '/' . $path;
396396
}
397397

398398
$output = [];
399399
foreach (explode('/', $path) as $chunk) {
400-
if ($chunk == '..') {
400+
if ($chunk === '..') {
401401
array_pop($output);
402-
} elseif ($chunk == '.') {
402+
} elseif ($chunk === '.') {
403403
} else {
404404
$output[] = $chunk;
405405
}
@@ -611,7 +611,7 @@ public function getMetaData(string $path): ?array {
611611
if ($data['mtime'] === false) {
612612
$data['mtime'] = time();
613613
}
614-
if ($data['mimetype'] == 'httpd/unix-directory') {
614+
if ($data['mimetype'] === 'httpd/unix-directory') {
615615
$data['size'] = -1; //unknown
616616
} else {
617617
$data['size'] = $this->filesize($path);

lib/private/Files/Storage/DAV.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function filetype(string $path): string|false {
284284
/** @var ResourceType[] $response */
285285
$responseType = $response['{DAV:}resourcetype']->getValue();
286286
}
287-
return (count($responseType) > 0 && $responseType[0] == '{DAV:}collection') ? 'dir' : 'file';
287+
return (count($responseType) > 0 && $responseType[0] === '{DAV:}collection') ? 'dir' : 'file';
288288
} catch (\Exception $e) {
289289
$this->convertException($e, $path);
290290
}
@@ -572,7 +572,7 @@ private function getMetaFromPropfind(string $path, array $response): array {
572572
/** @var ResourceType[] $response */
573573
$responseType = $response['{DAV:}resourcetype']->getValue();
574574
}
575-
$type = (count($responseType) > 0 && $responseType[0] == '{DAV:}collection') ? 'dir' : 'file';
575+
$type = (count($responseType) > 0 && $responseType[0] === '{DAV:}collection') ? 'dir' : 'file';
576576
if ($type === 'dir') {
577577
$mimeType = 'httpd/unix-directory';
578578
} elseif (isset($response['{DAV:}getcontenttype'])) {
@@ -648,7 +648,7 @@ protected function simpleResponse(string $method, string $path, ?string $body, i
648648
$path = $this->cleanPath($path);
649649
try {
650650
$response = $this->client->request($method, $this->encodePath($path), $body);
651-
return $response['statusCode'] == $expected;
651+
return $response['statusCode'] === $expected;
652652
} catch (ClientHttpException $e) {
653653
if ($e->getHttpStatus() === 404 && $method === 'DELETE') {
654654
$this->statCache->clear($path . '/');

lib/private/Files/Storage/Local.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function getMetaData(string $path): ?array {
216216

217217
public function filetype(string $path): string|false {
218218
$filetype = filetype($this->getSourcePath($path));
219-
if ($filetype == 'link') {
219+
if ($filetype === 'link') {
220220
$filetype = filetype(realpath($this->getSourcePath($path)));
221221
}
222222
return $filetype;

lib/private/Files/View.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function getAbsolutePath($path = '/'): ?string {
105105
* @param string $fakeRoot
106106
*/
107107
public function chroot($fakeRoot): void {
108-
if (!$fakeRoot == '') {
108+
if ($fakeRoot !== '') {
109109
if ($fakeRoot[0] !== '/') {
110110
$fakeRoot = '/' . $fakeRoot;
111111
}
@@ -127,7 +127,7 @@ public function getRoot(): string {
127127
*/
128128
public function getRelativePath($path): ?string {
129129
$this->assertPathLength($path);
130-
if ($this->fakeRoot == '') {
130+
if ($this->fakeRoot === '') {
131131
return $path;
132132
}
133133

@@ -320,7 +320,7 @@ public function opendir($path) {
320320
* @return bool|mixed
321321
*/
322322
public function is_dir($path) {
323-
if ($path == '/') {
323+
if ($path === '/') {
324324
return true;
325325
}
326326
return $this->basicOperation('is_dir', $path);
@@ -331,7 +331,7 @@ public function is_dir($path) {
331331
* @return bool|mixed
332332
*/
333333
public function is_file($path) {
334-
if ($path == '/') {
334+
if ($path === '/') {
335335
return false;
336336
}
337337
return $this->basicOperation('is_file', $path);
@@ -497,7 +497,7 @@ public function isSharable($path) {
497497
* @return bool|mixed
498498
*/
499499
public function file_exists($path) {
500-
if ($path == '/') {
500+
if ($path === '/') {
501501
return true;
502502
}
503503
return $this->basicOperation('file_exists', $path);
@@ -729,7 +729,7 @@ public function rename($source, $target, array $options = []) {
729729
$target = $this->getRelativePath($absolutePath2);
730730
$exists = $this->file_exists($target);
731731

732-
if ($source == null || $target == null) {
732+
if ($source === null || $target === null) {
733733
return false;
734734
}
735735

@@ -926,7 +926,7 @@ public function copy($source, $target, $preserveMtime = false) {
926926
$source = $this->getRelativePath($absolutePath1);
927927
$target = $this->getRelativePath($absolutePath2);
928928

929-
if ($source == null || $target == null) {
929+
if ($source === null || $target === null) {
930930
return false;
931931
}
932932
$run = true;
@@ -961,7 +961,7 @@ public function copy($source, $target, $preserveMtime = false) {
961961
$this->changeLock($target, ILockingProvider::LOCK_EXCLUSIVE);
962962
$lockTypePath2 = ILockingProvider::LOCK_EXCLUSIVE;
963963

964-
if ($mount1->getMountPoint() == $mount2->getMountPoint()) {
964+
if ($mount1->getMountPoint() === $mount2->getMountPoint()) {
965965
if ($storage1) {
966966
$result = $storage1->copy($internalPath1, $internalPath2);
967967
} else {
@@ -1132,7 +1132,7 @@ public function hash($type, $path, $raw = false): string|bool {
11321132
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
11331133
if (Filesystem::isValidPath($path)) {
11341134
$path = $this->getRelativePath($absolutePath);
1135-
if ($path == null) {
1135+
if ($path === null) {
11361136
return false;
11371137
}
11381138
if ($this->shouldEmitHooks($path)) {
@@ -1183,7 +1183,7 @@ private function basicOperation(string $operation, string $path, array $hooks =
11831183
&& !Filesystem::isFileBlacklisted($path)
11841184
) {
11851185
$path = $this->getRelativePath($absolutePath);
1186-
if ($path == null) {
1186+
if ($path === null) {
11871187
return false;
11881188
}
11891189

@@ -1251,7 +1251,7 @@ private function basicOperation(string $operation, string $path, array $hooks =
12511251
}
12521252

12531253
if ($this->shouldEmitHooks($path) && $result !== false) {
1254-
if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open
1254+
if ($operation !== 'fopen') { //no post hooks for fopen, the file stream is still open
12551255
$this->runHooks($hooks, $path, true);
12561256
}
12571257
}
@@ -1319,7 +1319,7 @@ private function runHooks($hooks, $path, $post = false) {
13191319
$run = true;
13201320
if ($this->shouldEmitHooks($relativePath)) {
13211321
foreach ($hooks as $hook) {
1322-
if ($hook != 'read') {
1322+
if ($hook !== 'read') {
13231323
\OC_Hook::emit(
13241324
Filesystem::CLASSNAME,
13251325
$prefix . $hook,
@@ -2256,7 +2256,7 @@ public function getUidAndFilename($filename) {
22562256
throw new NotFoundException($this->getAbsolutePath($filename) . ' not found');
22572257
}
22582258
$uid = $info->getOwner()->getUID();
2259-
if ($uid != \OC_User::getUser()) {
2259+
if ($uid !== \OC_User::getUser()) {
22602260
Filesystem::initMountPoints($uid);
22612261
$ownerView = new View('/' . $uid . '/files');
22622262
try {

0 commit comments

Comments
 (0)