Skip to content

Loading…

Do not add trailing whitespace to blank lines #493

Merged
merged 4 commits into from

4 participants

@nmpolo

This change prevents spaces from being added to blank lines so PHP Code Sniffer doesn't generate errors when using PSR2 standards.

@doctrinebot

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2108

@stof
Doctrine member

:+1:

@guilhermeblanco guilhermeblanco commented on the diff
lib/Doctrine/ORM/Tools/EntityGenerator.php
@@ -363,7 +363,7 @@ public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path)
$body = str_replace('<spaces>', $this->spaces, $body);
$last = strrpos($currentCode, '}');
- return substr($currentCode, 0, $last) . $body . (strlen($body) > 0 ? "\n" : ''). "}";
+ return substr($currentCode, 0, $last) . $body . (strlen($body) > 0 ? "\n" : ''). "}\n";
@guilhermeblanco Doctrine member

Replace \n with PHP_EOL

@stof Doctrine member
stof added a note

@guilhermeblanco All other parts of the EntityGenerator are using \n, not PHP_EOL. Why should the last newline be different ?

@guilhermeblanco Doctrine member

So we should change all of them. =)

@stof Doctrine member
stof added a note

why ? I'm on windows, but all my code uses \n, not \r\n. Commiting different line-endings according to the platform leads to a mess in the project.
Btw, PSR-2 tells to use \n for newlines, and the PHP-CS-Fixer will enforce it (and my git config will enforce it too by converting them before commiting).

@guilhermeblanco Doctrine member

Hm... I forgot about PSR-2.
You're right... this change request is invalid then. It's still one missing... =)

@stof Doctrine member
stof added a note

Does PSR-2 really asks for 2 end of line at the end of the file ?

@guilhermeblanco Doctrine member

It asks only one. It's written in 2.2.

All PHP files MUST end with a single blank line.

@nmpolo
nmpolo added a note

So should I leave this as it is?

@stof Doctrine member
stof added a note

for me, yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@guilhermeblanco guilhermeblanco commented on an outdated diff
lib/Doctrine/ORM/Tools/EntityGenerator.php
@@ -1207,7 +1207,9 @@ private function prefixCodeWithSpaces($code, $num = 1)
$lines = explode("\n", $code);
foreach ($lines as $key => $value) {
- $lines[$key] = str_repeat($this->spaces, $num) . $lines[$key];
+ if (!empty($value)) {
@guilhermeblanco Doctrine member

Missing spaces around ! sign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@guilhermeblanco guilhermeblanco merged commit a445793 into doctrine:master

1 check failed

Details default The Travis build failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/Doctrine/ORM/Tools/EntityGenerator.php
View
6 lib/Doctrine/ORM/Tools/EntityGenerator.php
@@ -364,7 +364,7 @@ public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path)
$body = str_replace('<spaces>', $this->spaces, $body);
$last = strrpos($currentCode, '}');
- return substr($currentCode, 0, $last) . $body . (strlen($body) > 0 ? "\n" : ''). "}";
+ return substr($currentCode, 0, $last) . $body . (strlen($body) > 0 ? "\n" : ''). "}\n";
@guilhermeblanco Doctrine member

Replace \n with PHP_EOL

@stof Doctrine member
stof added a note

@guilhermeblanco All other parts of the EntityGenerator are using \n, not PHP_EOL. Why should the last newline be different ?

@guilhermeblanco Doctrine member

So we should change all of them. =)

@stof Doctrine member
stof added a note

why ? I'm on windows, but all my code uses \n, not \r\n. Commiting different line-endings according to the platform leads to a mess in the project.
Btw, PSR-2 tells to use \n for newlines, and the PHP-CS-Fixer will enforce it (and my git config will enforce it too by converting them before commiting).

@guilhermeblanco Doctrine member

Hm... I forgot about PSR-2.
You're right... this change request is invalid then. It's still one missing... =)

@stof Doctrine member
stof added a note

Does PSR-2 really asks for 2 end of line at the end of the file ?

@guilhermeblanco Doctrine member

It asks only one. It's written in 2.2.

All PHP files MUST end with a single blank line.

@nmpolo
nmpolo added a note

So should I leave this as it is?

@stof Doctrine member
stof added a note

for me, yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
/**
@@ -1213,7 +1213,9 @@ private function prefixCodeWithSpaces($code, $num = 1)
$lines = explode("\n", $code);
foreach ($lines as $key => $value) {
- $lines[$key] = str_repeat($this->spaces, $num) . $lines[$key];
+ if ( ! empty($value)) {
+ $lines[$key] = str_repeat($this->spaces, $num) . $lines[$key];
+ }
}
return implode("\n", $lines);
Something went wrong with that request. Please try again.