railpage/railpagecore

View on GitHub

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
Severity: Minor
Found in lib/Forums/Thread.php by phpmd

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
Severity: Minor
Found in lib/Forums/Post.php by phpmd

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",
Severity: Minor
Found in lib/Images/Exif.php - About 1 hr to fix

    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;
            }
    Severity: Minor
    Found in lib/Jobs/Job.php - About 1 hr to fix

      Method getWinningPhoto has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getWinningPhoto() {
              
              if ($this->VotingDateClose >= new DateTime) {
                  return false;
              }
      Severity: Minor
      Found in lib/Images/Competition.php - About 1 hr to fix

        Method updateAuthors has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function updateAuthors() {
                
                $userlookup = array(); 
                
                $Database = (new AppCore)->getDatabaseConnection(); 
        Severity: Minor
        Found in lib/Images/Utility/Updater.php - About 1 hr to fix

          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(); 
                      
          Severity: Minor
          Found in lib/Images/ImageFactory.php - About 1 hr to fix

            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")) {
            Severity: Minor
            Found in lib/Session.php - About 1 hr to fix

              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
              Severity: Minor
              Found in lib/News/Article.php - About 1 hr to fix

                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("*")
                Severity: Minor
                Found in lib/News/Topic.php - About 1 hr to fix

                  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;
                          }
                  Severity: Minor
                  Found in lib/Assets/Asset.php - About 1 hr to fix

                    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;
                    Severity: Minor
                    Found in lib/Timetables/Train.php - About 1 hr to fix

                      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;
                                  }
                      Severity: Minor
                      Found in lib/PrivateMessages/PrivateMessages.php - About 1 hr to fix

                        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");
                        Severity: Minor
                        Found in lib/Gallery/Album.php - About 1 hr to fix

                          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(); 
                                  }
                          Severity: Minor
                          Found in lib/ContentUtility.php - About 1 hr to fix

                            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;
                            Severity: Minor
                            Found in lib/Forums/Forums.php - About 1 hr to fix

                              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;
                              Severity: Minor
                              Found in lib/Railcams/Provider/Flickr.php - About 1 hr to fix

                                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;
                                        }
                                Severity: Minor
                                Found in lib/Images/Images.php - About 1 hr to fix

                                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();
                                        }
                                Severity: Minor
                                Found in lib/Jobs/Jobs.php - About 1 hr to fix

                                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)) {
                                Severity: Minor
                                Found in lib/Users/User.php - About 1 hr to fix

                                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

                                Severity
                                Category
                                Status
                                Source
                                Language