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

Refactor and rename #221

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

Refactor and rename #221

wants to merge 18 commits into from

Conversation

mikey179
Copy link
Member

As discussed in #213 I took the opportunity to rename some classes. Also, in #220 (review) I mentioned I believe there's opportunity to restructure code. This is my attempt at that. It probably has some rough edges and I'm not sure it's a good idea to merge this big one. On the other hand, this is a big opportunity, as we will have a new major version anyway, and I managed to reduce the amount of code while all features are kept. Please have a look and let me know what you think.

Copy link
Member Author

@mikey179 mikey179 left a comment

Choose a reason for hiding this comment

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

I added some comments throughout the diff to highlight some things I think are worth to mention or to discuss.

*/
abstract class vfsStreamAbstractContent implements vfsStreamContent
class Inode
Copy link
Member Author

Choose a reason for hiding this comment

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

Like in a real filesystem , the inode contains all metadata about the file, except the filename and some other things that are specific to the type of file.

Copy link
Contributor

@bizurkur bizurkur Feb 26, 2020

Choose a reason for hiding this comment

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

I really like this

@@ -141,7 +94,7 @@ class vfsStreamWrapper
*/
public static function register(): void
{
self::$root = null;
self::$root = Root::empty();
Copy link
Member Author

Choose a reason for hiding this comment

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

I introduced a specific Root class so that some null checks could be eliminated. I believe this could be a starting point should we ever want to tackle the topic of partitions.

*/
public function seek(int $offset, int $whence): bool;
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed all seeking functionality from the content instances itself. Instead, this functionality can now be found in internal\OpenedFile, for which a new instance is created on each fopen(). This resembles what @bizurkur achieved with #220.

Copy link
Contributor

Choose a reason for hiding this comment

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

This took me a minute to get used to. It's neat that it avoids the extra seeks before each read/write in OpenedFile.

src/internal/ErroneousOpenedFile.php Outdated Show resolved Hide resolved
*
* @internal
*/
final class Mode
Copy link
Member Author

Choose a reason for hiding this comment

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

Just some stuff extracted from the StreamWrapper class to reduce its size.

*
* @return int[]|false
*/
public function stat()
Copy link
Member Author

Choose a reason for hiding this comment

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

Putting that here eliminates some code duplication in the streamwrapper class.

@@ -237,9 +169,19 @@ public function chmod(int $permissions): vfsStreamContent
}

/**
* returns permissions
* @deprecated use permissions() instead
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a suggestion, like with all getX() methods which return just the value of a property.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's just me, but I like the get/set prefixes because it makes it very obvious what the method does.

I might just be lazy and not like reading a method's description to find out what it's doing. An example:

$file->lastAttributeModified($filectime); // takes parameter = setter
$file->filectime(); // no parameter = getter

// but then...

$file->resourceId($resource); // takes parameter, but is a getter not a setter

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, resourceId($resource) is not a good method name for what it does. Should be something like resourceIdOf($resource) or resourceIdFor($resource) I think.

src/internal/Path.php Outdated Show resolved Hide resolved
@mikey179
Copy link
Member Author

In my last commit I updated the org layer to load the new classes. However, I'm a bit unsure how to continue:

  • Remove all classes/interfaces from org which don't have a match any more? These are mostly ones which people typically shouldn't have used, but you never know... but it would break the current promise that an update can be done seamlessly.
  • Does the org layer actually still make sense with the renaming?
  • Or should it be two steps - a release 2.0 with the namespace change only, quickly followed by a 3.0 with the rename in place?

I'd like to hear your thoughts on this.

@mikey179 mikey179 requested a review from a team February 28, 2020 09:01
@bizurkur
Copy link
Contributor

  • Does the org layer actually still make sense with the renaming?
  • Or should it be two steps - a release 2.0 with the namespace change only, quickly followed by a 3.0 with the rename in place?

I was a little curious about this, too. The rename does seem like it makes the old org layer somewhat pointless if all the files don't match up anymore. If the goal is to maintain an easy transition, putting this into 3.0 does sound like a better idea.

If we go that route, then we can update the org files that don't have a match anymore to include "this file will be removed in 3.0" to the deprecation message.

Then for any development, we'll just have to create a 2.x and remember to branch off of that. Merging any 2.x changes into 3.x could be fun...

@mikey179
Copy link
Member Author

Merging any 2.x changes into 3.x could be fun...

Yes, that's one of the thoughts I had - we might create a maintenance problem for us. So in case we opt for two major releases (not necessarily at the same time) we should limit the support time span for 2.0 - I'd even go to say that it should receive bug fixes only.

@mikey179
Copy link
Member Author

mikey179 commented Mar 2, 2020

Over the weekend I thought a bit about this and came up with the following idea:

  1. Merge the namespace change into 1.x.
  2. Rename the classes that will receive a new name, adjust the org namespace accordingly to reference the new names, and to declare the classes/interfaces which will be removed because they are not present any more after the refactoring.
  3. Release this as 1.7.0.
  4. Remove the org layer with the old namespace from master.
  5. Merge this one into master, and continue the work with the other issues and open PRs.
  6. Once we deem master ready for release it becomes 2.0.0.

This has some advantages:

  • People can upgrade to 1.7 without any problems, and start to adjust their code in preparation for 2.0. But they don't have to do this immediately with the upgrade.
  • Once people did the changes that become possible with 1.7 an upgrade to 2.0 should not require any major work.
  • We decouple our further work on 2.0 from the namespace change.
  • There's only one major release on the time plan, not two as with my initial thoughts.

What do you think? Have I overlooked anything that might pose a problem?

@bizurkur
Copy link
Contributor

bizurkur commented Mar 2, 2020

That sounds way better and should have far fewer complications 👍

mikey179 added a commit that referenced this pull request Mar 3, 2020
This ports the namespace change introduced with #209 to the 1.x
series, as suggested in #221. This allows users to upgrade to 1.7
and adjust the used namespace.
mikey179 added a commit that referenced this pull request Mar 5, 2020
port #209 to 1.x as suggested in #221

This ports the namespace change introduced with #209 to the 1.x
series, as suggested in #221. This allows users to upgrade to 1.7
and adjust the used namespace.

* raise requirement for minimum PHP version to 5.6.0

* remove builds with PHP < 5.6
mikey179 added a commit that referenced this pull request Mar 5, 2020
This introduces the class name changes proposed with #213 into the v1.x series according to the migration strategy detailed in  #221.
mikey179 added a commit that referenced this pull request Mar 23, 2020
* introduce class name changes in new namespace

This introduces the class name changes proposed with #213 into the v1.x series according to the migration strategy detailed in  #221.

* fix various type hints
@jaapio
Copy link
Contributor

jaapio commented Jul 3, 2020

What is the status of this pr? I would like to start working on php8 compatibility. But this large move of files makes me feel that I have to wait for this PR.

I reviewed the changes, I think this one is good to go...

@allejo
Copy link
Member

allejo commented Jul 3, 2020

Agreed. What else is left in this PR?

I'd like to get a migration path from 1.7.0 to 2.0.0 so we can finally EOL the 1.x series.

@mikey179
Copy link
Member Author

mikey179 commented Jul 6, 2020

If I remember correctly, within the plan I outlined above this should now be at point 3. Unfortunately for this PR I got pulled into a large project mid March and are lacking any time to continue working on this. I'm not sure if this one could be merged as is or if there were some other changes that should be done, something in the back of my mind tells me I wanted to look at something but I can't remember what it was. Probably it's ok to check with #227 if something needs to be done here before it should be merged so the change is consistent in 1.x and master.

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.

4 participants