vanderlee / PHP-stable-sort-functions

Stable sort variants of builtin PHP sort functions. These maintain original order if comparison values are equal.
http://vanderlee.github.io/PHP-stable-sort-functions/
33 stars 8 forks source link

Drupal 8 + PHP7 utility class #6

Closed joelpittet closed 7 years ago

joelpittet commented 8 years ago

A heads up. I've forked your classes to move to a utility class. Not sure if you are interested in going that route at all but if so, I'll send a pull request.

https://github.com/joelpittet/PHP-stable-sort-functions

Reason for the fork is documented in this issue on drupal.org: https://www.drupal.org/node/2466097#comment-10460925

vanderlee commented 8 years ago

This project is mostly meant as a repository for code rather than a full solution.

You class could be included as an addition to the current "functions" directory, if that would suit your needs. I can't remove the "functions" directory as it is already being used by other projects and people, so... backwards compatibility.

It would just mean duplicating some code and testcases. Not the most ideal situation, but hardly a big problem considering the small size of it all.

p.s. Shouldn't the class be named something like "StableSortArray"? Possibly move it to a PSR-4 compliant directory structure and namespace.

joelpittet commented 8 years ago

Very good point on BC. Maybe could even be functional wrappers for the static methods. We could also get the PSR4 autoloading to work I bet.

I was thinking StableSortArray but went with the one Fabianx suggested to be sussinct but that is a good suggestion so I'll run it pas them if I'm even on the right track with this.

Thanks for the quick response.

joelpittet commented 8 years ago

Is there any open bug reports with PHP regarding these functions?

vanderlee commented 8 years ago

Did you have any chance to make some progress on the class and functional wrappers yet? I'd like to keep all this compatible with atleast PHP 5.3, which I don't think should be a problem.

As for open bug reports; I am not aware of any bugs.

joelpittet commented 8 years ago

I did not, I got distracted by shiny issues:(

vanderlee commented 8 years ago

I just did a merge and refactoring of your 2.0.0 branch into a new 2.0.1 branch. Essentially moving it to a non-drupal-specific class, changing the functions to reference the class and some other minor changes. The class remains unchanged apart from the name.

I also renamed the project to https://github.com/vanderlee/PHP-stable-sort, to remove the "functions" part.

joelpittet commented 8 years ago

Oh that's great @vanderlee Thank you!

I wonder out of curiosity, do you follow a coding standard like PSR2 or PSR12 or from another project? Just wondering because Drupal is in the middle of discussing again if they will adopt either of those over their own.

Also, I wonder how (still learning) to ensure this works well with PSR4 autoloading. Likely needs to be namespaced under your name and setup in composer.json somehow. If I sort that out I'll send another pull request.

vanderlee commented 8 years ago

I'm not entirely up to date with all PSR standards. I try to adhere to them, but I also put value in trying to keep it usable in old PHP 5.3 (and even 5.2 if possible) that might not play nice with some of the newer standards.

You are probably right about the namespace though. Possibly the directory "classes" should be renamed to reflect that.

joelpittet commented 8 years ago

I usually use src/ Some references: http://www.php-fig.org/psr/psr-4/examples/ http://www.php-fig.org/psr/psr-4/