Showing 1,011 of 9,214 total issues
The class Thread has 19 fields. Consider redesigning Thread to keep the number of fields under 15. Open
class Thread extends Forums {
/**
* Thread ID
* @since Version 3.0.1
- Read upRead up
- Exclude checks
TooManyFields
Since: 0.1
Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.
Example
class Person {
protected $one;
private $two;
private $three;
[... many more fields ...]
}
Source https://phpmd.org/rules/codesize.html#toomanyfields
The class Post has 24 fields. Consider redesigning Post to keep the number of fields under 15. Open
class Post extends Forums {
/**
* Constant: Cache key for edit lookups
* @since Version 3.11.0
- Read upRead up
- Exclude checks
TooManyFields
Since: 0.1
Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.
Example
class Person {
protected $one;
private $two;
private $three;
[... many more fields ...]
}
Source https://phpmd.org/rules/codesize.html#toomanyfields
Method normaliseCameraMake
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function normaliseCameraMake($make) {
$findTheseMakes = [
"NIKON CORPORATION",
"NIKON",
Method validate
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function validate() {
if (!is_object($this->Organisation) || empty($this->Organisation->id)) {
throw new Exception("Cannot save job - organisation is empty or invalid");
return false;
}
Method getWinningPhoto
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getWinningPhoto() {
if ($this->VotingDateClose >= new DateTime) {
return false;
}
Method updateAuthors
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function updateAuthors() {
$userlookup = array();
$Database = (new AppCore)->getDatabaseConnection();
Method CreateImage
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function CreateImage($id = null, $provider = null, $options = null) {
$Redis = AppCore::GetRedis();
$Registry = Registry::GetInstance();
Method __construct
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct() {
$this->Memcached = new Memcached;
if (!defined("RP_SITE_DOMAIN")) {
Method getChangelog
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getChangelog() {
$query = "SELECT u.username, u.user_id, u.user_avatar, s.time AS timestamp, 'Article created' AS title, '' AS args
FROM nuke_stories AS s
LEFT JOIN nuke_users AS u ON u.user_id = s.user_id
Method fetchStoriesFromSphinx
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function fetchStoriesFromSphinx($page = 0, $limit = 25, $total = true) {
$Sphinx = $this->getSphinx();
$query = $Sphinx->select("*")
Method load
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function load() {
if (!$row = $this->db->fetchRow("SELECT * FROM asset WHERE id = ?", $this->id)) {
return;
}
Method setCommodity
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setCommodity($commodity) {
switch (strtolower($commodity)) {
case "intermodal" :
$this->commodity = self::COMMODITY_INTERMODAL;
break;
Method getUnread
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getUnread() {
if (!$this->User->id) {
throw new Exception("Cannot fetch unread PMs - not a registered user");
return false;
}
Method __construct
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct($id = null) {
parent::__construct();
$this->Module = new Module("Gallery");
Method relativeTime
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function relativeTime($timestamp, $now = null, $format = null) {
if ($timestamp instanceof DateTime) {
$timestamp = $timestamp->getTimestamp();
}
Method getUnreadForumThreadsForUser
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getUnreadForumThreadsForUser(User $User, $offset = 0, $items_per_page = false) {
$forums = $this->getAllowedForumsIDsForUser($User, "auth_read");
if ($items_per_page === false) {
$items_per_page = $User->items_per_page;
Method getPhoto
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getPhoto($id) {
$mckey = sprintf("railpage:railcam.provider=%s;railcam.image=%d", self::PROVIDER_NAME, $id);
if ($this->photo = $this->Memcached->fetch($mckey)) {
return $this->photo;
Function normaliseSizes_addShorthands
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private static function normaliseSizes_addShorthands($missingSize, $minWidth = 0, $maxWidth = 99999) {
if (!count(self::$sizes)) {
return;
}
- 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 filter
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function filter($args) {
if ($args === false) {
$args = 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 validateAvatar
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function validateAvatar($force = false) {
if (!empty( $this->avatar )) {
if ($force || ( empty( $this->avatar_width ) || empty( $this->avatar_height ) || $this->avatar_width == 0 || $this->avatar_height == 0 )) {
if ($size = @getimagesize($this->avatar)) {
- 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"