Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace global 'version' variable with Configuration::VERSION class constant #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lordofweb
Copy link

Rename global 'version' variable to 'version-brevo'

This pull request addresses a potential naming conflict by renaming the global 'version' variable to 'version-brevo' in the Brevo PHP package.

Changes:

  • Renamed $GLOBALS['version'] to $GLOBALS['version-brevo'] in lib/Configuration.php
  • Updated the reference in the userAgent string

This change aims to prevent conflicts with other packages or user code that might use a similar global variable name.

Related issue: #31

@lordofweb
Copy link
Author

This pull request addresses the issue of using a global variable for the Brevo PHP package version, which can cause conflicts and is deprecated in recent PHP versions.

Changes made

  1. Removed the line $GLOBALS['version'] = '2.0.0';
  2. Added a VERSION constant to the Configuration class
  3. Updated the reference in the userAgent string

Details of the changes

class Configuration
{
    /**
     * Version of the package
     */
    const VERSION = "2.0.0";

    // ...

    public function __construct()
    {
        $this->tempFolderPath = sys_get_temp_dir();
        $this->userAgent = 'brevo_clientAPI/v' . self::VERSION . '/php';
    }
}

Benefits of this change

  • Eliminates potential naming conflicts with other code
  • Improves code organization by keeping the version information within the relevant class
  • Ensures compatibility with PHP 8.1 and later versions by avoiding the deprecated $GLOBALS assignment

Related issue: #31

Please review this change and let me know if any further modifications are needed.

@lordofweb lordofweb changed the title Change the global PHP variable of the Brevo version to a Brevo-specific name Replace global 'version' variable with Configuration::VERSION class constant Oct 9, 2024
lib/Configuration.php Outdated Show resolved Hide resolved
@@ -120,7 +124,7 @@ class Configuration
public function __construct()
{
$this->tempFolderPath = sys_get_temp_dir();
$this->userAgent = 'brevo_clientAPI/v' . $GLOBALS['version'] . '/php';
$this->userAgent = 'brevo_clientAPI/v' . self::VERSION . '/php';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the only place where the VERSION constant is used, isn't it better to just write down the full string?

Suggested change
$this->userAgent = 'brevo_clientAPI/v' . self::VERSION . '/php';
$this->userAgent = 'brevo_clientAPI/v2.0.0/php';

Copy link

sonarcloud bot commented Oct 9, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants