-
Notifications
You must be signed in to change notification settings - Fork 379
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
Remove deprecated and legacy code, migrate some syntax, cleanup #908
Remove deprecated and legacy code, migrate some syntax, cleanup #908
Conversation
Ooh yeah; Travis test time down from 13-15 minutes to 4 minutes! |
There's a lot to this diff so it'll take me a while to go through in detail, but most immediately looking through how much more ... readable the testing configuration now is ... thank you so much! |
Seeing how PHP 5.6 is officially end of life, I don't see a reason to support it anymore in 2.0. Also Symfony 4 will also require PHP 7.0 (https://medium.com/@fabpot/fabien-potencier-4574622d6a7e) and Monolog 2.x will also require PHP 7.0 (https://github.com/Seldaek/monolog/blob/master/composer.json) |
@@ -25,12 +25,12 @@ class LiipImagineExtension extends Extension | |||
/** | |||
* @var ResolverFactoryInterface[] | |||
*/ | |||
protected $resolversFactories = array(); | |||
private $resolversFactories = array(); |
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.
array()
could be replaced with []
|
||
/** | ||
* @var LoaderFactoryInterface[] | ||
*/ | ||
protected $loadersFactories = array(); | ||
private $loadersFactories = array(); |
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.
array()
could be replaced with []
Templating/FilterExtension.php
Outdated
public function getFilters() | ||
{ | ||
return [ | ||
new \Twig_SimpleFilter('imagine_filter', array($this->helper, 'filter')), |
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.
can be replaced with [$this->helper, 'filter']
Templating/FilterExtension.php
Outdated
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() |
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.
Twig_Extension#getName
is deprecated and should be removed.
See https://github.com/twigphp/Twig/blob/2.x/CHANGELOG#L153
UPDATE: It seems Symfony/FrameworkBundle for 2.8 requires at least Twig 1.23 so this comment is invalid. Please ignore it.
2872097
to
714be65
Compare
714be65
to
f97a3cd
Compare
Rebased to fix merge conflicts introduced by #914 (that PR removed all class name parameters from the service definition file). @antoligy @cedricziel Aside from updating the
Aside from getting your opinion on the above items, I'd really appreciate it if you guys could take some time to review some of the changes introduced by the PR. I have other PRs that will start architecturally changing this bundle on the (If anyone else involved in this discussion has time to review this PR, that would greatly appreciated as well; this is a large PR so the more eyes the better @rpkamp @Koc) |
if (func_num_args() >= 4 && false === ($this->locator = func_get_arg(3)) instanceof LocatorInterface) { | ||
throw new \InvalidArgumentException(sprintf('Method %s() expects a LocatorInterface for the forth argument.', __METHOD__)); | ||
} elseif (func_num_args() < 4) { | ||
@trigger_error(sprintf('Method %s() will have a forth `LocatorInterface $locator` argument in version 2.0. Not defining it is deprecated since version 1.7.2', __METHOD__), E_USER_DEPRECATED); |
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.
Note to self: This deprecation notice needs to be amended to properly articulate the changes.
+1 for PHP 7.x or even 7.1 for nullable return types |
|
||
$this->locator->setOptions(array('roots' => (array) $dataRoots)); | ||
$this->locator = $locator; | ||
$this->locator->setOptions(['roots' => $rootPaths]); |
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.
Why pass the $rootPaths
to this class anyway since it's only handing them off to the passed in LocatorInterface
? Why not set the option on the LocatorInterface
before passing it to this class?
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.
That is a valid question and something I've considered changing, but the current configuration handling of these items is tied to the *Loader
implementations and not the *Locator
classes; the FileLocator
and InsecureFileSystem
"locator" variants are really implementation details ATM.
I'm not really positive how we should handle this moving forward and am very open to its discussion, but I do think that it is more appropriate to handle that in a PR of its own, no?
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.
IDK: now you got me thinking maybe it should be fully handled in this PR; what do you think?
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.
Since you're making a signature change here I would solve the problem fully in this PR, instead of in another PR which breaks the signature a second time. People aren't supposed to be using 2.x yet I guess, but you never know 😃
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.
I have not found a straightforward solution to this, and based on my testing the solution will likely be quite large (only making this pull request even larger), so I don't forsee this issue being resolved by this pull request. See #908 (comment) for additional details.
As for breaking changes (multiple times), I'm not too concerned about that; the whole point of having a development branch is to be able to actively develop on it. Those running the 1.x
branch should expect no backward incompatible changes, but that doesn't apply here. I run the 2.0
branch on a few personal projects, and while it's annoying to update it when breaking changes occur, that is a contract I agreed to when I decided to run an unreleased version. We're going to need to introduce a plethora of additional breaking changes to complete many of the TODO items for 2.0
, so let's focus on making the release amazing and not on making it easier for those running unreleased software. Right?
|
||
$container->setDefinition($resolverId, $resolverDefinition); | ||
$container->setDefinition($resolverId = 'liip_imagine.cache.resolver.'.$resolverName, $resolverDefinition); |
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.
I would not make this change, it makes the code harder to read.
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.
We do this often in the codebase now and can be found all over the place. While I disagree it makes it harder to read, I recognize many people feel this way. We should likely adopt a CONTRIBUTING.md
file that defines some coding standards that the community agrees on as a whole.
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.
Updated
@@ -57,7 +57,7 @@ public function getConfiguration(array $config, ContainerBuilder $container) | |||
} | |||
|
|||
/** | |||
* @see Symfony\Component\DependencyInjection\Extension.ExtensionInterface::load() | |||
* @see \Symfony\Component\DependencyInjection\Extension.ExtensionInterface::load() |
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.
Why add the leading backslash here?
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.
This is being migrated everywhere (slowly, they are everywhere) as many IDEs try to resolve these as within the current namespace when they are not declared as a root FQCN, instead of how they should be resolved, as true FQCN.
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.
Excellent point, and there's more on how php docblocks FQCNs are supported here: https://phpdoc.org/docs/latest/guides/types.html#class-name
$factory = $this->resolversFactories[$factoryName]; | ||
|
||
$factory->create($container, $resolverName, $resolverConfig[$factoryName]); | ||
$this->resolversFactories[$factoryName = key($resolverConfig)]->create($container, $resolverName, $resolverConfig[$factoryName]); |
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.
assigning and using a variable in the same line makes it harder to read.
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.
Amended code to negate this issue
$definition->setFactoryClass($factory[0]); | ||
$definition->setFactoryMethod($factory[1]); | ||
} | ||
$this->loadersFactories[$factoryName = key($loaderConfig)]->create($container, $loaderName, $loaderConfig[$factoryName]); |
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.
assigning and using a variable in the same line makes it harder to read.
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.
Amended code to negate this issue
Resources/config/imagine.xml
Outdated
<tag name="twig.extension" /> | ||
<argument type="service" id="liip_imagine.cache.manager" /> | ||
<argument type="service" id="liip_imagine.templating.filter_helper" /> |
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.
Why couple the twig helper to the templating helper? I realise the mostly have the same code, but making one dependent on the other feels off. If there is an abstraction here I would say that both the twig extension and the templating helper should depend on a shared service.
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.
The intention was to remove code duplication; now that we've bumped the PHP requirements, though, traits serve the same purpose, so this has been rectified in that was, allowing both the helper and extension to again consume the CacheManager
.
@rpkamp Thanks for the review! |
83b7646
to
279504d
Compare
*/ | ||
private function getChildDefinition($parent) | ||
{ | ||
return class_exists('\Symfony\Component\DependencyInjection\ChildDefinition') ? |
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.
you can use ChildDefinition::class
here
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.
Actually you can't, because if the class doesn't exist (in case of older Symfony versions) that can't be resolved.
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.
it is safe for non-existent classes
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 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.
Updated all FQCN strings to the special ::class
compile-time constant: ee9c834. Thanks for the recommendation.
All the changes introduced by the pull request, as well as #914, have been added to the |
On the topic of PHP 7, the primary argument to keeping our requirements lower were to match up with Symfony 2.8. Since we've handled deprecations in 2.8 in the 1.0 branch anyway, now that we're raising to PHP 7 I'm honestly wondering if we ought to bump to Symfony 3.0? |
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.
Thanks for taking the trouble to go through and assemble this PR @robfrawley, this is a hefty chunk of the 2.0 roadmap and I cannot emphasise enough how useful all this is.
I've gone through with a more finely toothed comb, and all seems well, save for a few trivial things mostly housekeeping related...
This to me raises a few points to consider, potentially separately to this PR (because I would very much like to see it merged!):
- Do we know, or have a way of telling, who uses the adapters that we provide? I am thinking primarily of GridFS and wondering if the replacement/alternative (should one even be required, my bias is that I do not yet use it!) could be potentially handled by a separate library.
- Similarly, do we know if anybody uses this library running in a Hack environment? Have we just broken it with this suite of changes? (looks unlikely, given your reports on the testing setup and the linked issues)
- Smaller, and more frequent PRs for the future? I understand that a lot of this was similar-ish and had to be within the same PR, but anything we can do to reduce the size of individual diffs is a win!
There's a trend of metrics here, unfortunately I haven't been able to find any useful information in Packagist... Possibly something to raise in a further issue, because 2.0 gives us the chance to trial feature apoptosis.
@@ -18,24 +18,6 @@ class SymfonyFramework | |||
/** | |||
* @return bool | |||
*/ | |||
public static function hasDefinitionSharing() |
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.
Not that anybody should have bound to this (or has had the time), but, should we deprecate this instead of flat-out removing?
Either way I think we ought to reference flag removal in the UPGRADE doc.
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.
Looks like I missed this in the UPGRADE.md
file; it should absolutely be mentioned. As for removal vs depreciation, I believe we should take advantage of not having a 2.x
release yet and remove it.
Without a 2.x
release, those running this development branch should know the API isn't stable. The moment we have an initial 2.0.0
release, this changes and we absolutely need to deprecate, but as of now, we should take the ability to remove outright and do so over depreciation, IMHO.
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.
Definitely agreed about the 2.x API being unstable so it's ok to break atm until we are settled, we'd also be doing this by killing off the GridFS driver. 🙂
Happy to brush this one up then!
@@ -21,9 +22,9 @@ class SignerTest extends AbstractTest | |||
{ | |||
public function testImplementsSignerInterface() |
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.
This comment is not intended for action/review...
Now that I look at it, this is a very strange thing to test for! We typehint on SignerInterface, don't we?
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.
(And all the others like it)
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.
I always thought these tests were odd as well; 👍 remove them in another PR.
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException; | ||
|
||
class GridFSLoader implements LoaderInterface |
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.
I think so, but I'm not sure that this should hold back this PR. Let's add to the roadmap for 2.0?
We don't and have no way of knowing. I don't use it either. I assume we'll have a PR shortly to add an adapter for the new
Again, I don't know how we'd get access to any statistics. That said, the HHVM (in PHP 7 mode) issues extend outside this bundle to Composer and Symfony components, as well, so I do not believe anyone can relying on this bundle under those circumstances. Once HHVM fixes these core language issues, I'll be sure to enable support in Travis again, though it seems like many projects are leaving HHVM support now that PHP 7 was released and offers similar performance improvements. Sadly, the current state of HHVM makes it impossible to support PHP 7 and HHVM at the same time.
Agreed; this blew up quick in size due to how many changes affected many files, but generally I agree with you here.
I'm comfortable with Symfony 3.x as our 2.x base requirement. |
f04ffa3
to
2ffc615
Compare
- use short array syntax - update composer requirements to PHP 7+ and Symfony 3+ - migrate fqcn strings to ::class compile-time constant - move travis operations to bash scripts
2ffc615
to
2528fc2
Compare
I plan to merge this pull request at the end of today, now that we've had multiple reviews and all changes have been implemented, pending any objections from @antoligy, @cedricziel, @rpkamp or @Koc. Last chance to make additional changes! |
What about https://github.com/liip/LiipImagineBundle/pull/908/files#diff-af283426a4b2643990ccbcbae0d7555fR53? Will you fix it in this PR or should it be fixed later? Either way is fine by me 😃 |
@rpkamp Moving that should be handled in a subsequent pull request. I'm not positive how to solve this issue, and it will only make this huge pull request even larger as solving the issue will likely span many files. Can you take a look and submit a pull request; a few quick attempts I made failed and it's not a priority for me ATM. |
I will have a look once this PR is fixed, no problem |
This PR removes all obviously marked deprecations and legacy code/tests from the
1.x
branch for the2.x
branch, removing backward compatibility layers for older Symfony versions, and moves from legacy syntaxes to more modern solutions, such as from the long to short array syntax.Requirements
>= 2.8
>= 7.0
Todo Still
UPGRADE.md
with all changesShould we Go Further
Do we want to bump one more version for PHP and require PHP7.0
, which would allow for us to really clean up the code with function types explicitly mapped everywhere. IDK if it's worth it, but it's a thought.Thanks to some comments, previous discussions, and my own thoughts, ATM this PR does go a step further to requiring PHP
7.x
.The only consideration we need to make, with a move to
7.x
, is moving HHVM to an "allowed failure" for the time being. This is required due to HHVM's incorrect handling of language-level type checking, as well as globally-enabled function type checking, (in stark contrast to how PHP handled this), which breaks our code and some dependencies when running HHVM in PHP 7 mode. See the following issues for reference:I've worked around this a bit by explicitly disabling the "type checking" feature of HHVM via the INI setting, but other errors still persist in PHP7-mode, so IDK.