get_items accesses the super-global variable $_COOKIE. Open
public function get_items(): array
{
$session_name = AmpConfig::get('session_name');
$sql = "SELECT `tmp_playlist_data`.`object_type`, `tmp_playlist_data`.`id`, `tmp_playlist_data`.`object_id` FROM `tmp_playlist_data` ";
if (isset($_COOKIE[$session_name])) {
- 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
get_items accesses the super-global variable $_COOKIE. Open
public function get_items(): array
{
$session_name = AmpConfig::get('session_name');
$sql = "SELECT `tmp_playlist_data`.`object_type`, `tmp_playlist_data`.`id`, `tmp_playlist_data`.`object_id` FROM `tmp_playlist_data` ";
if (isset($_COOKIE[$session_name])) {
- 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 Tmp_Playlist has 11 public methods. Consider refactoring Tmp_Playlist to keep number of public methods under 10. Open
class Tmp_Playlist extends database_object
{
protected const DB_TABLENAME = 'tmp_playlist';
// Variables from the Database
- 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 method get_items uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// try to guess
$sql .= "WHERE `tmp_playlist` = ? ORDER BY `id`;";
$db_results = Dba::read($sql, array($this->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
syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
Open
public int $id = 0;
- Exclude checks
The parameter $object_id is not named in camelCase. Open
public function delete_track($object_id): bool
{
/* delete the track its self */
$sql = "DELETE FROM `tmp_playlist_data` WHERE `id` = ?";
Dba::write($sql, array($object_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 $playlist_id is not named in camelCase. Open
private function has_info($playlist_id): bool
{
$sql = "SELECT * FROM `tmp_playlist` WHERE `id` = ?;";
$db_results = Dba::read($sql, array($playlist_id));
$data = Dba::fetch_assoc($db_results);
- 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 $object_id is not named in camelCase. Open
public function add_object($object_id, $object_type): bool
{
$sql = "INSERT INTO `tmp_playlist_data` (`object_id`, `tmp_playlist`, `object_type`) VALUES (?, ?, ?)";
Dba::write($sql, array($object_id, $this->id, $object_type));
- 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 $plist_id is not named in camelCase. Open
public static function session_clean($sessid, $plist_id): void
{
$sql = "DELETE FROM `tmp_playlist` WHERE `session` = ? AND `id` != ?";
Dba::write($sql, array($sessid, $plist_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 class Tmp_Playlist is not named in CamelCase. Open
class Tmp_Playlist extends database_object
{
protected const DB_TABLENAME = 'tmp_playlist';
// Variables from the Database
- 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 $session_id is not named in camelCase. Open
public static function get_from_session($session_id): Tmp_Playlist
{
$sql = "SELECT `id` FROM `tmp_playlist` WHERE `session` = ?";
$db_results = Dba::read($sql, array($session_id));
$row = Dba::fetch_row($db_results);
- 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 $playlist_id is not named in camelCase. Open
public function __construct($playlist_id = 0)
{
if (!$playlist_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 $object_type is not named in camelCase. Open
public function add_object($object_id, $object_type): bool
{
$sql = "INSERT INTO `tmp_playlist_data` (`object_id`, `tmp_playlist`, `object_type`) VALUES (?, ?, ?)";
Dba::write($sql, array($object_id, $this->id, $object_type));
- 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 "Tmp_Playlist" is not in camel caps format Open
class Tmp_Playlist extends database_object
- Exclude checks