Remove thecodingmachine/safe dependency#1482
Remove thecodingmachine/safe dependency#1482SjorsO wants to merge 2 commits intoMyIntervals:mainfrom
thecodingmachine/safe dependency#1482Conversation
|
Thanks @SjorsO. I did not realize 'Safe' was such a large library. I think that may because it is made by autogenerating the code from the PHP documenation (on , and puts the entire lot in the DocBlocks. For example the DocBlock for I've allowed the CI checks to run, which has picked up a few minor issues. Would you be able to resolve those?
We have only just started using 'Safe', and didn't consider that it may throw additional exceptions to be a breaking change.
I agree; I think it's highly unlikely, particularly as we have only just started using 'Safe'. |
|
If we copy those functions to our package, the added code becomes our responsibility and needs to follow the standards we have for new code: It needs proper test coverage, and we need to maintain it for the foreseeable future, including keeping it up to date with future PHP releases. Someone needs to do this work. I’m inclined to not take this responsibility myself. @SjorsO @JakeQZ Would any of you be willing to write the tests and shoulder maintaining the new functions? |
It doesn't stop there. We are also now using the 'Safe' library in Emogrifier of which this package is a dependency. Emogrifier is used by the WooCommerce WordPress plugin which is installed on over 4 million websites. I don't think this is a tenable solution, but I don't know what is. Options might include:
Obviously it is disappointing that the 'Safe' library turns out to be bloatware. |
Or create a separate package akin to 'Safe' that only includes the most commonly-used functions, and does not auto-generate the source. |
|
FWIW, I checked the size of the package I have installed with PHP 8.3. It's 6.31 MB, with 573 files. That does not seem like a lot to me, given that a typical photo from a phone is around 3 MB, and also considering that some popular WordPress plugins are much heftier:
Though I agree it's much more than it should be. I think the way forward is to get the issues fixed in the 'Safe' libraray:
|
|
That might be the best option for the time being, although a PITA. |
Personally I'd go with explicitly checking for I'm honestly not exactly sure why these "safe" functions are necessary. All other libraries I use don't seem to use them (including all of Laravel). |
It helps us keep our code simple as we don't need to check for |
|
For reference, I've opened up a new PR with a different approach: #1484 |
This PR drops the dependency on
thecodingmachine/safeby absorbing the 7 functions that PHP-CSS-Parser actually uses (out of the 1,110+ functions that the dependency defines).Removing this dependency significantly reduces the size of PHP-CSS-Parser:
PHP-CSS-Parser is installed 3.8 million times per month, assuming one compressed download per install, then this PR would save ~5 TB of bandwidth monthly. Removing this many lines of text may also speed up IDE indexing, although that's hard to measure.
This PR is a breaking change, code like this will no longer work:
Code like this must be updated to catch
Sabberworm\CSS\Safe\Exceptions\PcreException $einstead (although it seems unlikely to me that anyone is catching these exceptions specifically instead ofExceptionorThrowable).I haven't removed the
thecodingmachine/phpstan-safe-rulePHPStan rule, it still works as before.I've excluded
safe_functions.phpfrom PHPStan both because the phpdocs don't match the inspections, and because it would warn about the unsafe functions in this file.