-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Format generated config files using the short array syntax #12499
Format generated config files using the short array syntax #12499
Conversation
As an added note, I did attempt to do this using
|
{ | ||
if (gettype($var) === 'array') { | ||
$indexed = array_keys($var) === range(0, count($var) - 1); | ||
$r = []; |
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.
Please avoid variables with unclear names. $r
does not really describe what is it for.
* @param integer $depth | ||
* @return string | ||
*/ | ||
private function varExportShort($var, $depth = 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.
Please take advantage of PHP 7.0 syntax (type hints and return types for methods)
*/ | ||
private function varExportShort($var, $depth = 0) | ||
{ | ||
if (gettype($var) === '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.
Is there any specific reason not to use is_array
?
Additionally, readability may be slightly improved by reversing the logic like
if (!is_array($var)) {
return var_export($var, true);
}
/// Transforming to short array syntax here
...
@@ -11,6 +11,8 @@ | |||
*/ | |||
class PhpFormatter implements FormatterInterface | |||
{ | |||
const INDENT = ' '; |
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.
Please add a description for the constant (docBlock)
- const documenation - reverse condition for readability - better variable name - type and return hints
@ishakhsuvarov @okorshenko I was more or less expecting these changes would be in 2.2.2. Is it odd to you that it is on the 2.2.2-preview branch but not on the 2.2.2 tag? Or does that happen often? |
What if we want 4 spaces tab indentation? Shouldn't this follow a PSR? |
@clementblanco That did cross my mind, and I would prefer it as well, but I neglected to do it...I think because I was continuing to use |
Description
app/etc/config.php
(http://devdocs.magento.com/guides/v2.2/config-guide/config/config-php.html)app/etc/config.php
uses the long array syntax.Put that all together and the auto-generated config doesn't match the required standards to be checked in. The change made in this PR is to modify
PhpFormatter
to recursively return the array representation using short array syntax[]
instead of longarray()
. If the given variable is not an array, it uses the standardvar_export
behavior.Manual testing scenarios
Contribution checklist