File Manager.php
has 1180 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Björn Schießle <bjoern@schiessle.org>
* @author Joas Schilling <coding@schilljs.com>
Manager
has 69 functions (exceeds 20 allowed). Consider refactoring. Open
class Manager implements IManager {
/** @var IProviderFactory */
private $factory;
/** @var ILogger */
private $logger;
Function validatePermissions
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
protected function validatePermissions(IShare $share) {
// Permissions should be set
if ($share->getPermissions() === null) {
throw new \InvalidArgumentException('A share requires permissions');
}
- 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 transferShare
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
public function transferShare(IShare $share, $oldOwner, $newOwner, $finalTarget, $isChild = null) {
if ($this->userManager->get($oldOwner) === null) {
throw new TransferSharesException("The current owner of the share $oldOwner doesn't exist");
}
if ($this->userManager->get($newOwner) === 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 updateShare
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public function updateShare(\OCP\Share\IShare $share, $skipExpirationValidation = false) {
$expirationDateUpdated = false;
$this->canShare($share);
- 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 updateShare
has 104 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function updateShare(\OCP\Share\IShare $share, $skipExpirationValidation = false) {
$expirationDateUpdated = false;
$this->canShare($share);
Function getSharesBy
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
if ($path !== null &&
!($path instanceof \OCP\Files\File) &&
!($path instanceof \OCP\Files\Folder)) {
throw new \InvalidArgumentException('invalid 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 createShare
has 97 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function createShare(\OCP\Share\IShare $share) {
$this->canShare($share);
// Verify if there are any issues with the path
$this->pathCreateChecks($share->getNode());
Function getSharedWith
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) {
$provider = $this->factory->getProviderForType($shareType);
$shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset);
- 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 generalChecks
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
protected function generalChecks(\OCP\Share\IShare $share) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
// We expect a valid user as sharedWith for user shares
if (!$this->userManager->userExists($share->getSharedWith())) {
throw new \InvalidArgumentException('SharedWith is not a valid user');
- 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 userCreateChecks
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
protected function userCreateChecks(\OCP\Share\IShare $share) {
$userTypeHelper = new UserTypeHelper();
$isGuestUser = $userTypeHelper->isGuestUser($share->getSharedWith());
// Check if we can share with group members only
// We still should be able to share with guest user even when it's not a group member
- 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 validateExpirationDate
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function validateExpirationDate(\OCP\Share\IShare $share, $skipPastDateValidation = false) {
$expirationDate = $share->getExpirationDate();
if ($expirationDate !== null) {
// Set the expiration date to just the date at "zero" time in the day
Method validatePermissions
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function validatePermissions(IShare $share) {
// Permissions should be set
if ($share->getPermissions() === null) {
throw new \InvalidArgumentException('A share requires permissions');
}
Function validateExpirationDate
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
protected function validateExpirationDate(\OCP\Share\IShare $share, $skipPastDateValidation = false) {
$expirationDate = $share->getExpirationDate();
if ($expirationDate !== null) {
// Set the expiration date to just the date at "zero" time in the day
- 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 transferShare
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function transferShare(IShare $share, $oldOwner, $newOwner, $finalTarget, $isChild = null) {
if ($this->userManager->get($oldOwner) === null) {
throw new TransferSharesException("The current owner of the share $oldOwner doesn't exist");
}
if ($this->userManager->get($newOwner) === null) {
Function createShare
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function createShare(\OCP\Share\IShare $share) {
$this->canShare($share);
// Verify if there are any issues with the path
$this->pathCreateChecks($share->getNode());
- 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 getShareByToken
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function getShareByToken($token) {
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK);
try {
$share = $provider->getShareByToken($token);
- 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 getShareByToken
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getShareByToken($token) {
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK);
try {
$share = $provider->getShareByToken($token);
Method __construct
has 15 arguments (exceeds 4 allowed). Consider refactoring. Open
ILogger $logger,
IConfig $config,
ISecureRandom $secureRandom,
IHasher $hasher,
IMountManager $mountManager,
Method generalChecks
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function generalChecks(\OCP\Share\IShare $share) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
// We expect a valid user as sharedWith for user shares
if (!$this->userManager->userExists($share->getSharedWith())) {
throw new \InvalidArgumentException('SharedWith is not a valid user');
Function groupCreateChecks
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
protected function groupCreateChecks(\OCP\Share\IShare $share) {
// Verify group shares are allowed
if (!$this->allowGroupSharing()) {
throw new \Exception('Group sharing is not allowed');
}
- 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 getSharesBy
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
if ($path !== null &&
!($path instanceof \OCP\Files\File) &&
!($path instanceof \OCP\Files\Folder)) {
throw new \InvalidArgumentException('invalid path');
Function getAllSharesBy
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function getAllSharesBy($userId, $shareTypes, $nodeIDs, $reshares = false) {
// This function requires at least 1 node (parent folder)
if (empty($nodeIDs)) {
throw new \InvalidArgumentException('Array of nodeIDs empty');
}
- 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 getSharedWith
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) {
$provider = $this->factory->getProviderForType($shareType);
$shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset);
Function getAllSharedWith
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function getAllSharedWith($userId, $shareTypes, $node = null) {
$shares = [];
// Aggregate all required $shareTypes by mapping provider to supported shareTypes
$providerIdMap = $this->shareTypeToProviderMap($shareTypes);
- 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 userCreateChecks
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function userCreateChecks(\OCP\Share\IShare $share) {
$userTypeHelper = new UserTypeHelper();
$isGuestUser = $userTypeHelper->isGuestUser($share->getSharedWith());
// Check if we can share with group members only
// We still should be able to share with guest user even when it's not a group member
Method getSharesBy
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
Method transferShare
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function transferShare(IShare $share, $oldOwner, $newOwner, $finalTarget, $isChild = null) {
Method getSharedWith
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) {
Function sharingDisabledForUser
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function sharingDisabledForUser($userId) {
if ($userId === null) {
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 cleanSharesWithInvalidNodes
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function cleanSharesWithInvalidNodes() {
$types = [
\OCP\Share::SHARE_TYPE_USER,
\OCP\Share::SHARE_TYPE_GROUP,
\OCP\Share::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
Function pathCreateChecks
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function pathCreateChecks($path) {
// Make sure that we do not share a path that contains a shared mountpoint
if ($path instanceof \OCP\Files\Folder) {
$mounts = $this->mountManager->findIn($path->getPath());
foreach ($mounts as $mount) {
- 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
foreach ($shares as $share) {
// Check if the share is expired and if so delete it
if (self::shareHasExpired($share)) {
$this->activityManager->setAgentAuthor(IEvent::AUTOMATION_AUTHOR);
try {
- 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 95.
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
foreach ($shares as $share) {
// Check if the share is expired and if so delete it
if (self::shareHasExpired($share)) {
$this->activityManager->setAgentAuthor(IEvent::AUTOMATION_AUTHOR);
try {
- 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 95.
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