File Share.php
has 2250 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Bart Visscher <bartv@thisnet.nl>
* @author Bernhard Reiter <ockham@raz.or.at>
Function getItems
has a Cognitive Complexity of 275 (exceeds 5 allowed). Consider refactoring. Open
public static function getItems(
$itemType,
$item = null,
$shareType = null,
$shareWith = null,
- 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 shareItem
has a Cognitive Complexity of 106 (exceeds 5 allowed). Consider refactoring. Open
public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null, $passwordChanged = null) {
$backend = self::getBackend($itemType);
$l = \OC::$server->getL10N('lib');
if ($backend->isShareTypeAllowed($shareType) === 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 getUsersSharingFile
has a Cognitive Complexity of 92 (exceeds 5 allowed). Consider refactoring. Open
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
$userManager = \OC::$server->getUserManager();
$userObject = $userManager->get($ownerUser);
if ($userObject === null) {
- 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 getItems
has 344 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getItems(
$itemType,
$item = null,
$shareType = null,
$shareWith = null,
Method shareItem
has 287 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null, $passwordChanged = null) {
$backend = self::getBackend($itemType);
$l = \OC::$server->getL10N('lib');
if ($backend->isShareTypeAllowed($shareType) === false) {
Method put
has 210 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function put(
$itemType,
$itemSource,
$shareType,
$shareWith,
Function put
has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring. Open
private static function put(
$itemType,
$itemSource,
$shareType,
$shareWith,
- 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
Share
has 56 functions (exceeds 20 allowed). Consider refactoring. Open
class Share extends Constants {
/** CRUDS permissions (Create, Read, Update, Delete, Share) using a bitmask
* Construct permissions for share() and setPermissions with Or (|) e.g.
* Give user read and update permissions: PERMISSION_READ | PERMISSION_UPDATE
*
Function setPermissions
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
$l = \OC::$server->getL10N('lib');
$connection = \OC::$server->getDatabaseConnection();
$intArrayToLiteralArray = function ($intArray, $eb) {
- 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 getUsersSharingFile
has 169 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
$userManager = \OC::$server->getUserManager();
$userObject = $userManager->get($ownerUser);
if ($userObject === null) {
Function checkReshare
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
private static function checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate) {
$backend = self::getBackend($itemType);
$l = \OC::$server->getL10N('lib');
$result = [];
- 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 setPermissions
has 133 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
$l = \OC::$server->getL10N('lib');
$connection = \OC::$server->getDatabaseConnection();
$intArrayToLiteralArray = function ($intArray, $eb) {
Function getItemSharedWithUser
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
public static function getItemSharedWithUser($itemType, $itemSource, $user, $owner = null, $shareType = null) {
$shares = [];
$fileDependent = false;
$where = 'WHERE';
- 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 unshareFromSelf
has 83 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function unshareFromSelf($itemType, $itemOrigin, $originIsSource = false) {
$originType = ($originIsSource) ? 'source' : 'target';
$uid = \OCP\User::getUser();
if ($itemType === 'file' || $itemType === 'folder') {
Function unshareFromSelf
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
public static function unshareFromSelf($itemType, $itemOrigin, $originIsSource = false) {
$originType = ($originIsSource) ? 'source' : 'target';
$uid = \OCP\User::getUser();
if ($itemType === 'file' || $itemType === 'folder') {
- 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 checkReshare
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate) {
$backend = self::getBackend($itemType);
$l = \OC::$server->getL10N('lib');
$result = [];
Method getItemSharedWithUser
has 73 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getItemSharedWithUser($itemType, $itemSource, $user, $owner = null, $shareType = null) {
$shares = [];
$fileDependent = false;
$where = 'WHERE';
Function createSelectStatement
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
private static function createSelectStatement($format, $fileDependent, $uidOwner = null) {
$select = '*';
if ($format == self::FORMAT_STATUSES) {
if ($fileDependent) {
$select = '`*PREFIX*share`.`id`, `*PREFIX*share`.`parent`, `share_type`, `path`, `storage`, '
- 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 formatResult
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private static function formatResult($items, $column, $backend, $format = self::FORMAT_NONE, $parameters = null) {
if ($format === self::FORMAT_NONE) {
return $items;
} elseif ($format === self::FORMAT_STATUSES) {
$statuses = [];
- 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 groupItems
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
protected static function groupItems($items, $itemType) {
$fileSharing = ($itemType === 'file' || $itemType === 'folder') ? true : false;
$result = [];
- 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 createSelectStatement
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function createSelectStatement($format, $fileDependent, $uidOwner = null) {
$select = '*';
if ($format == self::FORMAT_STATUSES) {
if ($fileDependent) {
$select = '`*PREFIX*share`.`id`, `*PREFIX*share`.`parent`, `share_type`, `path`, `storage`, '
Function getSharedItemsOwners
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function getSharedItemsOwners($user, $type, $includeCollections = false, $includeOwner = false) {
// First, we find out if $type is part of a collection (and if that collection is part of
// another one and so on).
$collectionTypes = [];
if (!$includeCollections || !$collectionTypes = self::getCollectionItemTypes($type)) {
- 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 getItems
has 11 arguments (exceeds 4 allowed). Consider refactoring. Open
$itemType,
$item = null,
$shareType = null,
$shareWith = null,
$uidOwner = null,
Method registerBackend
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) {
if (self::isEnabled()) {
if (!isset(self::$backendTypes[$itemType])) {
self::$backendTypes[$itemType] = [
'class' => $class,
Method put
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
$itemType,
$itemSource,
$shareType,
$shareWith,
$uidOwner,
Method validateExpireDate
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function validateExpireDate($expireDate, $shareTime, $itemType, $itemSource) {
$l = \OC::$server->getL10N('lib');
$date = new \DateTime($expireDate);
$today = new \DateTime('now');
Method setExpirationDate
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null) {
$user = \OC_User::getUser();
$l = \OC::$server->getL10N('lib');
if ($date == '') {
Function transformDBResults
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function transformDBResults(&$row) {
if (isset($row['id'])) {
$row['id'] = (int) $row['id'];
}
if (isset($row['share_type'])) {
- 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 transformDBResults
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function transformDBResults(&$row) {
if (isset($row['id'])) {
$row['id'] = (int) $row['id'];
}
if (isset($row['share_type'])) {
Method unshareItem
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected static function unshareItem(array $item, $newParent = null) {
$shareType = (int)$item['share_type'];
$shareWith = null;
if ($shareType !== \OCP\Share::SHARE_TYPE_LINK) {
$shareWith = $item['share_with'];
Method getSharedItemsOwners
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getSharedItemsOwners($user, $type, $includeCollections = false, $includeOwner = false) {
// First, we find out if $type is part of a collection (and if that collection is part of
// another one and so on).
$collectionTypes = [];
if (!$includeCollections || !$collectionTypes = self::getCollectionItemTypes($type)) {
Method shareItem
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null, $passwordChanged = null) {
Method checkReshare
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate) {
Function expireItem
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected static function expireItem(array $item) {
$result = false;
// only use default expiration date for link shares
if ((int) $item['share_type'] === self::SHARE_TYPE_LINK) {
- 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 ($items[$id]['share_type'] != self::SHARE_TYPE_GROUP) {
$items[$id]['share_type'] = self::SHARE_TYPE_GROUP;
$items[$id]['share_with'] = $row['share_with'];
}
Avoid deeply nested control flow statements. Open
if (~(int)$items[$id]['permissions'] & \OCP\Constants::PERMISSION_SHARE
&& (int)$row['permissions'] & \OCP\Constants::PERMISSION_SHARE) {
$items[$row['id']] = $items[$id];
$switchedItems[$id] = $row['id'];
unset($items[$id]);
Avoid deeply nested control flow statements. Open
if ($item['permissions'] & ~$permissions) {
// Add to list of items that need permissions removed
$ids[] = $item['id'];
$parents[] = $item['id'];
}
Function getBackend
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function getBackend($itemType) {
$l = \OC::$server->getL10N('lib');
if (isset(self::$backends[$itemType])) {
return self::$backends[$itemType];
} elseif (isset(self::$backendTypes[$itemType]['class'])) {
- 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 getItemsSharedWithUser
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
$itemType,
$user,
$format = self::FORMAT_NONE,
$parameters = null,
$limit = -1,
Method getItemSharedWithBySource
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
$itemType,
$itemSource,
$format = self::FORMAT_NONE,
$parameters = null,
$includeCollections = false,
Consider simplifying this complex logical expression. Open
if (($fileSharing && $item['file_source'] === $r['file_source'] && $item['file_target'] === $r['file_target']) ||
(!$fileSharing && $item['item_source'] === $r['item_source'] && $item['item_target'] === $r['item_target'])) {
// add the first item to the list of grouped shares
if (!isset($result[$key]['grouped'])) {
$result[$key]['grouped'][] = $result[$key];
Consider simplifying this complex logical expression. Open
if ($includeCollections && $collectionTypes && $row['item_type'] !== 'folder' && \in_array($row['item_type'], $collectionTypes)) {
if (($collectionBackend = self::getBackend($row['item_type']))
&& $collectionBackend instanceof \OCP\Share_Backend_Collection) {
// Collections can be inside collections, check if the item is a collection
if (isset($item) && $row['item_type'] == $itemType && $row[$column] == $item) {
Method getItemsShared
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$itemType,
$format = self::FORMAT_NONE,
$parameters = null,
$limit = -1,
$includeCollections = false
Method getItemShared
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$itemType,
$itemSource,
$format = self::FORMAT_NONE,
$parameters = null,
$includeCollections = false
Method unshare
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function unshare($itemType, $itemSource, $shareType, $shareWith, $owner = null) {
Method getUsersItemShared
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false, $checkExpireDate = true) {
Method getUsersSharingFile
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
Method formatResult
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function formatResult($items, $column, $backend, $format = self::FORMAT_NONE, $parameters = null) {
Method setSendMailStatus
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function setSendMailStatus($itemType, $itemSource, $shareType, $recipient, $status) {
Method setPassword
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
IUserSession $userSession,
IDBConnection $connection,
IConfig $config,
$shareId,
$password
Method getItemSharedWith
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$itemType,
$itemTarget,
$format = self::FORMAT_NONE,
$parameters = null,
$includeCollections = false
Method setPermissions
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
Method sendRemoteShare
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner) {
Method getItemSharedWithUser
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function getItemSharedWithUser($itemType, $itemSource, $user, $owner = null, $shareType = null) {
Method getItemsSharedWith
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$itemType,
$format = self::FORMAT_NONE,
$parameters = null,
$limit = -1,
$includeCollections = false
Function getCollectionItemTypes
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function getCollectionItemTypes($itemType) {
$collectionTypes = [$itemType];
foreach (self::$backendTypes as $type => $backend) {
if (\in_array($backend['collectionOf'], $collectionTypes)) {
$collectionTypes[] = $type;
- 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 getUsersItemShared
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false, $checkExpireDate = true) {
$users = [];
$items = self::getItems($itemType, $itemSource, null, null, $uidOwner, self::FORMAT_NONE, null, -1, $includeCollections, false, $checkExpireDate);
if ($items) {
foreach ($items as $item) {
- 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 unshare
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function unshare($itemType, $itemSource, $shareType, $shareWith, $owner = null) {
// check if it is a valid itemType
self::getBackend($itemType);
$items = self::getItemSharedWithUser($itemType, $itemSource, $shareWith, $owner, $shareType);
- 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 resolveReShare
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function resolveReShare($linkItem) {
if (isset($linkItem['parent'])) {
$parent = $linkItem['parent'];
while (isset($parent)) {
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `id` = ?', 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
Avoid too many return
statements within this method. Open
return self::formatResult($items, $column, $backend, $format, $parameters);
Avoid too many return
statements within this method. Open
return [];
Avoid too many return
statements within this method. Open
return self::formatResult($collectionItems, $column, $backend, $format, $parameters);
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $result ? true : false;
Avoid too many return
statements within this method. Open
return \reset($collectionItems);
Function checkPasswordProtectedShare
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function checkPasswordProtectedShare(array $linkItem) {
if (!isset($linkItem['share_with'])) {
return true;
}
if (!isset($linkItem['share_type'])) {
- 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 registerBackend
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) {
if (self::isEnabled()) {
if (!isset(self::$backendTypes[$itemType])) {
self::$backendTypes[$itemType] = [
'class' => $class,
- 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 validateExpireDate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function validateExpireDate($expireDate, $shareTime, $itemType, $itemSource) {
$l = \OC::$server->getL10N('lib');
$date = new \DateTime($expireDate);
$today = new \DateTime('now');
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!$publicShare) {
$query = \OC_DB::prepare(
'
SELECT `share_with`
FROM `*PREFIX*share`
- 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 103.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!$remoteShare) {
$query = \OC_DB::prepare(
'
SELECT `share_with`
FROM `*PREFIX*share`
- 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 103.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ($checkExists = self::getItems(
$itemType,
$itemSource,
self::SHARE_TYPE_USER,
$shareWith,
- 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 98.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ($checkExists = self::getItems(
$itemType,
$itemSource,
self::$shareTypeUserAndGroups,
$shareWith,
- 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 98.
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