-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Refactoring: type-safety along with some more simple code-paths #48
Refactoring: type-safety along with some more simple code-paths #48
Conversation
This refactoring contains several changes: - Removed `psalm-baseline.xml` - Added array shapes where necessary - Imported array shape from composer where possible - overhaul of the `Collection` class - removed `Collection#reduce` as `array_reduce` stuff is really hard to read (IMHO) - dropped unused methods within the `Collection` class - added `Collection#anySatisfies` to verify if any of the elements satisfy a specific requirement - Make `Collection` generic so that it can hold any type of data - Removed `ArrayAccess` from `Collection` - This removes the necessity of adding these `ReturnTypeWillChange` attributes on PHP 8 - Added `Collection#has`, `Collection#get`, `Collection#set`, `Collection#remove` instead - Added native typehint to `Collection#count` so we can remove `ReturnTypeWillChange` attribute - Added native typehint to `Collection#getIterator` so we can remove `ReturnTypeWillChange` attribute - Added `Collection#toOrderedCollection` to remove array keys when necessary - Added `Collection#getKey` to find a specific key by a known value - Removed all usages of `Collection#reduce` - Marked everything `final` - Removed lazy callable factory for the `PackageProviderDetectionFactory` - Added native type-hints and property-types wherever possible - Fixed components which changed `extra.laminas` during versions while also providing multiple modules/config-provider Overall, the behavior is still the same. This just adds plenty of type-safety. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
…sts passed Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
f5e0997
to
3d48d2a
Compare
Are there any side effects with other components or their installation? If not, then create a new major version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but it does require a major version indeed.
I'd also endorse making everything that we can @internal
, to prevent misuse: lots of very internal details in the Injector
namespace, I think.
Not 100% sure if I understand that question. Featureset here is equal to the current version. But if we consider strict semver for composer plugins (which should only be used as composer plugins and not as libraries) the same way we do on libraries, then we should create a new major. But when it comes to the end-result this plugin has to achieve (adding components to config files after asking the user during |
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
We do not need this as the performance gain here is really minor anyways. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
…`BasePackage` Fixes `InvalidArgumentException` with message `Only subclasses of BasePackage are supported`. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
85caea7
to
0531a15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some choices I'd have done differently, but it achieves the goal (better type-safety), which in turn will make it more maintainable, so 👍.
Considering that this is a package meant for consumption, not extension, I tend to agree that a new major is not needed; it achieves the same goals and has the same behavior for consumers after the refactor.
@weierophinney Please let me know what you would do differently. Always happy to get a different view. |
See, I prefer reduce to each + reference. 😄 But probably the bigger refactor I'd do is to remove the collections stuff entirely; it was a solution in search of a problem at the time, and I think we could likely do this a lot more tightly with modern PHP than I did when I wrote this (more value objects, smaller public interface). But for now, this is a really good step towards better maintainability. |
Okay. I guess releasing this as a new major will suffice. there are no dependants of this component and upgrading to the new major will be easy for those who are not using our code as library code. With the next major, everything is internal and starting with that, we can do whatever bc breaks we want to implement from an API perspective. Cool for everyone? I also added the other issues to the next major and I will work on this after my holidays which will start on 06-15. 👌🏻 |
Since I got no feedback, I guess we are good to go? |
New major works 👍 |
Description
This refactoring contains several changes:
psalm-baseline.xml
Collection
classCollection#reduce
asarray_reduce
stuff is really hard to read (IMHO)Collection
classCollection#anySatisfies
to verify if any of the elements satisfy a specific requirementCollection
generic so that it can hold any type of dataArrayAccess
fromCollection
ReturnTypeWillChange
attributes on PHP 8Collection#has
,Collection#get
,Collection#set
,Collection#remove
insteadCollection#count
so we can removeReturnTypeWillChange
attributeCollection#getIterator
so we can removeReturnTypeWillChange
attributeCollection#toOrderedCollection
to remove array keys when necessaryCollection#getKey
to find a specific key by a known valueCollection#reduce
final
PackageProviderDetectionFactory
extra.laminas
during versions while also providing multiple modules/config-providerOverall, the behavior is still the same. This just adds plenty of type-safety.
BC break only due to the whole
final
and native property-, argument- and return-typehints.I am not 100% sure if we have to create a new major release for this but if we want to do so, I am fine with that as well.