Catalog_dropbox
has 32 functions (exceeds 20 allowed). Consider refactoring. Open
class Catalog_dropbox extends Catalog
{
private string $version = '000002';
private string $type = 'dropbox';
private string $description = 'Dropbox Remote Catalog';
The class Catalog_dropbox has 21 public methods. Consider refactoring Catalog_dropbox to keep number of public methods under 10. Open
class Catalog_dropbox extends Catalog
{
private string $version = '000002';
private string $type = 'dropbox';
private string $description = 'Dropbox Remote Catalog';
- 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 Catalog_dropbox has an overall complexity of 91 which is very high. The configured complexity threshold is 50. Open
class Catalog_dropbox extends Catalog
{
private string $version = '000002';
private string $type = 'dropbox';
private string $description = 'Dropbox Remote Catalog';
- Exclude checks
Function add_file
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function add_file($dropbox, $path): bool
{
$file = $dropbox->getMetadata($path, ["include_media_info" => true, "include_deleted" => true]);
$filesize = $file->getDataProperty('size');
if ($filesize > 0) {
- 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
File Catalog_dropbox.php
has 512 lines of code (exceeds 500 allowed). Consider refactoring. Open
<?php
/**
* vim:set softtabstop=4 shiftwidth=4 expandtab:
*
Function gather_art
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function gather_art($songs = null, $videos = null): bool
{
// Make sure they've actually got methods
$art_order = AmpConfig::get('art_order');
if (!count($art_order)) {
- 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 add_files
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function add_files($dropbox, $path): int
{
debug_event('dropbox.catalog', "List contents for " . $path, 5);
$listFolderContents = $dropbox->listFolder($path, ['recursive' => true]);
$songsadded = 0;
- 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 insert_video
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function insert_video($dropbox, $path): int
{
if ($this->check_remote_file($path)) {
debug_event('dropbox_catalog', 'Skipping existing song ' . $path, 5);
} else {
- 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 verify_catalog_proc
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function verify_catalog_proc(): int
{
set_time_limit(0);
$date = time();
- 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 insert_song
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function insert_song($dropbox, $path): bool
{
if ($this->check_remote_file($path)) {
debug_event('dropbox_catalog', 'Skipping existing song ' . $path, 5);
} else {
- 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 clean_catalog_proc
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function clean_catalog_proc(): int
{
$dead = 0;
$app = new DropboxApp($this->apikey, $this->secret, $this->authtoken);
$dropbox = new Dropbox($app);
- 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 true;
The class Catalog_dropbox has a coupling between objects value of 15. Consider to reduce the number of dependencies under 13. Open
class Catalog_dropbox extends Catalog
{
private string $version = '000002';
private string $type = 'dropbox';
private string $description = 'Dropbox Remote Catalog';
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
The method add_file uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
debug_event('dropbox.catalog', "read " . $path . " ignored, bad media type for this catalog.", 5);
}
- 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 add_file uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (count($this->get_gather_types('video')) > 0) {
if ($is_video_file && $this->insert_video($dropbox, $path)) {
return true;
} else {
- 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 insert_video uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
/* Create the vainfo object and get info */
$readfile = true;
$meta = $dropbox->getMetadata($path);
$outfile = Core::get_tmp_dir() . DIRECTORY_SEPARATOR . $meta->getName();
- 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 verify_catalog_proc uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
debug_event('dropbox.catalog', 'removing song', 5);
Ui::update_text('', sprintf(T_('Removing song: "%s"'), $row['title']));
Dba::write('DELETE FROM `song` WHERE `id` = ?', array($row['id']));
}
- 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 insert_song uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
debug_event(
'dropbox.catalog',
$results['file'] . " ignored because it is an orphan songs. Please check your catalog patterns.",
5
- 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 add_file uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
debug_event('dropbox.catalog', "read " . $path . " ignored, 0 bytes", 5);
}
- 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 insert_video uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->videos_to_gather[] = $video_id;
}
- 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 verify_catalog_proc uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
Ui::update_text('', sprintf(T_('Song up to date: "%s"'), $row['title']));
}
- 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 insert_song uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$meta = $dropbox->getMetadata($path);
$outfile = Core::get_tmp_dir() . DIRECTORY_SEPARATOR . $meta->getName();
// Download File
- 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 clean_catalog_proc uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
AmpError::add('general', T_('API Error: cannot connect to Dropbox.'));
}
- 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 check_remote_file uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$sql = 'SELECT `id` FROM `video` WHERE `file` = ?';
}
- 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 '672', column '13'). Open
public function check_remote_file($file)
{
$is_audio_file = Catalog::is_audio_file($file);
if ($is_audio_file) {
$sql = 'SELECT `id` FROM `song` WHERE `file` = ?';
- 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 insert_video uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
debug_event('dropbox.catalog', 'failed to download file', 5);
}
- 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 gather_art uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$searches['album'] = array();
$searches['artist'] = array();
foreach ($songs as $song) {
if ($song->isNew() === 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
The method add_file uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
debug_event('dropbox.catalog', "read " . $path . " ignored, bad media type for this video catalog.", 5);
}
- 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 unused local variables such as '$listFolderContents'. Open
$listFolderContents = $dropbox->listFolder($path);
- 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
Avoid unused private fields such as '$catalog_id'. Open
private int $catalog_id;
- Read upRead up
- Exclude checks
UnusedPrivateField
Since: 0.2
Detects when a private field is declared and/or assigned a value, but not used.
Example
class Something
{
private static $FOO = 2; // Unused
private $i = 5; // Unused
private $j = 6;
public function addOne()
{
return $this->j++;
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield
Avoid unused parameters such as '$new_path'. Open
public function move_catalog_proc($new_path): bool
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$videos'. Open
public function gather_art($songs = null, $videos = null): bool
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused local variables such as '$metadata'. Open
$metadata = $dropbox->getMetadata($file, ["include_deleted" => true]);
- 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
syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
Open
private string $version = '000002';
- Exclude checks
The parameter $catalog_id is not named in camelCase. Open
public function __construct($catalog_id = null)
{
if ($catalog_id) {
$this->id = (int)$catalog_id;
$info = $this->get_info($catalog_id, static::DB_TABLENAME);
- 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 class Catalog_dropbox is not named in CamelCase. Open
class Catalog_dropbox extends Catalog
{
private string $version = '000002';
private string $type = 'dropbox';
private string $description = 'Dropbox Remote Catalog';
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The parameter $catalog_id is not named in camelCase. Open
public static function create_type($catalog_id, $data): bool
{
$apikey = trim($data['apikey']);
$secret = trim($data['secret']);
$authtoken = trim($data['authtoken']);
- 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 parameter $new_path is not named in camelCase. Open
public function move_catalog_proc($new_path): bool
{
return false;
}
- 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 parameter $file_path is not named in camelCase. Open
public function get_rel_path($file_path): string
{
$path = strpos($file_path, "|");
if ($path !== false) {
$path++;
- 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
Class name "Catalog_dropbox" is not in camel caps format Open
class Catalog_dropbox extends Catalog
- Exclude checks