The code in BrowserDetector::__construct() is duplicating the code in BrowserDetector::setUserAgent()

Created on 27 December 2021, over 2 years ago
Updated 29 June 2024, 2 months ago

BrowserDetector::__construct() uses the following code.

    if ($userAgent != '') {
      // Set the user agent.
      $this->setUserAgent($userAgent);
      $this->dd->setUserAgent($userAgent);

      // We can parse the information.
      $this->dd->parse();
    }

The code in BrowserDetector::setUserAgent() is the following one.

    $this->userAgent = $userAgent;
    $this->dd->setUserAgent($userAgent);

    // We can parse the information.
    $this->dd->parse();

Since the constructor calls BrowserDetector::setUserAgent(), it doesn't need to call $this->dd->setUserAgent($userAgent) and $this->dd->parse(), as that is already done from BrowserDetector::setUserAgent(). The constructor should simply use the following code.

  public function __construct($userAgent = '') {
    // Initiate the DeviceDetector library.
    $this->dd = new DeviceDetector();
    $this->dd->discardBotInformation();
    $this->dd->skipBotDetection();

    if ($userAgent != '') {
      // Set the user agent.
      $this->setUserAgent($userAgent);
    }
  }
🐛 Bug report
Status

Needs work

Version

2.1

Component

Code

Created by

🇮🇹Italy apaderno Brescia, 🇮🇹

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024