Broadcast
has 30 functions (exceeds 20 allowed). Consider refactoring. Open
class Broadcast extends database_object implements library_item
{
protected const DB_TABLENAME = 'broadcast';
public int $id = 0;
The class Broadcast has 12 public methods. Consider refactoring Broadcast to keep number of public methods under 10. Open
class Broadcast extends database_object implements library_item
{
protected const DB_TABLENAME = 'broadcast';
public int $id = 0;
- 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 Broadcast has 45 public methods and attributes. Consider reducing the number of public items to less than 45. Open
class Broadcast extends database_object implements library_item
{
protected const DB_TABLENAME = 'broadcast';
public int $id = 0;
- Read upRead up
- Exclude checks
ExcessivePublicCount
Since: 0.1
A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.
Example
public class Foo {
public $value;
public $something;
public $var;
// [... more more public attributes ...]
public function doWork() {}
public function doMoreWork() {}
public function doWorkAgain() {}
// [... more more public methods ...]
}
Source https://phpmd.org/rules/codesize.html#excessivepubliccount
Avoid assigning values to variables in if clauses and the like (line '351', column '13'). Open
public static function get_broadcast($key): ?Broadcast
{
$sql = "SELECT `id` FROM `broadcast` WHERE `key` = ?";
$db_results = Dba::read($sql, array($key));
- 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
syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
Open
public int $id = 0;
- Exclude checks
The parameter $additional_params is not named in camelCase. Open
public function play_url($additional_params = '', $player = '', $local = false): string
{
unset($additional_params, $player, $local);
return (string)$this->id;
- 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 $broadcast_id is not named in camelCase. Open
public function __construct($broadcast_id = 0)
{
if (!$broadcast_id) {
return;
}
- 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 $broadcast_id is not named in camelCase. Open
public static function get_unbroadcast_link($broadcast_id): string
{
$link = "<div class=\"broadcast-action\">";
$link .= Ajax::button(
'?page=player&action=unbroadcast&broadcast_id=' . $broadcast_id,
- 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 $user_id is not named in camelCase. Open
public static function get_broadcasts($user_id): array
{
$sql = "SELECT `id` FROM `broadcast` WHERE `user` = ?";
$db_results = Dba::read($sql, array($user_id));
- 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
Avoid variables with short names like $id. Configured minimum length is 3. Open
public int $id = 0;
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The parameter $filter_type is not named in camelCase. Open
public function get_medias(?string $filter_type = null): array
{
// Not a media, shouldn't be that
$medias = array();
if ($filter_type === null || $filter_type === 'broadcast') {
- 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 $song_id is not named in camelCase. Open
public function update_song($song_id): void
{
$sql = "UPDATE `broadcast` SET `song` = ? WHERE `id` = ?";
Dba::write($sql, array($song_id, $this->id));
$this->song = $song_id;
- 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) {
}
}