File Storage.php
has 653 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Bart Visscher <bartv@thisnet.nl>
* @author Björn Schießle <bjoern@schiessle.org>
Function expire
has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring. Open
public static function expire($filename, $uid) {
$config = \OC::$server->getConfig();
$expiration = self::getExpiration();
if ($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method expire
has 112 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function expire($filename, $uid) {
$config = \OC::$server->getConfig();
$expiration = self::getExpiration();
if ($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) {
Function getVersions
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
public static function getVersions($uid, $filename) {
$versions = [];
if ($filename === null || $filename === '') {
return $versions;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Storage
has 28 functions (exceeds 20 allowed). Consider refactoring. Open
class Storage {
public const DEFAULTENABLED=true;
public const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota
public const VERSIONS_ROOT = 'files_versions/';
Function getAutoExpireList
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
protected static function getAutoExpireList($time, $versions) {
$size = 0;
$toDelete = []; // versions we want to delete
$interval = 1;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function store
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public static function store($filename) {
if (\OC::$server->getConfig()->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
// if the file gets streamed we need to remove the .part extension
// to get the right target
$ext = \pathinfo($filename, PATHINFO_EXTENSION);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function expireOlderThanMaxForUser
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public static function expireOlderThanMaxForUser($uid) {
$expiration = self::getExpiration();
$threshold = $expiration->getMaxAgeAsTimestamp();
$versions = self::getFileHelper()->getAllVersions($uid);
if (!$threshold || !\array_key_exists('all', $versions)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getVersions
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getVersions($uid, $filename) {
$versions = [];
if ($filename === null || $filename === '') {
return $versions;
}
Method restoreVersion
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function restoreVersion($uid, $filename, $fileToRestore, $revision) {
if (\OC::$server->getConfig()->getSystemValue('files_versions', Storage::DEFAULTENABLED) !== true) {
return false;
}
$users_view = new View('/'.$uid);
Function renameOrCopy
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public static function renameOrCopy($sourcePath, $targetPath, $operation) {
list($sourceOwner, $sourcePath) = self::getSourcePathAndUser($sourcePath);
// it was a upload of a existing file if no old path exists
// in this case the pre-hook already called the store method and we can
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method renameOrCopy
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function renameOrCopy($sourcePath, $targetPath, $operation) {
list($sourceOwner, $sourcePath) = self::getSourcePathAndUser($sourcePath);
// it was a upload of a existing file if no old path exists
// in this case the pre-hook already called the store method and we can
Method getAutoExpireList
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected static function getAutoExpireList($time, $versions) {
$size = 0;
$toDelete = []; // versions we want to delete
$interval = 1;
Method store
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function store($filename) {
if (\OC::$server->getConfig()->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
// if the file gets streamed we need to remove the .part extension
// to get the right target
$ext = \pathinfo($filename, PATHINFO_EXTENSION);
Method expireOlderThanMaxForUser
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function expireOlderThanMaxForUser($uid) {
$expiration = self::getExpiration();
$threshold = $expiration->getMaxAgeAsTimestamp();
$versions = self::getFileHelper()->getAllVersions($uid);
if (!$threshold || !\array_key_exists('all', $versions)) {
Function isFolderEmpty
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function isFolderEmpty($view, $dir) {
if ($dir === '' || $dir === '.' || $dir === '/') {
// root folder won't be considered as empty
return false;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method delete
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function delete($path) {
$deletedFile = self::$deletedFiles[$path];
$uid = $deletedFile['uid'];
$filename = $deletedFile['filename'];
Function restoreVersion
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function restoreVersion($uid, $filename, $fileToRestore, $revision) {
if (\OC::$server->getConfig()->getSystemValue('files_versions', Storage::DEFAULTENABLED) !== true) {
return false;
}
$users_view = new View('/'.$uid);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function delete
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function delete($path) {
$deletedFile = self::$deletedFiles[$path];
$uid = $deletedFile['uid'];
$filename = $deletedFile['filename'];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if (self::metaEnabled()) {
$versionFileInfo = $view->getFileInfo("$dir/$entryName");
if ($versionFileInfo) {
$versionMetadata = self::$metaData->getVersionMetadata($versionFileInfo);
Function getHumanReadableTimestamp
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function getHumanReadableTimestamp($timestamp) {
$diff = \time() - $timestamp;
if ($diff < 60) { // first minute
return $diff . " seconds ago";
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return \round($diff / 604800) . " weeks ago";
Avoid too many return
statements within this method. Open
return \round($diff / 2419200) . " months ago";
Avoid too many return
statements within this method. Open
return \round($diff / 29030400) . " years ago";
Function postStore
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function postStore(string $filename) {
if (self::metaEnabled()) {
// we don't support versioned directories
if (Filesystem::is_dir($filename) || !Filesystem::file_exists($filename)) {
return false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getExpireList
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected static function getExpireList($time, $versions, $quotaExceeded = false) {
$expiration = self::getExpiration();
if ($expiration->shouldAutoExpire() && \count($versions) > 0) {
list($toDelete, $size) = self::getAutoExpireList($time, $versions);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function isPublishedVersion
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected static function isPublishedVersion($view, $path) {
if (self::metaEnabled()) {
$versionFileInfo = $view->getFileInfo($path);
if ($versionFileInfo) {
$versionMetadata = self::$metaData->getVersionMetadata($versionFileInfo);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"