synchronize accesses the super-global variable $_ENV. Open
public function synchronize($source, $mirror, $keepFolderName = false)
{
$source = rtrim($source, '/') . ($keepFolderName ? '' : '/');
$mirror = rtrim($mirror, '/') . '/';
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
downloadFile accesses the super-global variable $_ENV. Open
public function downloadFile($filename, $target = ''): string
{
if ($filename[0] != '/') {
$filename = $this->instance->getWebPath($filename);
}
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
copyLocalFolder accesses the super-global variable $_ENV. Open
public function copyLocalFolder($localFolder, $remoteFolder = '')
{
if ($remoteFolder[0] != '/') {
$remoteFolder = $this->instance->getWebPath($remoteFolder);
}
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
The class FTP has 19 public methods. Consider refactoring FTP to keep number of public methods under 10. Open
class FTP extends Access implements Mountable
{
private $lastMount;
public function __construct(Instance $instance)
- 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 FTP has an overall complexity of 51 which is very high. The configured complexity threshold is 50. Open
class FTP extends Access implements Mountable
{
private $lastMount;
public function __construct(Instance $instance)
- Exclude checks
FTP
has 25 functions (exceeds 20 allowed). Consider refactoring. Open
class FTP extends Access implements Mountable
{
private $lastMount;
public function __construct(Instance $instance)
File FTP.php
has 261 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.
Method localizeFolder
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function localizeFolder($remoteLocation, $localMirror)
{
if ($remoteLocation[0] != '/') {
$remoteLocation = $this->instance->getWebPath($remoteLocation);
}
The method synchronize has a boolean flag argument $keepFolderName, which is a certain sign of a Single Responsibility Principle violation. Open
public function synchronize($source, $mirror, $keepFolderName = 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 localizeFolder uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
`tar -xf $eLoc`;
}
- 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 uploadFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$host->sendFile($filename, $this->instance->getWebPath($remoteLocation));
}
- 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
TODO found Open
// TODO: change directory using FTP
- Exclude checks
Argument 1 (str)
is int
but \md5()
takes string
Open
$name = md5(time()) . '.tar';
- Exclude checks
Argument 1 (str)
is int
but \md5()
takes string
Open
$name = md5(time()) . '.tar';
- Exclude checks
Assigning 21
to property but \TikiManager\Access\FTP->port
is string
Open
$this->port = 21;
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function moveFile($remoteSource, $remoteTarget)
{
if ($remoteSource[0] != '/') {
$remoteSource = $this->instance->getWebPath($remoteSource);
}
- 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 90.
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
public function copyFile($remoteSource, $remoteTarget)
{
if ($remoteSource[0] != '/') {
$remoteSource = $this->instance->getWebPath($remoteSource);
}
- 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 90.
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