@@ -104,7 +104,11 @@ public function addProperty(string $name, $value = null)
104104 public function addMethod (string $ methodString , bool $ isDeprecated = false , ?string $ deprecationReason = null )
105105 {
106106 if (!empty ($ methodString )) {
107- $ this ->methods [] = $ this ->prependDeprecationComment ($ methodString , $ isDeprecated , $ deprecationReason );
107+ $ methodString = $ this ->prependDeprecationComment ($ methodString , $ isDeprecated , $ deprecationReason );
108+
109+ // Normalize line endings here to make replacements in generateMethods() work.
110+ $ methodString = $ this ->normalizeLineEndings ($ methodString );
111+ $ this ->methods [] = $ methodString ;
108112 }
109113 }
110114
@@ -126,7 +130,8 @@ protected function generateFileContents(): string
126130 if (!empty ($ properties )) $ properties = PHP_EOL . $ properties ;
127131 $ methods = $ this ->generateMethods ();
128132
129- return sprintf (static ::FILE_FORMAT , $ namespace , $ imports , $ className , $ properties , $ methods );
133+ $ contents = sprintf (static ::FILE_FORMAT , $ namespace , $ imports , $ className , $ properties , $ methods );
134+ return $ this ->normalizeLineEndings ($ contents );
130135 }
131136
132137 /**
@@ -224,4 +229,14 @@ protected function prependDeprecationComment(string $code, bool $isDeprecated, ?
224229
225230 return $ code ;
226231 }
232+
233+ protected function normalizeLineEndings (string $ code )
234+ {
235+ $ code = str_replace ("\r" , '' , $ code );
236+ if (PHP_EOL !== "\n" ) {
237+ $ code = str_replace ("\n" , PHP_EOL , $ code );
238+ }
239+
240+ return $ code ;
241+ }
227242}
0 commit comments