File Trashbin.php
has 683 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* @author Bart Visscher <bartv@thisnet.nl>
* @author Bastien Ho <bastienho@urbancube.fr>
* @author Björn Schießle <bjoern@schiessle.org>
Function retainVersions
has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring. Open
private static function retainVersions($filename, $owner, $ownerPath, $timestamp, $sourceStorage = null, $forceCopy = false) {
if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {
$copyKeysResult = false;
// Temporary
- 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 restoreVersionsFromTrashbin
has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring. Open
private static function restoreVersionsFromTrashbin(View $view, $filename, $targetLocation) {
if (\OCP\App::isEnabled('files_versions')) {
$user = User::getUser();
$rootView = new View('/');
- 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
Trashbin
has 35 functions (exceeds 20 allowed). Consider refactoring. Open
class Trashbin {
/**
* @var IURLGenerator
*/
private $urlGenerator;
Function move2trash
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public static function move2trash($file_path) {
// get the user for which the filesystem is setup
$root = Filesystem::getRoot();
list(, $user) = \explode('/', $root);
list($owner, $ownerPath) = self::getUidAndFilename($file_path);
- 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 move2trash
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function move2trash($file_path) {
// get the user for which the filesystem is setup
$root = Filesystem::getRoot();
list(, $user) = \explode('/', $root);
list($owner, $ownerPath) = self::getUidAndFilename($file_path);
Function restore
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public static function restore($filename, $targetLocation = null) {
$user = User::getUser();
$view = new View('/' . $user);
$nameOfFile = \basename($filename);
$dirOfFile = \dirname($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
Method retainVersions
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function retainVersions($filename, $owner, $ownerPath, $timestamp, $sourceStorage = null, $forceCopy = false) {
if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {
$copyKeysResult = false;
// Temporary
Method restoreVersionsFromTrashbin
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function restoreVersionsFromTrashbin(View $view, $filename, $targetLocation) {
if (\OCP\App::isEnabled('files_versions')) {
$user = User::getUser();
$rootView = new View('/');
Function deleteVersions
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private static function deleteVersions(View $view, $file, $user) {
$size = 0;
if (\OCP\App::isEnabled('files_versions')) {
if ($view->is_dir('files_trashbin/versions/' . $file)) {
$size += self::calculateSize(new View('/' . $user . '/files_trashbin/versions/' . $file));
- 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 restore
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function restore($filename, $targetLocation = null) {
$user = User::getUser();
$view = new View('/' . $user);
$nameOfFile = \basename($filename);
$dirOfFile = \dirname($filename);
Function copy_recursive
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private static function copy_recursive($source, $destination, View $view) {
$size = 0;
if ($view->is_dir($source)) {
$view->mkdir($destination);
$view->touch($destination, $view->filemtime($source));
- 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 deleteVersions
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function deleteVersions(View $view, $file, $user) {
$size = 0;
if (\OCP\App::isEnabled('files_versions')) {
if ($view->is_dir('files_trashbin/versions/' . $file)) {
$size += self::calculateSize(new View('/' . $user . '/files_trashbin/versions/' . $file));
Function getVersionsFromTrash
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function getVersionsFromTrash($filename, $timestamp, $user) {
$view = new View('/' . $user . '/files_trashbin/versions');
$versions = [];
//force rescan of versions, local storage may not have updated the cache
- 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 copy_recursive
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function copy_recursive($source, $destination, View $view) {
$size = 0;
if ($view->is_dir($source)) {
$view->mkdir($destination);
$view->touch($destination, $view->filemtime($source));
Method retainVersions
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function retainVersions($filename, $owner, $ownerPath, $timestamp, $sourceStorage = null, $forceCopy = false) {
Method copyFilesToUser
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, $timestamp) {
Function resolvePrivateLink
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function resolvePrivateLink($uid, $fileId) {
if ($this->rootFolder->nodeExists($uid . '/files_trashbin/files/')) {
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
'@phan-var \OCP\Files\Folder $baseFolder';
$files = $baseFolder->getById($fileId);
- 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 isEmpty
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function isEmpty($user) {
$view = new View('/' . $user . '/files_trashbin');
if ($view->is_dir('/files') && $dh = $view->opendir('/files')) {
while ($file = \readdir($dh)) {
if (!Filesystem::isIgnoredDir($file)) {
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if ($dir === '/' || $dir === '.') {
$delimiter = \strrpos($filenameOnly, '.d');
$timestamp = \substr($filenameOnly, $delimiter+2);
$filenameOnlyWithoutTimestamp = \substr($filenameOnly, 0, $delimiter);
$dirAndFilename = $filenameOnlyWithoutTimestamp;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 113.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if ($dir === '/' || $dir === '.') {
$delimiter = \strrpos($filenameOnly, '.d');
$timestamp = \substr($filenameOnly, $delimiter+2);
$filenameOnlyWithoutTimestamp = \substr($filenameOnly, 0, $delimiter);
$dirAndFilename = $filenameOnlyWithoutTimestamp;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 113.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
$this->eventDispatcher->addListener(
'files.resolvePrivateLink',
function (GenericEvent $event) {
$uid = $event->getArgument('uid');
$fileId = $event->getArgument('fileid');
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 91.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76