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

Fully qualified class name in another namespace should not be replaced with self #7677

Closed
oschwald opened this issue Jan 4, 2024 · 1 comment
Labels
kind/bug status/duplicate topic/fqcn Fully Qualified Class Name usage and conversions

Comments

@oschwald
Copy link
Contributor

oschwald commented Jan 4, 2024

Bug report

Description

For this code, I am seeing the following diff with 3.46.0:

diff --git a/src/Model/City.php b/src/Model/City.php
index 1906a2f..9a098d5 100644
--- a/src/Model/City.php
+++ b/src/Model/City.php
@@ -65,14 +65,14 @@ class City extends Country
     {
         parent::__construct($raw, $locales);

-        $this->city = new \GeoIp2\Record\City($raw['city'] ?? [], $locales);
-        $this->location = new \GeoIp2\Record\Location($raw['location'] ?? []);
-        $this->postal = new \GeoIp2\Record\Postal($raw['postal'] ?? []);
+        $this->city = new self($raw['city'] ?? [], $locales);
+        $this->location = new Location($raw['location'] ?? []);
+        $this->postal = new Postal($raw['postal'] ?? []);

         if (!isset($raw['subdivisions'])) {
             $this->subdivisions = [];
             $this->mostSpecificSubdivision =
-                    new \GeoIp2\Record\Subdivision([], $locales);
+                    new Subdivision([], $locales);

             return;
         }
@@ -80,7 +80,7 @@ class City extends Country
         $subdivisions = [];
         foreach ($raw['subdivisions'] as $sub) {
             $subdivisions[] =
-                new \GeoIp2\Record\Subdivision($sub, $locales)
+                new Subdivision($sub, $locales)
             ;
         }

The replacement of \GeoIp2\Record\City with self is incorrect as self refers to \GeoIp2\Model\City.

Runtime version

PHP CS Fixer 3.46.0 Three Keys by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.3.0

Used command

$ ./vendor/bin/php-cs-fixer fix -vvv
PHP CS Fixer 3.46.0 Three Keys by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.3.0
Loaded config default from "/home/greg/MaxMind/GeoIP2-php/.php-cs-fixer.php".
Using cache file ".php-cs-fixer.cache".
 40/40 [████████████████████████████] 100%

   1) tests/GeoIp2/Test/WebService/ClientTest.php (fully_qualified_strict_types)
   2) src/Database/Reader.php (fully_qualified_strict_types)
   3) src/Model/City.php (fully_qualified_strict_types, self_accessor)
   4) src/Model/Country.php (fully_qualified_strict_types, self_accessor)

Fixed 4 of 40 files in 0.152 seconds, 16.000 MB memory used

Configuration file

<?php

$config = new PhpCsFixer\Config();

return $config
    ->setRiskyAllowed(true)
    ->setRules([
        '@Symfony' => true,
        '@Symfony:risky' => true,
        '@PhpCsFixer' => true,
        '@PSR1' => true,
        '@PSR2' => true,
        '@PSR12' => true,
        '@PSR12:risky' => true,
        'array_syntax' => ['syntax' => 'short'],
        'combine_consecutive_unsets' => true,
        'concat_space' => [ 'spacing' => 'one'],
        'explicit_string_variable' => false,
        'fopen_flags' => ['b_mode' => true],
        'heredoc_to_nowdoc' => true,
        'increment_style' => false,
        'list_syntax' => ['syntax' => 'short'],
        'multiline_whitespace_before_semicolons' => false,
        'no_unreachable_default_argument_value' => true,
        'no_useless_else' => true,
        'no_useless_return' => true,
        'ordered_imports' => true,
        'php_unit_strict' => true,
        'php_unit_test_class_requires_covers' => true,
        'phpdoc_add_missing_param_annotation' => true,
        'phpdoc_no_alias_tag' => false,
        'phpdoc_order' => true,
        'phpdoc_types_order' => ['sort_algorithm' => 'alpha', 'null_adjustment' => 'always_last'],
        'semicolon_after_instruction' => true,
        'single_line_throw' => false,
        'strict_comparison' => true,
        'strict_param' => true,
        'yoda_style' => false,
    ])
    ->setFinder(
        PhpCsFixer\Finder::create()
            ->exclude('ext')
            ->in(__DIR__)
    )
;

Code snippet that reproduces the problem

See this class.

@Wirone
Copy link
Member

Wirone commented Jan 5, 2024

I am going to close this as a duplicate of #7642 - you're getting self as a side effect of invalid import that should not happen. If we fix #7642, GeoIp2\Record\City won't be imported and shortened, which means it also won't be changed to self. Sorry for the problem, for now this is something you need to fix manually by importing aliased use GeoIp2\Record\City as CityRecord; or something like that in order to be able to continue using import_symbols=true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug status/duplicate topic/fqcn Fully Qualified Class Name usage and conversions
Projects
None yet
Development

No branches or pull requests

2 participants