Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit 20e1d4d

Browse files
author
amarcu
committed
Fix test warning, improve naming in tests
1 parent 61070f0 commit 20e1d4d

21 files changed

+54
-45
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/vendor/
2+
composer.lock

examples/dorm/CodegenDorm.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function generate(): void {
4545
$path = $rc->getFileName();
4646
$pos = strrpos($path, '/');
4747
$dir = substr($path, 0, $pos + 1);
48+
$gen_from = 'codegen.php '.$this->getSchemaName().'Schema';
4849

4950
// This generates a file (we pass the file name) that contains the
5051
// class defined above and saves it.
@@ -54,7 +55,7 @@ public function generate(): void {
5455
// of the existing file and merging it if it's partially generated.
5556
codegen_file($dir.$this->getSchemaName().'.php')
5657
->addClass($class)
57-
->setGeneratedFrom(codegen_generated_from_script())
58+
->setGeneratedFrom(codegen_generated_from_script($gen_from))
5859
->save();
5960
}
6061

examples/dorm/CodegenMutator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ public function generate(): void {
5151
$path = $rc->getFileName();
5252
$pos = strrpos($path, '/');
5353
$dir = substr($path, 0, $pos + 1);
54+
$gen_from = 'codegen.php '.$rc->getShortName();
5455

5556
// This generates a file (we pass the file name) that contains the
5657
// class defined above and saves it.
5758
codegen_file($dir.$name.'.php')
5859
->addClass($class)
5960
->setIsStrict(true)
60-
->setGeneratedFrom(codegen_generated_from_script())
61+
->setGeneratedFrom(codegen_generated_from_script($gen_from))
6162
->save();
6263
}
6364

examples/dorm/demo/DormUser.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
* This file is partially generated. Only make modifications between BEGIN
44
* MANUAL SECTION and END MANUAL SECTION designators.
55
*
6-
* To re-generate this file run
7-
* /home/ubuntu/hack-codegen/examples/dorm/codegen.php
6+
* To re-generate this file run codegen.php DormUserSchema
87
*
98
*
10-
* @partially-generated SignedSource<<f9e8b0c880da41854d491905f3a7314e>>
9+
* @partially-generated SignedSource<<609ad77761b889b1c3dd2a45c5aa296a>>
1110
*/
1211

1312
final class DormUser {

examples/dorm/demo/DormUserMutator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
* This file is partially generated. Only make modifications between BEGIN
44
* MANUAL SECTION and END MANUAL SECTION designators.
55
*
6-
* To re-generate this file run
7-
* /home/ubuntu/hack-codegen/examples/dorm/codegen.php
6+
* To re-generate this file run codegen.php DormUserSchema
87
*
98
*
10-
* @partially-generated SignedSource<<f9c5059806c0ec22c4ba40846c277eb9>>
9+
* @partially-generated SignedSource<<aed81933eb3016547905627d230a9d5a>>
1110
*/
1211

1312
final class DormUserMutator {

lib/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function createTemporaryFile(
1717
): string {
1818
$fname = tempnam(sys_get_temp_dir(), $prefix);
1919
if ($cleanup) {
20-
register_shutdown_function(array('Filesystem', 'remove'), $fname);
20+
register_shutdown_function(array(Filesystem::class, 'remove'), $fname);
2121
}
2222
return $fname;
2323
}

src/CodegenClass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function getExtends(): ?string {
5151
return $this->extendsClass;
5252
}
5353

54+
5455
public function setConstructor(CodegenConstructor $constructor): this {
5556
$this->constructor = $constructor;
5657
return $this;

src/CodegenFile.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,13 @@ public function render(): string {
228228

229229
$old_content = $this->loadExistingFiles();
230230

231-
$doc_block = $this->docBlock;
232-
if ($this->generatedFrom !== null) {
233-
$doc_block = $doc_block. $this->generatedFrom->render() ."\n";
231+
$doc_block = (string)$this->docBlock;
232+
$gen_from = $this->generatedFrom;
233+
if ($gen_from !== null) {
234+
if ($doc_block && !Str::endsWith($doc_block, "\n")) {
235+
$doc_block .= "\n";
236+
}
237+
$doc_block = $doc_block.$gen_from->render()."\n";
234238
}
235239

236240
if (PartiallyGeneratedCode::containsManualSection($content)) {

src/CodegenFunctionBase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public function __construct(
3838
$this->name = $name;
3939
}
4040

41+
public function setName(string $name): this {
42+
$this->name = $name;
43+
return $this;
44+
}
45+
4146
public function setIsAsync(bool $value = true): this {
4247
$this->isAsync = $value;
4348
return $this;

src/CodegenGeneratedFrom.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ function codegen_generated_from_class(string $class): CodegenGeneratedFrom {
3434
return new CodegenGeneratedFrom("Generated from $class");
3535
}
3636

37-
function codegen_generated_from_string(string $string): CodegenGeneratedFrom {
38-
return new CodegenGeneratedFrom("Generated from $string");
39-
}
40-
4137
function codegen_generated_from_method(
4238
string $class,
4339
string $method

0 commit comments

Comments
 (0)