Skip to content

IMAP: Resource object constructor and stub #6534

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

Closed
wants to merge 2 commits into from

Conversation

Ayesh
Copy link
Member

@Ayesh Ayesh commented Dec 23, 2020

This is similar to #6533 (FTPConnection), but for IMAPConnection resource class.

As of now, direct construction of IMAPConnection class is allowed, and I think it was meant to be disallowed just like other new resource objects. In this PR:

  • Disallow new IMAPConnection constructor with \Error exception Cannot directly construct IMAPConnection, use imap_open() instead.
  • Update the stub to declare IMAPConnection with final flag.

Thank you.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Thank you for this :D

Could you add a separate test checking that one cannot extend the class?

Comment on lines 4 to 5
<?php
require_once __DIR__ . '/setup/skipif.inc';
Copy link
Member

Choose a reason for hiding this comment

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

Just a nitpick but this test doesn't need to check for the presence of a mailbox, so could you change this to

Suggested change
<?php
require_once __DIR__ . '/setup/skipif.inc';
<?php
extension_loaded('imap') or die('skip imap extension not available in this build');

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, I just force-pushed an updated commit with this test simplified like you suggested.

Disallows constructing an `IMAPConnection` class directly with `new IMAPConnection` construct, by throwing an `Error` exception if attempted.
`imap_open` is still the only way to create `IMAPConnection` objects.
Updates the `IMAPConnection` class stub to make sure it has the `final` flag, and adds a test to verify it.
@Ayesh
Copy link
Member Author

Ayesh commented Dec 23, 2020

Thanks a lot for the review @Girgias. I update both commits and force-pushed with updated test for constructor check, and a new test for a T extends IMAPConnection test.

Thank you.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

LGTM, will wait for CI to clear before merging. :)

@Girgias
Copy link
Member

Girgias commented Dec 23, 2020

Merged as 7f1659a and af68d4a

@Girgias Girgias closed this Dec 23, 2020
@Ayesh
Copy link
Member Author

Ayesh commented Dec 24, 2020

Thanks a lot @Girgias 🙏🏼

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.

2 participants