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

[DependencyInjection] Handle env var placeholders in CheckTypeDeclarationsPass #34783

Merged

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Dec 3, 2019

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

A case we forgot to handle.

@nicolas-grekas nicolas-grekas added this to the 4.4 milestone Dec 3, 2019
@nicolas-grekas
Copy link
Member

There's something we do in Config: we replace env placeholders with credible values.
But honestly, it can only go back to false-positives. And the false-negatives don't matter: as long as the app works, it doesn't exist.

The goal of the command is not to prove a theoretical point but to help spot errors quickly.

We should skip instead.

@fancyweb fancyweb force-pushed the fwb-lint-command-handle-env-var-placeholders branch from 748d88e to 28dc7ca Compare December 5, 2019 14:07
@fancyweb fancyweb changed the title [DependencyInjection] Resolve env var placeholders in CheckTypeDeclarationsPass [DependencyInjection] Skip env var placeholders in CheckTypeDeclarationsPass Dec 5, 2019
@fancyweb fancyweb force-pushed the fwb-lint-command-handle-env-var-placeholders branch 2 times, most recently from df891df to 47e9a0f Compare December 5, 2019 20:32
$value = $this->container->getParameter($match[1]);
} elseif (\is_string($value)) {
if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) {
// Only array parameters are not inlined when dumped.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comments because those things are kind of hard to follow. We actually don't need to resolve the value here since we only care about the type.

@fancyweb fancyweb changed the title [DependencyInjection] Skip env var placeholders in CheckTypeDeclarationsPass [DependencyInjection] Handle env var placeholders in CheckTypeDeclarationsPass Dec 5, 2019
} elseif ($envPlaceholderUniquePrefix && false !== strpos($value, 'env_')) {
// If the value is an env placeholder that is either mixed with a string or with another env placeholder, then its resolved value will always be a string, so we don't need to resolve it.
// We don't need to change the value because it is already a string.
if ('' === preg_replace('/'.$envPlaceholderUniquePrefix.'_\w+_[a-f0-9]{32}/U', '', $value, -1, $c) && 1 === $c) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

3 cases here (with param: "%env(FOO)%":

  • only 1 env placeholder (eg: %param%) -> we try to resolve it to get its type.
  • more than 1 chained env placeholder (eg: %param%%param%) -> it has to be a string
  • mixed env placeholder with a string (eg : foo%param%) -> it has to be a string

@fancyweb fancyweb force-pushed the fwb-lint-command-handle-env-var-placeholders branch from 47e9a0f to e1df59a Compare December 5, 2019 20:42
@fancyweb fancyweb force-pushed the fwb-lint-command-handle-env-var-placeholders branch from e1df59a to c357485 Compare December 5, 2019 22:06
@fabpot
Copy link
Member

fabpot commented Dec 7, 2019

Thank you @fancyweb.

fabpot added a commit that referenced this pull request Dec 7, 2019
…TypeDeclarationsPass (fancyweb)

This PR was merged into the 4.4 branch.

Discussion
----------

[DependencyInjection] Handle env var placeholders in CheckTypeDeclarationsPass

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

A case we forgot to handle.

Commits
-------

c357485 [DependencyInjection] Handle env var placeholders in CheckTypeDeclarationsPass
@fabpot fabpot merged commit c357485 into symfony:4.4 Dec 7, 2019
@fancyweb fancyweb deleted the fwb-lint-command-handle-env-var-placeholders branch December 9, 2019 08:09
This was referenced Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants