Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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
Collaborator

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

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

Replace \n with PHP_EOL

@stof
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 Owner

So we should change all of them. =)

@stof
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 Owner

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

@stof
stof added a note

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

@guilhermeblanco Owner

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
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
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 Owner

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 from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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 Owner

Replace \n with PHP_EOL

@stof
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 Owner

So we should change all of them. =)

@stof
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 Owner

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

@stof
stof added a note

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

@guilhermeblanco Owner

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