Code should not be duplicated 7

More information: https://insight.symfony.com/what-we-analyse/php.duplicated_code

  1. }
  2. }
  3. //Page Counter End
  4. if ($objVisitIP->numRows < 1)

    The next 41 lines appear both in classes/ModuleVisitorsTag.php:755 and public/ModuleVisitorsCount.php:299.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Glen Langer
  5. { //Browser Check wenn nicht geblockt
  6. //Only counting if User Agent is set.
  7. if ( strlen(\Environment::get('httpUserAgent'))>0 )
  8. {
  9. /* Variante 3 */
  1. \Database::getInstance()
  2. ->prepare("INSERT INTO tl_visitors_browser %s")
  3. ->set($arrSet)
  4. ->execute();
  5. }
  6. else

    The next 46 lines appear both in classes/ModuleVisitorsTag.php:823 and public/ModuleVisitorsCount.php:369.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Glen Langer
  7. {
  8. //Update
  9. $objBrowserCounter->next();
  10. $visitors_counter = $objBrowserCounter->visitors_counter +1;
  11. // Update
  1. */
  2. protected function visitorCheckReferrer($vid)
  3. {
  4. if ($this->_HitCounted === true)
  5. {
  6. if ($this->_PF === false)

    The next 25 lines appear both in classes/ModuleVisitorsTag.php:880 and public/ModuleVisitorsCount.php:429.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Glen Langer
  7. {
  8. $ModuleVisitorReferrer = new \Visitors\ModuleVisitorReferrer();
  9. $ModuleVisitorReferrer->checkReferrer();
  10. $ReferrerDNS = $ModuleVisitorReferrer->getReferrerDNS();
  11. $ReferrerFull= $ModuleVisitorReferrer->getReferrerFull();
  1. /**
  2. * Get User IP
  3. *
  4. * @return string
  5. */
  6. protected function visitorGetUserIP()

    The next 34 lines appear in classes/ModuleVisitorsTag.php:979, public/ModuleVisitorsCount.php:465 and public/ModuleVisitorsScreenCount.php:342.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Glen Langer
  7. {
  8. $UserIP = \Environment::get('ip');
  9. if (strpos($UserIP, ',') !== false) //first IP
  10. {
  11. $UserIP = trim( substr($UserIP, 0, strpos($UserIP, ',') ) );
  1. visitors_page_lang
  2. ")
  3. ->limit($limit)
  4. ->execute($VisitorsID);
  5. while ($objPageStatCount->next())

    The next 48 lines appear in classes/ModuleVisitorStatPageCounter.php:105, classes/ModuleVisitorStatPageCounter.php:281 and classes/ModuleVisitorStatPageCounter.php:366.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Glen Langer
  6. {
  7. switch ($objPageStatCount->visitors_page_type)
  8. {
  9. case self::PAGE_TYPE_NORMAL :
  10. $objPage = \PageModel::findWithDetails($objPageStatCount->visitors_page_id);
  1. visitors_page_lang
  2. ")
  3. ->limit($limit)
  4. ->execute($VisitorsID);
  5. while ($objPageStatCount->next())

    The next 30 lines appear both in classes/ModuleVisitorStatPageCounter.php:105 and classes/ModuleVisitorStatPageCounter.php:197.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Glen Langer
  6. {
  7. switch ($objPageStatCount->visitors_page_type)
  8. {
  9. case self::PAGE_TYPE_NORMAL :
  10. $objPage = \PageModel::findWithDetails($objPageStatCount->visitors_page_id);
  1. visitors_page_lang
  2. ")
  3. ->limit($limit)
  4. ->execute($VisitorsID);
  5. while ($objPageStatCount->next())

    The next 57 lines appear both in classes/ModuleVisitorStatPageCounter.php:105 and classes/ModuleVisitorStatPageCounter.php:536.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Glen Langer
  6. {
  7. switch ($objPageStatCount->visitors_page_type)
  8. {
  9. case self::PAGE_TYPE_NORMAL :
  10. $objPage = \PageModel::findWithDetails($objPageStatCount->visitors_page_id);

Commented code should not be committed 11

More information: https://insight.symfony.com/what-we-analyse/php.commented_out_code

  1. header('Content-Disposition: attachment;filename="visitors_statistic-export.ods"');
  2. header('Cache-Control: max-age=0');
  3. if ($this->BrowserAgent == 'IE')
  4. {
  5. // If you're serving to IE 9, then the following may be needed
  6. //header('Cache-Control: max-age=1');

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  7. // If you're serving to IE over SSL, then the following may be needed
  8. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  10. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1. header('Content-Disposition: attachment;filename="visitors_statistic-export.utf8.csv"');
  2. header('Cache-Control: max-age=0');
  3. if ($this->BrowserAgent == 'IE')
  4. {
  5. // If you're serving to IE 9, then the following may be needed
  6. //header('Cache-Control: max-age=1');

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  7. // If you're serving to IE over SSL, then the following may be needed
  8. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  10. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1. }
  2. if ($PageType == self::PAGE_TYPE_FORBIDDEN)
  3. {
  4. //Page ID von der 403 Seite ermitteln
  5. ////$pageId = $this->visitorGetRootPageFromUrl(false);

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  6. ////$objPage = \PageModel::find403ByPid($pageId);
  7. ModuleVisitorLog::writeLog(__METHOD__ , __LINE__ , 'PageIdNormal over 403: '. $PageId);
  8. ////return $objPage->id;
  9. return $PageId;
  10. }
  1. if ($PageType == self::PAGE_TYPE_FORBIDDEN)
  2. {
  3. //Page ID von der 403 Seite ermitteln
  4. ////$pageId = $this->visitorGetRootPageFromUrl(false);
  5. ////$objPage = \PageModel::find403ByPid($pageId);

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  6. ModuleVisitorLog::writeLog(__METHOD__ , __LINE__ , 'PageIdNormal over 403: '. $PageId);
  7. ////return $objPage->id;
  8. return $PageId;
  9. }
  1. {
  2. //Page ID von der 403 Seite ermitteln
  3. ////$pageId = $this->visitorGetRootPageFromUrl(false);
  4. ////$objPage = \PageModel::find403ByPid($pageId);
  5. ModuleVisitorLog::writeLog(__METHOD__ , __LINE__ , 'PageIdNormal over 403: '. $PageId);
  6. ////return $objPage->id;

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  7. return $PageId;
  8. }
  9. //Reader mit Parameter oder ohne?
  10. $uri = $_SERVER['REQUEST_URI']; // /news/james-wilson-returns.html
  1. //Page ID von der 403 Seite ermitteln
  2. $host = \Environment::get('host');
  3. // Find the matching root pages (thanks to Andreas Schempp)
  4. $objRootPage = \PageModel::findFirstPublishedRootByHostAndLanguage($host, $visitors_page_lang);
  5. $objPage = \PageModel::find403ByPid($objRootPage->id);
  6. //$objPage = \PageModel::findWithDetails($objPage->id);

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  7. return $objPage->alias;
  8. }
  9. /**
  10. * generatePageVisitHitTopDays speziell für den Export
  1. *
  2. * last-updated: 2014-10-26T15:14:03+01:00
  3. */
  4. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['all_months'] = 'All months';

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  5. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['all_years'] = 'All years';
  6. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['csv'] = 'CSV .csv';
  7. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['excel'] = 'Excel .xlsx';
  8. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['opendocument'] = 'OpenDocument .ods';
  9. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export'] = 'Export';
  1. * last-updated: 2014-10-26T15:14:03+01:00
  2. */
  3. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['all_months'] = 'All months';
  4. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['all_years'] = 'All years';

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  5. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['csv'] = 'CSV .csv';
  6. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['excel'] = 'Excel .xlsx';
  7. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['opendocument'] = 'OpenDocument .ods';
  8. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export'] = 'Export';
  9. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['export_button_title'] = 'The Button opens a new window.';
  1. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['all_years'] = 'All years';
  2. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['csv'] = 'CSV .csv';
  3. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['excel'] = 'Excel .xlsx';
  4. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['opendocument'] = 'OpenDocument .ods';
  5. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export'] = 'Export';
  6. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['export_button_title'] = 'The Button opens a new window.';

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  7. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export_field_category'] = 'Category';
  8. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export_field_id'] = 'ID';
  9. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export_field_name'] = 'Name';
  10. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export_field_published'] = 'Published';
  11. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export_field_date'] = 'Date';
  1. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export_title'] = 'Visitors Statistic';
  2. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export_page_title'] = 'Page Statistic';
  3. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['format'] = 'Format';
  4. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['number_of_days'] = 'Number of days';
  5. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['month'] = 'Month';

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  6. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['statistics_export'] = 'Statistics export';
  7. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['year'] = 'Year';
  1. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['export_page_title'] = 'Page Statistic';
  2. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['format'] = 'Format';
  3. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['number_of_days'] = 'Number of days';
  4. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['month'] = 'Month';
  5. $GLOBALS['TL_LANG']['tl_visitors_stat_export']['statistics_export'] = 'Statistics export';
  6. //$GLOBALS['TL_LANG']['tl_visitors_stat_export']['year'] = 'Year';

    Commented out code reduces readability and lowers the code confidence for other developers. If it's common usage for debug, it should not be committed. Using a version control system, such code can be safely removed.

    Time to fix: about 30 minutes
    Open Issue Permalink
    Last edited by Glen Langer

Unused method, property, variable or parameter

More information: https://insight.symfony.com/what-we-analyse/php.unused_local_variable_or_private_member

  1. private $_SE = false; // Search Engine
  2. private $_PF = false; // Prefetch found
  3. private $_VB = false; // Visit Blocker

    This _VB attribute is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  4. private $_VisitCounted = false;
  5. private $_HitCounted = false;

PHP code should not contain unreachable code

More information: https://insight.symfony.com/what-we-analyse/php.unreachable_code

Updated rule! We've recently tweaked this rule. This may explain the disappearance of false positives, or new suggestions not linked to any activity in the code.

This code is unreachable.

Time to fix: about 1 hour
Open Issue Permalink
Last edited by Glen Langer

PHP classes should be short

More information: https://insight.symfony.com/what-we-analyse/php.class_too_long

20% of all classes are larger than 500 lines. Split them up to keep less than 5% large classes.

Time to fix: about 2.9 days
Open Issue Permalink
Collective

PHP methods should not contain too much logic

More information: https://insight.symfony.com/what-we-analyse/php.method_too_long

8% of all methods have more than 50 lines. This violation is raised when more than 5% methods are too long.

Time to fix: about 4.8 days
Open Issue Permalink
Collective

PHP code should follow PSR-1 basic coding standard 2

More information: https://insight.symfony.com/what-we-analyse/php.psr1

in classes/Encoding.php, line 294
  1. }
  2. $text = self::toUTF8(static::utf8_decode($text, $option));
  3. return $text;
  4. }
  5. static function UTF8FixWin1252Chars($text){

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  6. // If you received an UTF-8 string that was converted from Windows-1252 as it was ISO8859-1
  7. // (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it.
  8. // See: http://en.wikipedia.org/wiki/Windows-1252
  9. return str_replace(array_keys(self::$brokenUtf8ToUtf8), array_values(self::$brokenUtf8ToUtf8), $text);
in classes/Encoding.php, line 344
  1. $encodingLabel = self::normalizeEncoding($encodingLabel);
  2. if($encodingLabel == 'ISO-8859-1') return self::toLatin1($text);
  3. return self::toUTF8($text);
  4. }
  5. protected static function utf8_decode($text, $option)

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  6. {
  7. if ($option == self::WITHOUT_ICONV || !function_exists('iconv')) {
  8. $o = utf8_decode(
  9. str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), self::toUTF8($text))
  10. );

Methods and properties visibility should always be explicitly defined 7

More information: https://insight.symfony.com/what-we-analyse/php.method_or_property_missing_visibility

in classes/Encoding.php, line 161
  1. "\xc5\xbe" => "\x9e",
  2. "\xc5\xb8" => "\x9f"
  3. );
  4. static function toUTF8($text){

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  5. /**
  6. * Function \ForceUTF8\Encoding::toUTF8
  7. *
  8. * This function leaves UTF8 characters alone, while converting almost all non-UTF8 to UTF8.
  9. *
in classes/Encoding.php, line 256
  1. }
  2. }
  3. return $buf;
  4. }
  5. static function toWin1252($text, $option = self::WITHOUT_ICONV) {

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  6. if(is_array($text)) {
  7. foreach($text as $k => $v) {
  8. $text[$k] = self::toWin1252($v, $option);
  9. }
  10. return $text;
in classes/Encoding.php, line 269
  1. } else {
  2. return $text;
  3. }
  4. }
  5. static function toISO8859($text) {

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  6. return self::toWin1252($text);
  7. }
  8. static function toLatin1($text) {
  9. return self::toWin1252($text);
in classes/Encoding.php, line 273
  1. static function toISO8859($text) {
  2. return self::toWin1252($text);
  3. }
  4. static function toLatin1($text) {

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  5. return self::toWin1252($text);
  6. }
  7. static function fixUTF8($text, $option = self::WITHOUT_ICONV){
  8. if(is_array($text)) {
in classes/Encoding.php, line 277
  1. static function toLatin1($text) {
  2. return self::toWin1252($text);
  3. }
  4. static function fixUTF8($text, $option = self::WITHOUT_ICONV){

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  5. if(is_array($text)) {
  6. foreach($text as $k => $v) {
  7. $text[$k] = self::fixUTF8($v, $option);
  8. }
  9. return $text;
in classes/Encoding.php, line 294
  1. }
  2. $text = self::toUTF8(static::utf8_decode($text, $option));
  3. return $text;
  4. }
  5. static function UTF8FixWin1252Chars($text){

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  6. // If you received an UTF-8 string that was converted from Windows-1252 as it was ISO8859-1
  7. // (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it.
  8. // See: http://en.wikipedia.org/wiki/Windows-1252
  9. return str_replace(array_keys(self::$brokenUtf8ToUtf8), array_values(self::$brokenUtf8ToUtf8), $text);
in classes/Encoding.php, line 302
  1. // See: http://en.wikipedia.org/wiki/Windows-1252
  2. return str_replace(array_keys(self::$brokenUtf8ToUtf8), array_values(self::$brokenUtf8ToUtf8), $text);
  3. }
  4. static function removeBOM($str=""){

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Glen Langer
  5. if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
  6. $str=substr($str, 3);
  7. }
  8. return $str;
  9. }