@@ -81,9 +81,42 @@ final public function add(?string $code): this {
8181 return $this -> addf(' %s' , $code );
8282 }
8383
84+ /**
85+ * Add the specified code with no additional processing.
86+ *
87+ * For example, if there is a newline, any following characters will not be
88+ * indented. This is useful for heredocs.
89+ *
90+ * @see addVerbatimf
91+ */
92+ final public function addVerbatim (string $code ): this {
93+ $this -> code -> append($code );
94+ return $this ;
95+ }
96+
97+ /**
98+ * Add the specified code with a %-placeholder format string, but no further
99+ * processing.
100+ *
101+ * For example, if there is a newline, any following characters will not be
102+ * indented. This is useful for heredocs.
103+ *
104+ * @see addVerbatim
105+ */
106+ final public function addVerbatimf (
107+ Str \SprintfFormatString $code ,
108+ mixed ...$args
109+ ): this {
110+ $this -> code -> append(\vsprintf ($code , $args ));
111+ return $this ;
112+ }
113+
84114 /* * Add code to the buffer, using a % placeholder format string. */
85- final public function addf (Str \SprintfFormatString $code , mixed ...$args ): this {
86- return $this -> addvf((string ) $code , $args );
115+ final public function addf (
116+ Str \SprintfFormatString $code ,
117+ mixed ...$args
118+ ): this {
119+ return $this -> addvf((string )$code , $args );
87120 }
88121
89122 /* * Add code to the buffer, using a % placeholder format string and
@@ -111,10 +144,11 @@ final protected function addvf(string $code, array<mixed> $args): this {
111144 // if we're in a new line, insert indentation
112145 if ($this -> isNewLine ) {
113146 if ($this -> indentationLevel !== 0 ) {
114- if ($this -> config -> shouldUseTabs()){
147+ if ($this -> config -> shouldUseTabs()) {
115148 $this -> code -> append(Str \repeat (" \t " , $this -> indentationLevel ));
116149 } else {
117- $n = $this -> config -> getSpacesPerIndentation() * $this -> indentationLevel ;
150+ $n =
151+ $this -> config -> getSpacesPerIndentation() * $this -> indentationLevel ;
118152 $this -> code -> append(Str \repeat (' ' , $n ));
119153 }
120154 }
@@ -129,10 +163,7 @@ final protected function addvf(string $code, array<mixed> $args): this {
129163 /**
130164 * If the condition is true, add code to the buffer; otherwise, do nothing.
131165 */
132- final public function addIf (
133- bool $condition ,
134- string $code ,
135- ): this {
166+ final public function addIf (bool $condition , string $code ): this {
136167 if ($condition ) {
137168 $this -> add($code );
138169 }
@@ -149,7 +180,7 @@ final public function addIff(
149180 mixed ...$args
150181 ): this {
151182 if ($condition ) {
152- $this -> addvf((string ) $code , $args );
183+ $this -> addvf((string )$code , $args );
153184 }
154185 return $this ;
155186 }
@@ -161,18 +192,15 @@ final protected function addLineImplvf(
161192 ?string $code ,
162193 array <mixed > $args ,
163194 ): this {
164- return $this -> addvf((string ) $code , $args )-> newLine();
195+ return $this -> addvf((string )$code , $args )-> newLine();
165196 }
166197
167198 /**
168199 * If the condition is true, append the code followed by a newline.
169200 *
170201 * @see addLineIff
171202 */
172- final public function addLineIf (
173- bool $condition ,
174- string $code ,
175- ): this {
203+ final public function addLineIf (bool $condition , string $code ): this {
176204 return $this -> addLineIff($condition , ' %s' , $code );
177205 }
178206
@@ -186,7 +214,7 @@ final public function addLineIff(
186214 mixed ...$args
187215 ): this {
188216 if ($condition ) {
189- $this -> addLineImplvf((string ) $code , $args );
217+ $this -> addLineImplvf((string )$code , $args );
190218 }
191219 return $this ;
192220 }
0 commit comments