File Restore.php
has 533 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
// Copyright (c) 2016, Avan.Tech, et. al.
// Copyright (c) 2008, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
Function restoreFolder
has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring. Open
public function restoreFolder($src, $target, $isFull = false)
{
$access = $this->getAccess();
$instance = $this->instance;
$src = rtrim($src, '/\\');
- 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 restoreFolder
has 127 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function restoreFolder($src, $target, $isFull = false)
{
$access = $this->getAccess();
$instance = $this->instance;
$src = rtrim($src, '/\\');
Restore
has 30 functions (exceeds 20 allowed). Consider refactoring. Open
class Restore extends Backup
{
const CLONE_PROCESS = 'clone';
const RESTORE_PROCESS = 'restore';
Function readManifest
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
public function readManifest($manifestPath)
{
$access = $this->getAccess();
if ($this->direct && $this->source->type == 'local') {
- 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
The class Restore has 14 public methods. Consider refactoring Restore to keep number of public methods under 10. Open
class Restore extends Backup
{
const CLONE_PROCESS = 'clone';
const RESTORE_PROCESS = 'restore';
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class Restore has an overall complexity of 121 which is very high. The configured complexity threshold is 50. Open
class Restore extends Backup
{
const CLONE_PROCESS = 'clone';
const RESTORE_PROCESS = 'restore';
- Exclude checks
Method readManifest
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function readManifest($manifestPath)
{
$access = $this->getAccess();
if ($this->direct && $this->source->type == 'local') {
Function readSystemIniConfigFileFromManifest
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function readSystemIniConfigFileFromManifest($manifest_file)
{
$result = [];
$access = $this->getAccess();
$manifest = $access->fileGetContents($manifest_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
Function restoreFilesFromFolder
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function restoreFilesFromFolder(string $srcFolder)
{
$manifest = "{$srcFolder}/manifest.txt";
$folders = $this->readManifest($manifest);
- 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 readSystemIniConfigFileFromManifest
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function readSystemIniConfigFileFromManifest($manifest_file)
{
$result = [];
$access = $this->getAccess();
$manifest = $access->fileGetContents($manifest_file);
Method decompressArchive
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function decompressArchive($folder, $archive)
{
$access = $this->access;
$bzipStep = false;
Function setIniFilesToExclude
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function setIniFilesToExclude($manifest)
{
$system_config_file_info = $this->readSystemIniConfigFileFromManifest($manifest);
- 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 decompressArchive
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function decompressArchive($folder, $archive)
{
$access = $this->access;
$bzipStep = 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
The method restoreFolder() has 156 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function restoreFolder($src, $target, $isFull = false)
{
$access = $this->getAccess();
$instance = $this->instance;
$src = rtrim($src, '/\\');
- Exclude checks
The method readManifest() has an NPath complexity of 3462. The configured NPath complexity threshold is 200. Open
public function readManifest($manifestPath)
{
$access = $this->getAccess();
if ($this->direct && $this->source->type == 'local') {
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method restoreFolder() has an NPath complexity of 7206. The configured NPath complexity threshold is 200. Open
public function restoreFolder($src, $target, $isFull = false)
{
$access = $this->getAccess();
$instance = $this->instance;
$src = rtrim($src, '/\\');
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method restoreFolder() has a Cyclomatic Complexity of 25. The configured cyclomatic complexity threshold is 10. Open
public function restoreFolder($src, $target, $isFull = false)
{
$access = $this->getAccess();
$instance = $this->instance;
$src = rtrim($src, '/\\');
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method readManifest() has a Cyclomatic Complexity of 18. The configured cyclomatic complexity threshold is 10. Open
public function readManifest($manifestPath)
{
$access = $this->getAccess();
if ($this->direct && $this->source->type == 'local') {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method __construct has a boolean flag argument $onlyData, which is a certain sign of a Single Responsibility Principle violation. Open
public function __construct(Instance $instance, bool $direct = false, bool $onlyData = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method __construct has a boolean flag argument $direct, which is a certain sign of a Single Responsibility Principle violation. Open
public function __construct(Instance $instance, bool $direct = false, bool $onlyData = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method restoreFolder has a boolean flag argument $isFull, which is a certain sign of a Single Responsibility Principle violation. Open
public function restoreFolder($src, $target, $isFull = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid using static access to class '\TikiManager\Libs\Helpers\ApplicationHelper' in method 'removeFolder'. Open
if (ApplicationHelper::isWindows()) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method restoreFromVCS uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return false;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid assigning values to variables in if clauses and the like (line '402', column '17'). Open
public function restoreFolder($src, $target, $isFull = false)
{
$access = $this->getAccess();
$instance = $this->instance;
$src = rtrim($src, '/\\');
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method readManifest uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$source = $archiveFolder . DIRECTORY_SEPARATOR . $hash;
$source .= $type != 'conf_external' ? DIRECTORY_SEPARATOR . basename($destination) : '';
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method readManifest uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->io->warning("{Skipping {$destination}. Path shouldn't have absolute paths, to avoid override data.");
continue;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method restoreFolder uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$rsyncFlags = [
'-a',
$isFull ? '--delete' : '--force'
];
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\TikiManager\Libs\Helpers\ApplicationHelper' in method 'decompressArchive'. Open
if (ApplicationHelper::isWindows()) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\TikiManager\Libs\Helpers\ApplicationHelper' in method 'readManifest'. Open
$destination = ApplicationHelper::getAbsolutePath($destination);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method restoreFilesFromFolder uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->getAccess()->uploadFile($src, $target);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\TikiManager\Libs\Helpers\ApplicationHelper' in method 'restoreFolder'. Open
if (ApplicationHelper::isWindows() && $instance->type == 'local') {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid assigning values to variables in if clauses and the like (line '396', column '17'). Open
public function restoreFolder($src, $target, $isFull = false)
{
$access = $this->getAccess();
$instance = $this->instance;
$src = rtrim($src, '/\\');
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid unused local variables such as '$matches'. Open
$windowsAbsolutePaths = (preg_match($windowsAbsolutePathsRegex, $destination, $matches)) ? true : false;
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Argument 1 (str)
is ?string
but \rtrim()
takes string
Open
$src = rtrim($src, '/\\');
- Exclude checks
Argument 1 (str)
is int
but \md5()
takes string
Open
$dest = implode(\DIRECTORY_SEPARATOR, [Environment::get('TEMP_FOLDER'), md5(time()), $this->instance->name]);
- Exclude checks
Saw an @param annotation for manifest_file,
but it was not found in the param list of function setIniFilesToExclude($manifest)
Open
* @param $manifest_file
- Exclude checks
The parameter $manifest_file is not named in camelCase. Open
public function readSystemIniConfigFileFromManifest($manifest_file)
{
$result = [];
$access = $this->getAccess();
$manifest = $access->fileGetContents($manifest_file);
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The variable $system_config_file_info is not named in camelCase. Open
public function setIniFilesToExclude($manifest)
{
$system_config_file_info = $this->readSystemIniConfigFileFromManifest($manifest);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $system_config_file_info is not named in camelCase. Open
public function setIniFilesToExclude($manifest)
{
$system_config_file_info = $this->readSystemIniConfigFileFromManifest($manifest);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $system_config_file_info is not named in camelCase. Open
public function setIniFilesToExclude($manifest)
{
$system_config_file_info = $this->readSystemIniConfigFileFromManifest($manifest);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $system_config_file_info is not named in camelCase. Open
public function setIniFilesToExclude($manifest)
{
$system_config_file_info = $this->readSystemIniConfigFileFromManifest($manifest);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $manifest_file is not named in camelCase. Open
public function readSystemIniConfigFileFromManifest($manifest_file)
{
$result = [];
$access = $this->getAccess();
$manifest = $access->fileGetContents($manifest_file);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}