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

Enforce leading backslash even in non-yet-namespaced classes #9680

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

mvorisek
Copy link
Contributor

extracted from #9481

let's land this in a separate PR and minimize future diffs/conflicts

@mvorisek mvorisek marked this pull request as ready for review October 26, 2024 09:31
@mvorisek mvorisek changed the title Make all class usages fully qualified Add fully qualified backslash to all simple class usages Oct 26, 2024
@mvorisek
Copy link
Contributor Author

mvorisek commented Nov 4, 2024

@alecpl I have rebased this PR, can it be merged to prevent further merge conflicts?

@mvorisek
Copy link
Contributor Author

@pabzm can you review/merge? I need this one for #9481.

@alecpl
Copy link
Member

alecpl commented Nov 17, 2024

I think I would prefer a use statements instead. Or we should do something with the release-1.6 code. Backporting anything has become hard.

@mvorisek
Copy link
Contributor Author

@alecpl thank you for the idea using import to minimize conflicts!

So I reworked this PR:
a) all non-intra project usages are newly with leading \ - this is how they should be imported once namespaced
b) all intra project usages in currently non-namespaced files are kept, but dummy use X as X; imports are added

After #9481 the dummy imports will be replaced with meaningful imports.

Code can stay as it is, so conflicts across release branches are minimal.

Leading \ for non-instra project usages is asserted by CI.

@mvorisek mvorisek changed the title Add fully qualified backslash to all simple class usages Enforce leading backslash even in non-yet-namespaced classes Nov 19, 2024
use enigma_userid as enigma_userid;
use rcmail as rcmail;
use rcube as rcube;
use rcube_user as rcube_user;
Copy link
Member

Choose a reason for hiding this comment

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

What's up with these. Why not just a use without as? It is temporary, I hope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need use because of https://github.com/roundcube/roundcubemail/blob/5dcb791647/.php-cs-fixer.dist.php#L83, the config lines will be removed once the files and properly namespaced and the use changes to namespaced classes.

We need the use X as X; to suppress php warning - https://3v4l.org/dS4TX

@@ -327,7 +343,7 @@ public function create_message($headers, $body, $isHtml = false, $attachments =
}

// create PEAR::Mail_mime instance
$MAIL_MIME = new Mail_mime("\r\n");
$MAIL_MIME = new \Mail_mime("\r\n");
Copy link
Member

Choose a reason for hiding this comment

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

For cases like this, when we use an external class many times, I'd like to see a use statement too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The convection in php community is to use backslash /wo import if the classes are not namespaced.

It makes sense, as for ex. catch (\Exception $e) as much more readable than catch (Exception $e) - in the later case, you might think it catches only project's exceptions.

Is this ok to keep?

If you worry stictly about backport conflicts, I can make a followup PR into v1.6 branch.

@pabzm
Copy link
Member

pabzm commented Nov 20, 2024

@pabzm can you review/merge? I need this one for #9481.

Didn't find the time until now, sorry. From my side all is fine! The offer to contribute to a backport-PR is very helpful, too!

@alecpl
Copy link
Member

alecpl commented Nov 23, 2024

I'm not happy with this change. Where does it lead to, is there an end goal? Are we going to make a big BC break, call it Roundcube 2.0, where e.g. rcube_utils becomes Roundcube\Utils etc.? I suppose I wouldn't be against it if someone has time to do all this. What about a timeline? Do you foresee any obstacles (plugins maybe)? The intermediate state is a mess.

@mvorisek
Copy link
Contributor Author

@alecpl good questions. We should namespace the classes sooner or later. As doing so will be imply BC break, I created #9481 which namespace the classes, but at the same time provide BCible layer for loading the classes as non-namespaced. So these PRs which might look like a mess are actually very precisely crafted to allow smooth transition.

As #9481 might be hard to review/discuss at once, I created this preparatory PR which focuses solely on enabling leading_backslash_in_global_namespace PHP CS Fixer syntax. This is needed for minimizing diffs a) for backporting, b) for reducing the size of #9481.

I wouldn't be against it if someone has time to do all this. What about a timeline? Do you foresee any obstacles (plugins maybe)? The intermediate state is a mess.

In #9481 I have demonstrated it working incl. the BCible autoloading layer. Nothing is broken, everything works.

If you support this, I would be happy if this PR can be merged as is. This PR is safe and does not imply any BC breaks. It is pure CS update.

@mvorisek
Copy link
Contributor Author

@alecpl does this work for you?

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