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

fix(IStorage): Use false instead of bool intersection type to match implementations #48219

Merged
merged 6 commits into from
Sep 27, 2024
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
4 changes: 2 additions & 2 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ public function testGetQuotaInfoUnlimited(): void {
$storage->expects($this->any())
->method('instanceOfStorage')
->willReturnMap([
'\OCA\Files_Sharing\SharedStorage' => false,
'\OC\Files\Storage\Wrapper\Quota' => false,
['\OCA\Files_Sharing\SharedStorage', false],
['\OC\Files\Storage\Wrapper\Quota', false],
]);

$storage->expects($this->once())
Expand Down
75 changes: 29 additions & 46 deletions apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

private LoggerInterface $logger;

public function needsPartFile() {
public function needsPartFile(): bool {
return false;
}

Expand Down Expand Up @@ -63,7 +63,7 @@
* @param string $path
* @return string correctly encoded path
*/
private function normalizePath($path) {
private function normalizePath($path): string {
$path = trim($path, '/');

if (!$path) {
Expand All @@ -73,24 +73,24 @@
return $path;
}

private function isRoot($path) {
private function isRoot($path): bool {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $path has no provided type
return $path === '.';
}

private function cleanKey($path) {
private function cleanKey($path): string {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $path has no provided type
if ($this->isRoot($path)) {
return '/';
}
return $path;
}

private function clearCache() {
private function clearCache(): void {
$this->objectCache = new CappedMemoryCache();
$this->directoryCache = new CappedMemoryCache();
$this->filesCache = new CappedMemoryCache();
}

private function invalidateCache($key) {
private function invalidateCache($key): void {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $key has no provided type
unset($this->objectCache[$key]);
$keys = array_keys($this->objectCache->getData());
$keyLength = strlen($key);
Expand All @@ -110,10 +110,7 @@
unset($this->directoryCache[$key]);
}

/**
* @return array|false
*/
private function headObject(string $key) {
private function headObject(string $key): array|false {
if (!isset($this->objectCache[$key])) {
try {
$this->objectCache[$key] = $this->getConnection()->headObject([
Expand Down Expand Up @@ -144,11 +141,9 @@
* Implementation from flysystem-aws-s3-v3:
* https://github.com/thephpleague/flysystem-aws-s3-v3/blob/8241e9cc5b28f981e0d24cdaf9867f14c7498ae4/src/AwsS3Adapter.php#L670-L694
*
* @param $path
* @return bool
* @throws \Exception
*/
private function doesDirectoryExist($path) {
private function doesDirectoryExist($path): bool {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $path has no provided type
if ($path === '.' || $path === '') {
return true;
}
Expand Down Expand Up @@ -190,13 +185,7 @@
return false;
}

/**
* Remove a file or folder
*
* @param string $path
* @return bool
*/
protected function remove($path) {
protected function remove($path): bool {
// remember fileType to reduce http calls
$fileType = $this->filetype($path);
if ($fileType === 'dir') {
Expand All @@ -208,7 +197,7 @@
}
}

public function mkdir($path) {
public function mkdir($path): bool {
$path = $this->normalizePath($path);

if ($this->is_dir($path)) {
Expand Down Expand Up @@ -236,12 +225,12 @@
return true;
}

public function file_exists($path) {
public function file_exists($path): bool {
return $this->filetype($path) !== false;
}


public function rmdir($path) {
public function rmdir($path): bool {
$path = $this->normalizePath($path);

if ($this->isRoot($path)) {
Expand All @@ -256,12 +245,12 @@
return $this->batchDelete($path);
}

protected function clearBucket() {
protected function clearBucket(): bool {
$this->clearCache();
return $this->batchDelete();
}

private function batchDelete($path = null) {
private function batchDelete($path = null): bool {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $path has no provided type
// TODO explore using https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.BatchDelete.html
$params = [
'Bucket' => $this->bucket
Expand Down Expand Up @@ -312,7 +301,7 @@
}
}

public function stat($path) {
public function stat($path): array|false {
$path = $this->normalizePath($path);

if ($this->is_dir($path)) {
Expand All @@ -334,11 +323,8 @@
*
* When the information is already present (e.g. opendir has been called before)
* this value is return. Otherwise a headObject is emitted.
*
* @param $path
* @return int|mixed
*/
private function getContentLength($path) {
private function getContentLength($path): int {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $path has no provided type
if (isset($this->filesCache[$path])) {
return (int)$this->filesCache[$path]['ContentLength'];
}
Expand All @@ -356,11 +342,8 @@
*
* When the information is already present (e.g. opendir has been called before)
* this value is return. Otherwise a headObject is emitted.
*
* @param $path
* @return mixed|string
*/
private function getLastModified($path) {
private function getLastModified($path): string {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $path has no provided type
if (isset($this->filesCache[$path])) {
return $this->filesCache[$path]['LastModified'];
}
Expand All @@ -373,7 +356,7 @@
return 'now';
}

public function is_dir($path) {
public function is_dir($path): bool {
$path = $this->normalizePath($path);

if (isset($this->filesCache[$path])) {
Expand All @@ -391,7 +374,7 @@
}
}

public function filetype($path) {
public function filetype($path): string|false {
$path = $this->normalizePath($path);

if ($this->isRoot($path)) {
Expand Down Expand Up @@ -419,15 +402,15 @@
return false;
}

public function getPermissions($path) {
public function getPermissions($path): int {
$type = $this->filetype($path);
if (!$type) {
return 0;
}
return $type === 'dir' ? Constants::PERMISSION_ALL : Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE;
}

public function unlink($path) {
public function unlink($path): bool {
$path = $this->normalizePath($path);

if ($this->is_dir($path)) {
Expand Down Expand Up @@ -506,7 +489,7 @@
return false;
}

public function touch($path, $mtime = null) {
public function touch($path, $mtime = null): bool {
if (is_null($mtime)) {
$mtime = time();
}
Expand Down Expand Up @@ -541,7 +524,7 @@
return true;
}

public function copy($source, $target, $isFile = null) {
public function copy($source, $target, $isFile = null): bool {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $isFile has no provided type
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);

Expand Down Expand Up @@ -584,7 +567,7 @@
return true;
}

public function rename($source, $target) {
public function rename($source, $target): bool {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);

Expand All @@ -611,18 +594,18 @@
return true;
}

public function test() {
public function test(): bool {
$this->getConnection()->headBucket([
'Bucket' => $this->bucket
]);
return true;
}

public function getId() {
public function getId(): string {
return $this->id;
}

public function writeBack($tmpFile, $path) {
public function writeBack($tmpFile, $path): bool {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $tmpFile has no provided type

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $path has no provided type
try {
$source = fopen($tmpFile, 'r');
$this->writeObject($path, $source, $this->mimeDetector->detectPath($path));
Expand All @@ -642,7 +625,7 @@
/**
* check if curl is installed
*/
public static function checkDependencies() {
public static function checkDependencies(): bool {
return true;
}

Expand Down Expand Up @@ -743,7 +726,7 @@
}
}

public function hasUpdated($path, $time) {
public function hasUpdated($path, $time): bool {
// for files we can get the proper mtime
if ($path !== '' && $object = $this->headObject($path)) {
$stat = $this->objectToMetaData($object);
Expand Down
Loading
Loading