mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Type sizes as int|float throughout the code base
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
5c1a0e0307
commit
cd885b5705
18 changed files with 35 additions and 43 deletions
|
|
@ -53,10 +53,8 @@ use Sabre\DAV\Server;
|
|||
use Sabre\DAV\Tree;
|
||||
use Sabre\HTTP\RequestInterface;
|
||||
use Sabre\HTTP\ResponseInterface;
|
||||
use Sabre\Uri;
|
||||
|
||||
class FilesPlugin extends ServerPlugin {
|
||||
|
||||
// namespace
|
||||
public const NS_OWNCLOUD = 'http://owncloud.org/ns';
|
||||
public const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
|
||||
|
|
@ -352,7 +350,7 @@ class FilesPlugin extends ServerPlugin {
|
|||
$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
|
||||
return json_encode($this->previewManager->isAvailable($node->getFileInfo()), JSON_THROW_ON_ERROR);
|
||||
});
|
||||
$propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): ?int {
|
||||
$propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): int|float {
|
||||
return $node->getSize();
|
||||
});
|
||||
$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
|
||||
|
|
@ -382,7 +380,7 @@ class FilesPlugin extends ServerPlugin {
|
|||
});
|
||||
/**
|
||||
* Return file/folder name as displayname. The primary reason to
|
||||
* implement it this way is to avoid costly fallback to
|
||||
* implement it this way is to avoid costly fallback to
|
||||
* CustomPropertiesBackend (esp. visible when querying all files
|
||||
* in a folder).
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -67,10 +67,7 @@ abstract class Node implements \Sabre\DAV\INode {
|
|||
*/
|
||||
protected $property_cache = null;
|
||||
|
||||
/**
|
||||
* @var \OCP\Files\FileInfo
|
||||
*/
|
||||
protected $info;
|
||||
protected FileInfo $info;
|
||||
|
||||
/**
|
||||
* @var IManager
|
||||
|
|
@ -81,10 +78,6 @@ abstract class Node implements \Sabre\DAV\INode {
|
|||
|
||||
/**
|
||||
* Sets up the node, expects a full path name
|
||||
*
|
||||
* @param \OC\Files\View $view
|
||||
* @param \OCP\Files\FileInfo $info
|
||||
* @param IManager $shareManager
|
||||
*/
|
||||
public function __construct(View $view, FileInfo $info, IManager $shareManager = null) {
|
||||
$this->fileView = $view;
|
||||
|
|
@ -232,7 +225,7 @@ abstract class Node implements \Sabre\DAV\INode {
|
|||
*
|
||||
* @return int|float
|
||||
*/
|
||||
public function getSize() {
|
||||
public function getSize(): int|float {
|
||||
return $this->info->getSize();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ class QuotaPlugin extends \Sabre\DAV\ServerPlugin {
|
|||
* This method is called before any HTTP method and validates there is enough free space to store the file
|
||||
*
|
||||
* @param string $path relative to the users home
|
||||
* @param int $length
|
||||
* @param int|float|null $length
|
||||
* @throws InsufficientStorage
|
||||
* @return bool
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ use OCA\DAV\Connector\Sabre\File;
|
|||
use Sabre\DAV\IFile;
|
||||
|
||||
class UploadFile implements IFile {
|
||||
|
||||
/** @var File */
|
||||
private $file;
|
||||
|
||||
|
|
@ -53,6 +52,9 @@ class UploadFile implements IFile {
|
|||
return $this->file->getETag();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|float
|
||||
*/
|
||||
public function getSize() {
|
||||
return $this->file->getSize();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -261,6 +261,8 @@ class FilesReportPluginTest extends \Test\TestCase {
|
|||
$filesNode2 = $this->getMockBuilder(File::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$filesNode2->method('getSize')
|
||||
->willReturn(10);
|
||||
|
||||
$this->userFolder->expects($this->exactly(2))
|
||||
->method('getById')
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ abstract class AbstractTrash implements ITrash {
|
|||
return $this->data;
|
||||
}
|
||||
|
||||
public function getSize(): int {
|
||||
public function getSize(): int|float {
|
||||
return $this->data->getSize();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ class LazyFolder implements \OCP\Files\Folder {
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSize($includeMounts = true) {
|
||||
public function getSize($includeMounts = true): int|float {
|
||||
return $this->__call(__FUNCTION__, func_get_args());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,11 +209,11 @@ class Node implements \OCP\Files\Node {
|
|||
|
||||
/**
|
||||
* @param bool $includeMounts
|
||||
* @return int
|
||||
* @return int|float
|
||||
* @throws InvalidPathException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function getSize($includeMounts = true) {
|
||||
public function getSize($includeMounts = true): int|float {
|
||||
return $this->getFileInfo()->getSize($includeMounts);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class NonExistingFile extends File {
|
|||
}
|
||||
}
|
||||
|
||||
public function getSize($includeMounts = true) {
|
||||
public function getSize($includeMounts = true): int|float {
|
||||
if ($this->fileInfo) {
|
||||
return parent::getSize($includeMounts);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class NonExistingFolder extends Folder {
|
|||
}
|
||||
}
|
||||
|
||||
public function getSize($includeMounts = true) {
|
||||
public function getSize($includeMounts = true): int|float {
|
||||
if ($this->fileInfo) {
|
||||
return parent::getSize($includeMounts);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -290,9 +290,9 @@ class Root extends Folder implements IRootFolder {
|
|||
|
||||
/**
|
||||
* @param bool $includeMounts
|
||||
* @return int
|
||||
* @return int|float
|
||||
*/
|
||||
public function getSize($includeMounts = true) {
|
||||
public function getSize($includeMounts = true): int|float {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class NewSimpleFile implements ISimpleFile {
|
|||
/**
|
||||
* Get the size in bytes
|
||||
*/
|
||||
public function getSize(): int {
|
||||
public function getSize(): int|float {
|
||||
if ($this->file) {
|
||||
return $this->file->getSize();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class SimpleFile implements ISimpleFile {
|
|||
/**
|
||||
* Get the size in bytes
|
||||
*/
|
||||
public function getSize(): int {
|
||||
public function getSize(): int|float {
|
||||
return $this->file->getSize();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ use ZipStreamer\ZipStreamer;
|
|||
|
||||
class Streamer {
|
||||
// array of regexp. Matching user agents will get tar instead of zip
|
||||
private $preferTarFor = [ '/macintosh|mac os x/i' ];
|
||||
private array $preferTarFor = [ '/macintosh|mac os x/i' ];
|
||||
|
||||
// streamer instance
|
||||
private $streamerInstance;
|
||||
|
|
@ -49,11 +49,11 @@ class Streamer {
|
|||
* Streamer constructor.
|
||||
*
|
||||
* @param IRequest $request
|
||||
* @param int $size The size of the files in bytes
|
||||
* @param int|float $size The size of the files in bytes
|
||||
* @param int $numberOfFiles The number of files (and directories) that will
|
||||
* be included in the streamed file
|
||||
*/
|
||||
public function __construct(IRequest $request, int $size, int $numberOfFiles) {
|
||||
public function __construct(IRequest $request, int|float $size, int $numberOfFiles) {
|
||||
/**
|
||||
* zip32 constraints for a basic (without compression, volumes nor
|
||||
* encryption) zip file according to the Zip specification:
|
||||
|
|
@ -149,11 +149,11 @@ class Streamer {
|
|||
*
|
||||
* @param resource $stream Stream to read data from
|
||||
* @param string $internalName Filepath and name to be used in the archive.
|
||||
* @param int $size Filesize
|
||||
* @param int|bool $time File mtime as int, or false
|
||||
* @param int|float $size Filesize
|
||||
* @param int|false $time File mtime as int, or false
|
||||
* @return bool $success
|
||||
*/
|
||||
public function addFileFromStream($stream, string $internalName, int $size, $time): bool {
|
||||
public function addFileFromStream($stream, string $internalName, int|float $size, $time): bool {
|
||||
$options = [];
|
||||
if ($time) {
|
||||
$options = [
|
||||
|
|
|
|||
|
|
@ -59,14 +59,11 @@ class OC_Files {
|
|||
public const UPLOAD_MIN_LIMIT_BYTES = 1048576; // 1 MiB
|
||||
|
||||
|
||||
private static $multipartBoundary = '';
|
||||
private static string $multipartBoundary = '';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function getBoundary() {
|
||||
private static function getBoundary(): string {
|
||||
if (empty(self::$multipartBoundary)) {
|
||||
self::$multipartBoundary = md5(mt_rand());
|
||||
self::$multipartBoundary = md5((string)mt_rand());
|
||||
}
|
||||
return self::$multipartBoundary;
|
||||
}
|
||||
|
|
@ -76,7 +73,7 @@ class OC_Files {
|
|||
* @param string $name
|
||||
* @param array $rangeArray ('from'=>int,'to'=>int), ...
|
||||
*/
|
||||
private static function sendHeaders($filename, $name, array $rangeArray) {
|
||||
private static function sendHeaders($filename, $name, array $rangeArray): void {
|
||||
OC_Response::setContentDispositionHeader($name, 'attachment');
|
||||
header('Content-Transfer-Encoding: binary', true);
|
||||
header('Pragma: public');// enable caching in IE
|
||||
|
|
@ -247,10 +244,10 @@ class OC_Files {
|
|||
|
||||
/**
|
||||
* @param string $rangeHeaderPos
|
||||
* @param int $fileSize
|
||||
* @param int|float $fileSize
|
||||
* @return array $rangeArray ('from'=>int,'to'=>int), ...
|
||||
*/
|
||||
private static function parseHttpRangeHeader($rangeHeaderPos, $fileSize) {
|
||||
private static function parseHttpRangeHeader($rangeHeaderPos, $fileSize): array {
|
||||
$rArray = explode(',', $rangeHeaderPos);
|
||||
$minOffset = 0;
|
||||
$ind = 0;
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ interface Node extends FileInfo {
|
|||
* Get the size of the file or folder in bytes
|
||||
*
|
||||
* @param bool $includeMounts
|
||||
* @return int
|
||||
* @return int|float
|
||||
* @throws InvalidPathException
|
||||
* @throws NotFoundException
|
||||
* @since 6.0.0
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ interface ISimpleFile {
|
|||
*
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getSize(): int;
|
||||
public function getSize(): int|float;
|
||||
|
||||
/**
|
||||
* Get the ETag
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class InMemoryFile implements ISimpleFile {
|
|||
* @inheritdoc
|
||||
* @since 16.0.0
|
||||
*/
|
||||
public function getSize(): int {
|
||||
public function getSize(): int|float {
|
||||
return strlen($this->contents);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue