media_to_url accesses the super-global variable $_SESSION. Open
public static function media_to_url(array $media, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$type = $media['object_type'] ?? null;
$object_id = $media['object_id'] ?? null;
if ($type === null || $object_id === null) {
- 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
media_to_url accesses the super-global variable $_SESSION. Open
public static function media_to_url(array $media, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$type = $media['object_type'] ?? null;
$object_id = $media['object_id'] ?? null;
if ($type === null || $object_id === null) {
- 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
media_to_url accesses the super-global variable $_SESSION. Open
public static function media_to_url(array $media, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$type = $media['object_type'] ?? null;
$object_id = $media['object_id'] ?? null;
if ($type === null || $object_id === null) {
- 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
create_localplay accesses the super-global variable $_REQUEST. Open
public function create_localplay(): void
{
$localplay = new LocalPlay(AmpConfig::get('localplay_controller'));
$localplay->connect();
$append = $_REQUEST['append'] ?? false;
- 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
Function media_object_to_url
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
private static function media_object_to_url(Media $object, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$surl = null;
$url = self::STREAM_PLAYLIST_ROW;
if (!$user) {
- 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 Stream_Playlist.php
has 579 lines of code (exceeds 500 allowed). Consider refactoring. Open
<?php
declare(strict_types=0);
/**
The class Stream_Playlist has 20 public methods. Consider refactoring Stream_Playlist to keep number of public methods under 10. Open
class Stream_Playlist
{
private const STREAM_PLAYLIST_ROW = [
'sid' => null,
'url' => "",
- 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 Stream_Playlist has an overall complexity of 121 which is very high. The configured complexity threshold is 50. Open
class Stream_Playlist
{
private const STREAM_PLAYLIST_ROW = [
'sid' => null,
'url' => "",
- Exclude checks
Stream_Playlist
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
class Stream_Playlist
{
private const STREAM_PLAYLIST_ROW = [
'sid' => null,
'url' => "",
Function generate_playlist
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function generate_playlist(string $type, bool $redirect = false): bool
{
if (!count($this->urls)) {
debug_event(self::class, 'Error: Empty URL array for ' . $this->id, 2);
- 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 media_to_url
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public static function media_to_url(array $media, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$type = $media['object_type'] ?? null;
$object_id = $media['object_id'] ?? null;
if ($type === null || $object_id === null) {
- 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 create_xspf
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function create_xspf(): void
{
$result = "";
foreach ($this->urls as $url) {
$xml = array();
- 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_urls
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function _add_urls(array $urls): void
{
debug_event(self::class, "Adding urls to {" . $this->id . "}...", 5);
$sql = '';
$fields = array();
- 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 create_localplay
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function create_localplay(): void
{
$localplay = new LocalPlay(AmpConfig::get('localplay_controller'));
$localplay->connect();
$append = $_REQUEST['append'] ?? 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
Function __construct
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function __construct($session_id = null)
{
if ($session_id != -1) {
if ($session_id !== null) {
Stream::set_session($session_id);
- 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 create_hls
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function create_hls(): void
{
$ssize = 10;
$ret = "#EXTM3U\n";
$ret .= "#EXT-X-TARGETDURATION:" . $ssize . "\n";
- 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 media_object_to_url() has 103 lines of code. Current threshold is set to 100. Avoid really long methods. Open
private static function media_object_to_url(Media $object, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$surl = null;
$url = self::STREAM_PLAYLIST_ROW;
if (!$user) {
- Exclude checks
The method generate_playlist() has 112 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function generate_playlist(string $type, bool $redirect = false): bool
{
if (!count($this->urls)) {
debug_event(self::class, 'Error: Empty URL array for ' . $this->id, 2);
- Exclude checks
The method media_to_url() has an NPath complexity of 4608. The configured NPath complexity threshold is 200. Open
public static function media_to_url(array $media, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$type = $media['object_type'] ?? null;
$object_id = $media['object_id'] ?? null;
if ($type === null || $object_id === null) {
- 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 media_object_to_url() has an NPath complexity of 2244. The configured NPath complexity threshold is 200. Open
private static function media_object_to_url(Media $object, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$surl = null;
$url = self::STREAM_PLAYLIST_ROW;
if (!$user) {
- 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 generate_playlist() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
public function generate_playlist(string $type, bool $redirect = false): bool
{
if (!count($this->urls)) {
debug_event(self::class, 'Error: Empty URL array for ' . $this->id, 2);
- 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 media_to_url() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public static function media_to_url(array $media, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$type = $media['object_type'] ?? null;
$object_id = $media['object_id'] ?? null;
if ($type === null || $object_id === null) {
- 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 media_object_to_url() has a Cyclomatic Complexity of 28. The configured cyclomatic complexity threshold is 10. Open
private static function media_object_to_url(Media $object, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$surl = null;
$url = self::STREAM_PLAYLIST_ROW;
if (!$user) {
- 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 class Stream_Playlist has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13. Open
class Stream_Playlist
{
private const STREAM_PLAYLIST_ROW = [
'sid' => null,
'url' => "",
- 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 media_object_to_url uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (in_array($type, array('song', 'podcast_episode', 'video'))) {
/** @var Song|Podcast_Episode|Video $object */
$url['url'] = (!empty($user))
? $object->play_url($additional_params, '', false, $user->id, $user->streamtoken)
- 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 create_web_player uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
require Ui::find_template('create_web_player.inc.php');
}
- 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 media_object_to_url uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$url['url'] = $object->play_url($additional_params);
}
- 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
FIXME found Open
// FIXME: duration looks hacky and wrong
- Exclude checks
syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST)
Open
public array $urls = [];
- Exclude checks
The class Stream_Playlist is not named in CamelCase. Open
class Stream_Playlist
{
private const STREAM_PLAYLIST_ROW = [
'sid' => null,
'url' => "",
- 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
Avoid variables with short names like $id. Configured minimum length is 3. Open
public $id;
- 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 $additional_params is not named in camelCase. Open
public function add(array $media = array(), string $additional_params = ''): void
{
$urls = self::media_to_urlarray($media, $additional_params);
$this->_add_urls($urls);
}
- 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 $additional_params is not named in camelCase. Open
public static function media_to_url(array $media, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$type = $media['object_type'] ?? null;
$object_id = $media['object_id'] ?? null;
if ($type === null || $object_id === null) {
- 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 $additional_params is not named in camelCase. Open
private static function media_object_to_url(Media $object, string $additional_params = '', string $urltype = 'web', ?User $user = null): ?Stream_Url
{
$surl = null;
$url = self::STREAM_PLAYLIST_ROW;
if (!$user) {
- 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 $hu. Configured minimum length is 3. Open
$hu = $item->play_url($additional_params);
- 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 $additional_params is not named in camelCase. Open
public static function media_to_urlarray(array $media, string $additional_params = ''): array
{
$urls = array();
foreach ($media as $medium) {
$surl = self::media_to_url($medium, $additional_params);
- 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 $session_id is not named in camelCase. Open
public function __construct($session_id = null)
{
if ($session_id != -1) {
if ($session_id !== null) {
Stream::set_session($session_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
Method name "_add_url" should not be prefixed with an underscore to indicate visibility Open
private function _add_url(Stream_Url $url): void
- Exclude checks
Method name "_add_urls" should not be prefixed with an underscore to indicate visibility Open
private function _add_urls(array $urls): void
- Exclude checks
Class name "Stream_Playlist" is not in camel caps format Open
class Stream_Playlist
- Exclude checks