Skip to content

Update to coding-standard ^0.7#73

Closed
alies-dev wants to merge 2 commits intomainfrom
update-coding-standard
Closed

Update to coding-standard ^0.7#73
alies-dev wants to merge 2 commits intomainfrom
update-coding-standard

Conversation

@alies-dev
Copy link
Copy Markdown
Member

Summary

  • Replaced standalone friendsofphp/php-cs-fixer and squizlabs/php_codesniffer with interaction-design-foundation/coding-standard ^0.7
  • Updated .php-cs-fixer.php to use the shared Config::create() factory
  • Updated phpcs.xml to reference the IxDFCodingStandard ruleset
  • Applied all auto-fixable violations from both phpcbf and php-cs-fixer
  • Kept HttpClient non-final (mocked in tests) and AbstractService::boot() non-final (overridden by subclasses)

Notes

  • Remaining PHPCS violations are non-auto-fixable (cognitive complexity, forbidden functions, naming conventions, mixed type hints, superfluous naming suffixes) and should be addressed in follow-up PRs
  • All tests pass

Test plan

  • composer update succeeds
  • vendor/bin/phpunit passes (44 tests, 98 assertions)
  • vendor/bin/php-cs-fixer fix --dry-run reports no fixable issues

Replace standalone friendsofphp/php-cs-fixer and squizlabs/php_codesniffer
with the shared IxDF coding standard package. Update .php-cs-fixer.php to
use the shared Config factory and phpcs.xml to reference IxDFCodingStandard.
Auto-fixed violations detected by the new IxDF coding standard.
Kept HttpClient and AbstractService::boot() non-final to preserve
testability and extensibility.
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request modernizes the project's coding standards by migrating to a unified interaction-design-foundation/coding-standard package. This change simplifies development dependencies, centralizes code style configuration, and automatically applies a wide range of code style fixes. The update aims to enhance code consistency, readability, and maintainability across the codebase, while carefully preserving necessary extension points for testing and subclassing.

Highlights

  • Coding Standard Update: Replaced standalone friendsofphp/php-cs-fixer and squizlabs/php_codesniffer with interaction-design-foundation/coding-standard ^0.7 to centralize and streamline code style enforcement.
  • Configuration Simplification: Updated .php-cs-fixer.php to leverage the shared Config::create() factory and phpcs.xml to reference the IxDFCodingStandard ruleset, significantly reducing boilerplate.
  • Automated Code Fixes: Applied all auto-fixable violations identified by both phpcbf and php-cs-fixer to improve immediate code quality.
  • Preserved Flexibility: Maintained HttpClient as non-final to allow for mocking in tests and AbstractService::boot() as non-final to permit overriding by subclasses, ensuring continued extensibility.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .gitignore
    • Added '.cache/' to the list of ignored files.
  • .php-cs-fixer.php
    • Replaced the extensive manual configuration with a concise call to Config::create(__DIR__) from the new coding standard.
  • composer.json
    • Removed friendsofphp/php-cs-fixer and squizlabs/php_codesniffer from dev dependencies.
    • Added interaction-design-foundation/coding-standard as a dev dependency.
    • Configured Composer to allow the dealerdirect/phpcodesniffer-composer-installer plugin.
  • phpcs.xml
    • Replaced the custom PSR2 ruleset with a reference to IxDFCodingStandard.
  • rector.php
    • Updated directory paths to use single quotes for consistency.
  • src/Cache.php
    • Consolidated the declare(strict_types=1); statement.
    • Removed redundant phpdoc parameters and descriptions from method signatures.
    • Changed string concatenation from . to . for consistency.
    • Marked the class as final.
  • src/Console/Clear.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Removed redundant phpdoc descriptions.
    • Updated static::FAILURE and static::SUCCESS to self::FAILURE and self::SUCCESS.
    • Changed string literals from double to single quotes.
  • src/Console/Update.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Removed redundant phpdoc descriptions.
    • Updated static::FAILURE and static::SUCCESS to self::FAILURE and self::SUCCESS.
    • Changed string literals from double to single quotes.
  • src/Contracts/ServiceInterface.php
    • Consolidated the declare(strict_types=1); statement.
    • Removed redundant phpdoc parameters and descriptions.
  • src/Exceptions/MissingConfigurationException.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final and simplified its definition to an empty body.
  • src/Facades/GeoIP.php
    • Consolidated the declare(strict_types=1); statement.
    • Removed redundant phpdoc descriptions.
  • src/GeoIP.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Changed protected properties to private.
    • Removed redundant phpdoc descriptions.
    • Updated string concatenation from . to ..
    • Changed catch (\Exception $e) to catch (\Throwable $e) for broader exception handling.
  • src/GeoIPServiceProvider.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Removed redundant phpdoc descriptions.
    • Updated path strings to use single quotes.
  • src/Location.php
    • Consolidated the declare(strict_types=1); statement.
    • Removed the Class Location phpdoc block.
    • Marked the class as final.
    • Removed redundant phpdoc parameters and descriptions.
    • Updated string concatenation from . to ..
    • Removed the How to use it comment for LocationArray.
  • src/Services/AbstractService.php
    • Consolidated the declare(strict_types=1); statement.
    • Removed redundant phpdoc descriptions.
    • Marked the hydrate and config methods as final public.
    • Marked the ensureConfigurationParameterDefined method as final public.
  • src/Services/IP2Location.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Updated string concatenation from . to ..
  • src/Services/IPApi.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Removed redundant phpdoc descriptions.
    • Updated string concatenation from . to ..
  • src/Services/IPData.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Updated the HttpClient property type hint.
    • Updated string concatenation from . to ..
  • src/Services/IPFinder.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Updated the HttpClient property type hint.
    • Updated string concatenation from . to ..
  • src/Services/IPGeoLocation.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Updated the HttpClient property type hint.
    • Removed redundant phpdoc descriptions.
    • Updated string concatenation from . to ..
  • src/Services/MaxMindDatabase.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Removed redundant phpdoc descriptions.
    • Updated path strings to use single quotes.
    • Changed in_array(strtolower(...)) to in_array(mb_strtolower(...)) for case-insensitive string comparison.
    • Updated string concatenation from . to ..
  • src/Services/MaxMindWebService.php
    • Consolidated the declare(strict_types=1); statement.
    • Marked the class as final.
    • Removed redundant phpdoc descriptions.
  • src/Support/HttpClient.php
    • Consolidated the declare(strict_types=1); statement.
    • Removed redundant phpdoc descriptions.
    • Updated CURLOPT_ constants to use their fully qualified names (e.g., \CURLOPT_URL).
    • Replaced substr with mb_substr for multibyte string safety.
    • Replaced trim with mb_trim for multibyte string safety.
    • Updated PHP_URL_SCHEME to \PHP_URL_SCHEME.
  • src/helpers.php
    • Consolidated the declare(strict_types=1); statement.
    • Removed redundant phpdoc descriptions.
  • tests/Services/MaxMindDatabaseTest.php
    • Refactored the constructor for TestableMaxMindDatabase to use compact property promotion.
  • tests/TestCase.php
    • Updated path strings to use single quotes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the project to a new coding standard, primarily through automated style fixes, aiming for improved consistency and maintainability. However, critical PHP version compatibility and security issues have been introduced. The use of #[Override] (PHP 8.3+) and mb_trim (PHP 8.4+) in src/Support/HttpClient.php will cause fatal errors on the target PHP 8.2 environment, leading to a Denial of Service. Additionally, mb_substr with byte-based offsets from cURL could result in data corruption when multi-byte characters are present in HTTP responses. These incompatible features must be addressed to ensure proper functionality and security.

Comment on lines 21 to +22
#[\Override]
public function hydrate(array $attributes = []): Location
final public function hydrate(array $attributes = []): Location
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The #[Override] attribute was introduced in PHP 8.3. Your rector.php configuration specifies PHP 8.2 compatibility, and your composer.json allows for PHP 8.2. Using this attribute will cause a fatal error (Attribute class "Override" not found) in a PHP 8.2 environment. To maintain compatibility, this attribute should be removed. This issue is present in multiple files across the pull request.

    final public function hydrate(array $attributes = []): Location

Comment on lines 31 to +32
#[\Override]
public function config(string $key, mixed $default = null)
final public function config(string $key, mixed $default = null)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Similar to the comment above, the #[Override] attribute is not compatible with PHP 8.2 and should be removed to prevent fatal errors and maintain the advertised version compatibility.

    final public function config(string $key, mixed $default = null)

Comment on lines 17 to 18
#[\Override]
protected static function getFacadeAccessor(): string
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The #[Override] attribute is a PHP 8.3+ feature. As the project appears to support PHP 8.2, using this attribute will lead to a fatal error. It should be removed to ensure compatibility.

    protected static function getFacadeAccessor(): string

Comment on lines +98 to +99
$header = mb_substr($response, 0, $header_size);
$body = mb_substr($response, $header_size);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

The use of mb_substr here is incorrect and can lead to data corruption. curl_getinfo($curl, \CURLINFO_HEADER_SIZE) returns the size of the headers in bytes, but mb_substr (when used with a multi-byte encoding like UTF-8) expects offsets and lengths in characters. If the HTTP response contains any multi-byte characters (e.g., in headers or at the beginning of the body), the split between headers and body will be calculated incorrectly, leading to corrupted data and subsequent failures in json_decode. Revert to using substr which operates on bytes.

        $header = substr($response, 0, $header_size);
        $body = substr($response, $header_size);


if (count($header) === 2) {
$result[$header[0]] = trim($header[1]);
$result[$header[0]] = mb_trim($header[1]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

The function mb_trim was introduced in PHP 8.4. Since this project targets PHP 8.2 (as specified in rector.php), calling mb_trim will result in a Fatal error: Call to undefined function mb_trim(), causing the application to crash whenever a GeoIP service response is parsed. This constitutes a Denial of Service (DoS) vulnerability. Revert to using trim.

                $result[$header[0]] = trim($header[1]);

@alies-dev alies-dev closed this Mar 13, 2026
@alies-dev alies-dev deleted the update-coding-standard branch March 13, 2026 11:51
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.

1 participant