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

Remove deprecated and legacy code, migrate some syntax, cleanup #908

Merged

Conversation

robfrawley
Copy link
Collaborator

@robfrawley robfrawley commented Apr 13, 2017

Q A
Branch? 2.0
Bug fix? no
New feature? no
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

This PR removes all obviously marked deprecations and legacy code/tests from the 1.x branch for the 2.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

  • Symfony >= 2.8
  • PHP >= 7.0

Todo Still

  • Change to short array syntax
  • Remove obviously marked deprecations
  • Remove obviously marked legacy code/text
  • Remove unobvious deprecations
  • Remove unobvious legacy code/texts
  • Update UPGRADE.md with all changes
  • Update any relevant documentation

Should we Go Further

Do we want to bump one more version for PHP and require PHP 7.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.

@robfrawley robfrawley added Attn: BC Break This issue or PR results in a backwards-compatibility break and therefore requires a major release. Type: Documentation This item pertains to documentation of this project. Level: Enhancement ✨ This item involves an enhancement to existing functionality. State: Reviewing This item is being reviewed to determine if it should be accepted. Type: Support This item pertains to support for this project. RFC: Draft This indicates the described RFC is still being drafted. labels Apr 13, 2017
@robfrawley robfrawley added this to the 2.0.0 milestone Apr 13, 2017
@robfrawley robfrawley self-assigned this Apr 13, 2017
@robfrawley robfrawley changed the title [WIP] Remove deprecations, legacy code, etc [WIP] [RFC] Remove deprecations, legacy code, etc Apr 13, 2017
@robfrawley
Copy link
Collaborator Author

Ooh yeah; Travis test time down from 13-15 minutes to 4 minutes!

@alexwilson
Copy link
Collaborator

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!

@rpkamp
Copy link
Contributor

rpkamp commented Apr 23, 2017

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();
Copy link
Contributor

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();
Copy link
Contributor

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 []

public function getFilters()
{
return [
new \Twig_SimpleFilter('imagine_filter', array($this->helper, 'filter')),
Copy link
Contributor

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']

/**
* {@inheritdoc}
*/
public function getName()
Copy link
Contributor

@rpkamp rpkamp Apr 23, 2017

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.

@robfrawley robfrawley force-pushed the feature-deprecation-and-legacy-removal branch 8 times, most recently from 2872097 to 714be65 Compare April 24, 2017 04:49
@robfrawley robfrawley force-pushed the feature-deprecation-and-legacy-removal branch from 714be65 to f97a3cd Compare May 2, 2017 16:57
@robfrawley
Copy link
Collaborator Author

robfrawley commented May 2, 2017

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 UPGRADE.md and CHANGELOG.md files, this is ready to go. Things to consider before finalizing this PR:

  • Are we comfortable making the 2.x branch PHP 7.x only? Benefits include a vastly simplified Travis test definition file, as well as allowing us to introduce function type hints (which, IMHO, help with usage, debugging, and provide a great firewall between an improper use of a method), as well as some other language constructs. Moreover, as was already pointed out, the next major Symfony version will require PHP 7.x and I foresee releasing 2.x around the same timeframe (Novemberish). Of course, the 1.x branch will remain as is for those who need to use PHP 5.6, and I intend to continue to accept PRs and issues against it for some time, so it's not like people won't be able to use this bundle with older PHP versions...thoughts?

  • The Mongo functionality was removed due to it no longer working (the same extension isn't going to be made available for PHP 7.x); do we want to rewrite it instead of removing it (for the new extension)?

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 2.x branch, but I don't want to add those until we've got this completed to avoid merge conflicts.

(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);
Copy link
Collaborator Author

@robfrawley robfrawley May 2, 2017

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.

@Koc
Copy link
Contributor

Koc commented May 2, 2017

+1 for PHP 7.x or even 7.1 for nullable return types

@robfrawley robfrawley changed the title [WIP] Remove deprecated and legacy code, migrate syntax to PHP 7+ [WIP] Remove deprecated and legacy code, migrate some syntax May 3, 2017
@robfrawley robfrawley removed the RFC: Draft This indicates the described RFC is still being drafted. label May 3, 2017

$this->locator->setOptions(array('roots' => (array) $dataRoots));
$this->locator = $locator;
$this->locator->setOptions(['roots' => $rootPaths]);
Copy link
Contributor

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

@robfrawley robfrawley May 3, 2017

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?

Copy link
Contributor

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 😃

Copy link
Collaborator Author

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);
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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()
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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]);
Copy link
Contributor

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.

Copy link
Collaborator Author

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]);
Copy link
Contributor

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.

Copy link
Collaborator Author

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

<tag name="twig.extension" />
<argument type="service" id="liip_imagine.cache.manager" />
<argument type="service" id="liip_imagine.templating.filter_helper" />
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

@robfrawley
Copy link
Collaborator Author

@rpkamp Thanks for the review!

@robfrawley robfrawley force-pushed the feature-deprecation-and-legacy-removal branch from 83b7646 to 279504d Compare May 3, 2017 21:12
@robfrawley robfrawley changed the title [WIP] Remove deprecated and legacy code, migrate some syntax [WIP] Remove deprecated and legacy code, migrate some syntax, cleanup May 3, 2017
*/
private function getChildDefinition($parent)
{
return class_exists('\Symfony\Component\DependencyInjection\ChildDefinition') ?
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

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.

@robfrawley
Copy link
Collaborator Author

All the changes introduced by the pull request, as well as #914, have been added to the UPGRADE.md file in commit f04ffa3. @antoligy @cedricziel Any comments before this is merged?

@alexwilson
Copy link
Collaborator

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?

Copy link
Collaborator

@alexwilson alexwilson left a 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()
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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()
Copy link
Collaborator

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?

Copy link
Collaborator

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)

Copy link
Collaborator Author

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
Copy link
Collaborator

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?

@robfrawley
Copy link
Collaborator Author

@antoligy

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.

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 mongodb extension, but as I don't use it I'm not particularly qualified to create the adapter myself.

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)

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.

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!

Agreed; this blew up quick in size due to how many changes affected many files, but generally I agree with you here.

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?

I'm comfortable with Symfony 3.x as our 2.x base requirement.

@robfrawley robfrawley force-pushed the feature-deprecation-and-legacy-removal branch from f04ffa3 to 2ffc615 Compare May 6, 2017 17:42
robfrawley added 2 commits May 6, 2017 14:05
- 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
@robfrawley robfrawley force-pushed the feature-deprecation-and-legacy-removal branch from 2ffc615 to 2528fc2 Compare May 6, 2017 18:06
@robfrawley
Copy link
Collaborator Author

robfrawley commented May 6, 2017

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!

@rpkamp
Copy link
Contributor

rpkamp commented May 7, 2017

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 😃

@robfrawley
Copy link
Collaborator Author

robfrawley commented May 7, 2017

@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.

@rpkamp
Copy link
Contributor

rpkamp commented May 7, 2017

I will have a look once this PR is fixed, no problem

@robfrawley robfrawley merged commit d9081a2 into liip:2.0 May 7, 2017
@lsmith77 lsmith77 removed the State: Reviewing This item is being reviewed to determine if it should be accepted. label May 7, 2017
@robfrawley robfrawley changed the title [WIP] Remove deprecated and legacy code, migrate some syntax, cleanup Remove deprecated and legacy code, migrate some syntax, cleanup May 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Attn: BC Break This issue or PR results in a backwards-compatibility break and therefore requires a major release. Level: Enhancement ✨ This item involves an enhancement to existing functionality. Type: Documentation This item pertains to documentation of this project. Type: Support This item pertains to support for this project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants