Skip to content

Commit 0fa345c

Browse files
committed
feat: add method equals in class skeleton
1 parent e2e4203 commit 0fa345c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/wizardPhpSkeletons.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ async function generatePhpClassSkeleton(className: string, namespace: string): P
9090
}
9191

9292
let gettersAndSetters = "";
93+
let equalsCondition = [];
9394
for (const property of properties) {
9495
const capitalizedName = capitalize(property.name);
9596
gettersAndSetters += `
@@ -101,8 +102,17 @@ async function generatePhpClassSkeleton(className: string, namespace: string): P
101102
{
102103
$this->${property.name} = $${property.name};
103104
}`;
105+
equalsCondition.push(`$this->get${capitalizedName}() == $toCompare->get${capitalizedName}()`);
104106
}
105107

108+
109+
const equalsMethod = equalsCondition.length ? `
110+
public function equals(self $toCompare): boolean
111+
{
112+
return ${equalsCondition.join('\n AND ')};
113+
}
114+
` : '';
115+
106116
const skeleton = `<?php
107117
108118
declare(strict_types=1);
@@ -116,6 +126,8 @@ class ${className}
116126
}
117127
118128
${gettersAndSetters}
129+
130+
${equalsMethod}
119131
}`;
120132

121133
return skeleton;

0 commit comments

Comments
 (0)