|
|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
namespace App\Service\Doctrine\SchemaValidation;
|
|
|
@@ -39,16 +40,15 @@ use Nette\PhpGenerator\PsrPrinter;
|
|
|
class SchemaSnippetsMaker
|
|
|
{
|
|
|
public function __construct(
|
|
|
- private readonly EntityUtils $entityUtils
|
|
|
- )
|
|
|
- {}
|
|
|
+ private readonly EntityUtils $entityUtils,
|
|
|
+ ) {
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Make entities snippets from a 'diff' array,
|
|
|
- * as generated by SchemaValidationService::validateSchema()
|
|
|
+ * as generated by SchemaValidationService::validateSchema().
|
|
|
*
|
|
|
* @param array<string, Difference | array<Difference>> $diff
|
|
|
- * @return void
|
|
|
*/
|
|
|
public function makeSnippets(array $diff): void
|
|
|
{
|
|
|
@@ -128,12 +128,12 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Make the getters / setters for the given property
|
|
|
+ * Make the getters / setters for the given property.
|
|
|
*
|
|
|
- * @param Property $prop
|
|
|
* @return array<Method>
|
|
|
*/
|
|
|
- protected function makeMethodsSnippetForProp(Property $prop): array {
|
|
|
+ protected function makeMethodsSnippetForProp(Property $prop): array
|
|
|
+ {
|
|
|
$methods = [];
|
|
|
|
|
|
if ($prop->getType() !== Collection::class) {
|
|
|
@@ -149,11 +149,9 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Génère un objet ClassType
|
|
|
- * @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/ClassType.html
|
|
|
+ * Génère un objet ClassType.
|
|
|
*
|
|
|
- * @param string $entity
|
|
|
- * @return ClassType
|
|
|
+ * @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/ClassType.html
|
|
|
*/
|
|
|
protected function makeSnippetEntityClass(string $entity): ClassType
|
|
|
{
|
|
|
@@ -161,15 +159,14 @@ class SchemaSnippetsMaker
|
|
|
|
|
|
$class->setAttributes([
|
|
|
new Attribute(ApiResource::class, ['operations' => []]),
|
|
|
- new Attribute(Entity::class, [])
|
|
|
+ new Attribute(Entity::class, []),
|
|
|
]);
|
|
|
|
|
|
return $class;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Retourne le chemin absolu vers le répertoire dans lesquels sont créés les snippets
|
|
|
- * @return string
|
|
|
+ * Retourne le chemin absolu vers le répertoire dans lesquels sont créés les snippets.
|
|
|
*/
|
|
|
protected function getSnippetsDir(): string
|
|
|
{
|
|
|
@@ -177,12 +174,10 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Vide et ajuste les droits du répertoire des snippets
|
|
|
- *
|
|
|
- * @param string $snippetsDir
|
|
|
- * @return void
|
|
|
+ * Vide et ajuste les droits du répertoire des snippets.
|
|
|
*/
|
|
|
- protected function prepareSnippetsDir(string $snippetsDir): void {
|
|
|
+ protected function prepareSnippetsDir(string $snippetsDir): void
|
|
|
+ {
|
|
|
if (is_dir($snippetsDir)) {
|
|
|
FileUtils::rrmDir($snippetsDir);
|
|
|
}
|
|
|
@@ -190,38 +185,31 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Retourne le chemin absolu du snippet donné
|
|
|
- *
|
|
|
- * @param string $snippetsDir
|
|
|
- * @param string $entity
|
|
|
- * @return string
|
|
|
+ * Retourne le chemin absolu du snippet donné.
|
|
|
*/
|
|
|
protected function getSnippetPath(string $snippetsDir, string $entity): string
|
|
|
{
|
|
|
try {
|
|
|
$fullName = $this->entityUtils->getFullNameFromEntityName($entity);
|
|
|
} catch (\LogicException) {
|
|
|
- $fullName = '_NameSpaceNotFound/' . $entity;
|
|
|
+ $fullName = '_NameSpaceNotFound/'.$entity;
|
|
|
}
|
|
|
|
|
|
- $relativePath = str_replace('\\', '/', $fullName) . '.php';
|
|
|
+ $relativePath = str_replace('\\', '/', $fullName).'.php';
|
|
|
|
|
|
return Path::join($snippetsDir, $relativePath);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Créé le fichier du snippet sur le disque
|
|
|
- *
|
|
|
- * @param PhpFile $phpFile
|
|
|
- * @param string $fileName
|
|
|
- * @return void
|
|
|
+ * Créé le fichier du snippet sur le disque.
|
|
|
*/
|
|
|
- protected function writeSnippet(PhpFile $phpFile, string $fileName): void {
|
|
|
+ protected function writeSnippet(PhpFile $phpFile, string $fileName): void
|
|
|
+ {
|
|
|
if (!is_dir(dirname($fileName))) {
|
|
|
mkdir(dirname($fileName), 0777, true);
|
|
|
}
|
|
|
|
|
|
- $printer = new PsrPrinter;
|
|
|
+ $printer = new PsrPrinter();
|
|
|
|
|
|
$content = $printer->printFile($phpFile);
|
|
|
$content = $this->postProcessFileContent($content);
|
|
|
@@ -239,6 +227,7 @@ class SchemaSnippetsMaker
|
|
|
* les classes d'entités à importer (pour le typage de ces propriétés).
|
|
|
*
|
|
|
* @param array<string, Difference> $differences
|
|
|
+ *
|
|
|
* @return array<string>
|
|
|
*/
|
|
|
protected function getEntityToImportFromRelations(array $differences): array
|
|
|
@@ -247,9 +236,9 @@ class SchemaSnippetsMaker
|
|
|
|
|
|
foreach ($differences as $field => $difference) {
|
|
|
if (
|
|
|
- !is_array($difference->getExpectedType()) ||
|
|
|
- !in_array(isset($difference->getExpectedType()['type']), [ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE]) ||
|
|
|
- !isset($difference->getExpectedType()['targetEntity'])
|
|
|
+ !is_array($difference->getExpectedType())
|
|
|
+ || !in_array(isset($difference->getExpectedType()['type']), [ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE])
|
|
|
+ || !isset($difference->getExpectedType()['targetEntity'])
|
|
|
) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -272,15 +261,12 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Obtient le namespace pour l'entité donnée
|
|
|
- *
|
|
|
- * @param string $entity
|
|
|
- * @return string
|
|
|
+ * Obtient le namespace pour l'entité donnée.
|
|
|
*/
|
|
|
protected function getNamespaceValue(string $entity): string
|
|
|
{
|
|
|
try {
|
|
|
- $fullQualifiedName = str_contains($entity, "\\") ?
|
|
|
+ $fullQualifiedName = str_contains($entity, '\\') ?
|
|
|
$entity :
|
|
|
$this->entityUtils->getFullNameFromEntityName($entity);
|
|
|
|
|
|
@@ -292,7 +278,6 @@ class SchemaSnippetsMaker
|
|
|
|
|
|
/**
|
|
|
* @param array<string, string|array<string>> $type
|
|
|
- * @return string
|
|
|
*/
|
|
|
protected function getRelationTargetEntityName(array $type): string
|
|
|
{
|
|
|
@@ -305,14 +290,13 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Construit l'objet PhpFile
|
|
|
- * @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/PhpFile.html
|
|
|
+ * Construit l'objet PhpFile.
|
|
|
*
|
|
|
- * @return PhpFile
|
|
|
+ * @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/PhpFile.html
|
|
|
*/
|
|
|
protected function makeFileSnippet(): PhpFile
|
|
|
{
|
|
|
- $file = new PhpFile;
|
|
|
+ $file = new PhpFile();
|
|
|
$file->addComment('This file is auto-generated.');
|
|
|
$file->setStrictTypes();
|
|
|
|
|
|
@@ -320,11 +304,9 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Construit l'objet PhpNamespace
|
|
|
- * @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/PhpNamespace.html
|
|
|
+ * Construit l'objet PhpNamespace.
|
|
|
*
|
|
|
- * @param string $entity
|
|
|
- * @return PhpNamespace
|
|
|
+ * @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/PhpNamespace.html
|
|
|
*/
|
|
|
protected function makeNamespaceSnippet(string $entity): PhpNamespace
|
|
|
{
|
|
|
@@ -340,10 +322,9 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Construit l'objet Property pour le champs 'id' d'une entité
|
|
|
- * @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/Property.html
|
|
|
+ * Construit l'objet Property pour le champs 'id' d'une entité.
|
|
|
*
|
|
|
- * @return Property
|
|
|
+ * @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/Property.html
|
|
|
*/
|
|
|
protected function makeIdPropertySnippet(): Property
|
|
|
{
|
|
|
@@ -353,6 +334,7 @@ class SchemaSnippetsMaker
|
|
|
$prop->addAttribute('ORM\Id');
|
|
|
$prop->addAttribute('ORM\Column');
|
|
|
$prop->addAttribute('ORM\GeneratedValue');
|
|
|
+
|
|
|
return $prop;
|
|
|
}
|
|
|
|
|
|
@@ -365,16 +347,12 @@ class SchemaSnippetsMaker
|
|
|
'datetime' => '?\DateTimeInterface',
|
|
|
'json_array' => 'array',
|
|
|
][$doctrineType] ?? 'mixed';
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Make a Property object for a simple field (not a relation)
|
|
|
- * @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/Property.html
|
|
|
+ * Make a Property object for a simple field (not a relation).
|
|
|
*
|
|
|
- * @param string $name
|
|
|
- * @param string $type
|
|
|
- * @return Property
|
|
|
+ * @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/Property.html
|
|
|
*/
|
|
|
protected function makeSnippetEntitySimpleProp(string $name, string $type): Property
|
|
|
{
|
|
|
@@ -387,7 +365,7 @@ class SchemaSnippetsMaker
|
|
|
$prop = new Property($name);
|
|
|
$prop->setProtected();
|
|
|
$prop->setType($php_type);
|
|
|
- $prop->setComment("-- Warning : auto-generated property, checkup the attribute options --");
|
|
|
+ $prop->setComment('-- Warning : auto-generated property, checkup the attribute options --');
|
|
|
|
|
|
if ($type === 'text') {
|
|
|
$prop->addAttribute(Column::class, ['length' => 255, 'options' => ['nullable' => true]]);
|
|
|
@@ -407,12 +385,11 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Make a Property object for a relation field
|
|
|
+ * Make a Property object for a relation field.
|
|
|
+ *
|
|
|
* @see https://api.nette.org/php-generator/master/Nette/PhpGenerator/Property.html
|
|
|
*
|
|
|
- * @param string $name
|
|
|
* @param array<mixed> $type
|
|
|
- * @return Property
|
|
|
*/
|
|
|
protected function makeSnippetEntityCollectionProp(string $name, array $type): Property
|
|
|
{
|
|
|
@@ -421,12 +398,11 @@ class SchemaSnippetsMaker
|
|
|
$prop->setType('Collection');
|
|
|
|
|
|
if (
|
|
|
- isset($type['type']) &&
|
|
|
- $type['type'] === ClassMetadataInfo::ONE_TO_ONE || $type['type'] === ClassMetadataInfo::MANY_TO_ONE
|
|
|
+ isset($type['type'])
|
|
|
+ && $type['type'] === ClassMetadataInfo::ONE_TO_ONE || $type['type'] === ClassMetadataInfo::MANY_TO_ONE
|
|
|
) {
|
|
|
$targetEntityName = $this->getRelationTargetEntityName($type);
|
|
|
$prop->setType($targetEntityName);
|
|
|
-
|
|
|
} else {
|
|
|
$prop->setType(Collection::class);
|
|
|
}
|
|
|
@@ -449,10 +425,9 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Make the attribute defining the relation (ex: #[ORM\ManyToMany(...)])
|
|
|
+ * Make the attribute defining the relation (ex: #[ORM\ManyToMany(...)]).
|
|
|
*
|
|
|
* @param array<string | array<string | array<string>>> $type
|
|
|
- * @return Attribute
|
|
|
*/
|
|
|
protected function makeRelationAttribute(array $type): Attribute
|
|
|
{
|
|
|
@@ -462,7 +437,7 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
if (isset($type['targetEntity'])) {
|
|
|
- $options['targetEntity'] = $this->entityUtils->getEntityNameFromFullName($type['targetEntity']) . '::class';
|
|
|
+ $options['targetEntity'] = $this->entityUtils->getEntityNameFromFullName($type['targetEntity']).'::class';
|
|
|
}
|
|
|
|
|
|
if (isset($type['cascade'])) {
|
|
|
@@ -488,12 +463,12 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Make the #[ORM\JoinTable] attribute (if a definition exists)
|
|
|
+ * Make the #[ORM\JoinTable] attribute (if a definition exists).
|
|
|
*
|
|
|
* @param array<string | array<string | array<string>>> $type
|
|
|
- * @return Attribute|null
|
|
|
*/
|
|
|
- protected function makeJoinTableAttributes(array $type): ?Attribute {
|
|
|
+ protected function makeJoinTableAttributes(array $type): ?Attribute
|
|
|
+ {
|
|
|
if (!isset($type['joinTable'])) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -512,10 +487,11 @@ class SchemaSnippetsMaker
|
|
|
* Is `$inverse` is true, make the #[InverseJoinColumn] instead.
|
|
|
*
|
|
|
* @param array<string | array<string | array<string>>> $type
|
|
|
- * @param bool $inverse
|
|
|
+ *
|
|
|
* @return array<Attribute>
|
|
|
*/
|
|
|
- protected function makeJoinColumnAttributes(array $type, bool $inverse = false): array {
|
|
|
+ protected function makeJoinColumnAttributes(array $type, bool $inverse = false): array
|
|
|
+ {
|
|
|
$key = $inverse ? 'inverseJoinColumns' : 'joinColumns';
|
|
|
|
|
|
$definition = $type[$key] ?? $type['joinTable'][$key] ?? [];
|
|
|
@@ -528,7 +504,7 @@ class SchemaSnippetsMaker
|
|
|
foreach ($definition as $joinColDefinition) {
|
|
|
$options = [];
|
|
|
|
|
|
- if (isset($joinColDefinition['name']) && $joinColDefinition['name'] !== $type['fieldName'] . '_id') {
|
|
|
+ if (isset($joinColDefinition['name']) && $joinColDefinition['name'] !== $type['fieldName'].'_id') {
|
|
|
$options['name'] = $joinColDefinition['name'];
|
|
|
}
|
|
|
if (($joinColDefinition['unique'] ?? false) === true) {
|
|
|
@@ -562,42 +538,40 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Make the '__construct' method with collections initialization
|
|
|
+ * Make the '__construct' method with collections initialization.
|
|
|
+ *
|
|
|
* @param array<Property> $collections
|
|
|
- * @return Method
|
|
|
*/
|
|
|
- protected function makeSnippetConstructor(array $collections): Method {
|
|
|
+ protected function makeSnippetConstructor(array $collections): Method
|
|
|
+ {
|
|
|
$constructor = new Method('__construct');
|
|
|
$constructor->setPublic();
|
|
|
|
|
|
foreach ($collections as $collection) {
|
|
|
- $constructor->addBody('$this->' . $collection->getName() . ' = new ArrayCollection();');
|
|
|
+ $constructor->addBody('$this->'.$collection->getName().' = new ArrayCollection();');
|
|
|
}
|
|
|
|
|
|
return $constructor;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Make a 'getter' method for the given property
|
|
|
- *
|
|
|
- * @param Property $prop
|
|
|
- * @return Method
|
|
|
+ * Make a 'getter' method for the given property.
|
|
|
*/
|
|
|
- protected function makeSnippetGetterForProp(Property $prop): Method {
|
|
|
- $method = new Method('get' . ucfirst($prop->getName()));
|
|
|
+ protected function makeSnippetGetterForProp(Property $prop): Method
|
|
|
+ {
|
|
|
+ $method = new Method('get'.ucfirst($prop->getName()));
|
|
|
$method->setReturnType($prop->getType());
|
|
|
- $method->setBody('return $this->' . $prop->getName() . ';');
|
|
|
+ $method->setBody('return $this->'.$prop->getName().';');
|
|
|
+
|
|
|
return $method;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Make a 'setter' method for the given property
|
|
|
- *
|
|
|
- * @param Property $prop
|
|
|
- * @return Method
|
|
|
+ * Make a 'setter' method for the given property.
|
|
|
*/
|
|
|
- protected function makeSnippetSetterForProp(Property $prop): Method {
|
|
|
- $method = new Method('set' . ucfirst($prop->getName()));
|
|
|
+ protected function makeSnippetSetterForProp(Property $prop): Method
|
|
|
+ {
|
|
|
+ $method = new Method('set'.ucfirst($prop->getName()));
|
|
|
|
|
|
$parameter = new Parameter($prop->getName());
|
|
|
$parameter->setType($prop->getType());
|
|
|
@@ -608,11 +582,12 @@ class SchemaSnippetsMaker
|
|
|
implode(
|
|
|
"\n",
|
|
|
[
|
|
|
- '$this->' . $prop->getName() . ' = $' . $prop->getName() . ';',
|
|
|
+ '$this->'.$prop->getName().' = $'.$prop->getName().';',
|
|
|
'return $this;',
|
|
|
]
|
|
|
)
|
|
|
);
|
|
|
+
|
|
|
return $method;
|
|
|
}
|
|
|
|
|
|
@@ -624,8 +599,8 @@ class SchemaSnippetsMaker
|
|
|
|
|
|
foreach ($prop->getAttributes() as $attribute) {
|
|
|
if (
|
|
|
- $attribute instanceof Attribute &&
|
|
|
- ($attribute->getName() === OneToMany::class || $attribute->getName() === ManyToMany::class)
|
|
|
+ $attribute instanceof Attribute
|
|
|
+ && ($attribute->getName() === OneToMany::class || $attribute->getName() === ManyToMany::class)
|
|
|
) {
|
|
|
$targetEntityName = $attribute->getArguments()['targetEntity'];
|
|
|
if (!$targetEntityName) {
|
|
|
@@ -642,9 +617,11 @@ class SchemaSnippetsMaker
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return $targetEntityName;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -664,12 +641,12 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
if (!$relationAttr) {
|
|
|
- throw new \LogicException('Missing relation attribute for collection property ' . $prop->getName());
|
|
|
+ throw new \LogicException('Missing relation attribute for collection property '.$prop->getName());
|
|
|
}
|
|
|
|
|
|
$inversedBy = $relationAttr->getArguments()['inversedBy'] ?? $relationAttr->getArguments()['mappedBy'] ?? null;
|
|
|
if (!$inversedBy) {
|
|
|
- var_dump('Could not determine the inverse prop for collection property ' . $prop->getName());
|
|
|
+ var_dump('Could not determine the inverse prop for collection property '.$prop->getName());
|
|
|
$inversedBy = 'XXXX';
|
|
|
}
|
|
|
|
|
|
@@ -683,22 +660,19 @@ class SchemaSnippetsMaker
|
|
|
}
|
|
|
|
|
|
return
|
|
|
- $prefix .
|
|
|
- ucfirst($inversedBy) .
|
|
|
+ $prefix.
|
|
|
+ ucfirst($inversedBy).
|
|
|
(($prefix === 'set' && $isRemoving) ? '(null)' : '($this)');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Make an 'adder' method for the given property
|
|
|
- *
|
|
|
- * @param Property $prop
|
|
|
- * @return Method
|
|
|
+ * Make an 'adder' method for the given property.
|
|
|
*/
|
|
|
- protected function makeSnippetAdderForCollection(Property $prop): Method {
|
|
|
-
|
|
|
+ protected function makeSnippetAdderForCollection(Property $prop): Method
|
|
|
+ {
|
|
|
$singularPropName = $this->singularize($prop->getName());
|
|
|
|
|
|
- $method = new Method('add' . ucfirst($singularPropName));
|
|
|
+ $method = new Method('add'.ucfirst($singularPropName));
|
|
|
|
|
|
$targetEntityName = $this->getTargetEntityNameFromCollectionProp($prop);
|
|
|
|
|
|
@@ -712,26 +686,25 @@ class SchemaSnippetsMaker
|
|
|
$method->setBody(implode(
|
|
|
"\n",
|
|
|
[
|
|
|
- 'if (!$this->' . $prop->getName() . '->contains($' . $singularPropName . ')) {',
|
|
|
- ' $this->' . $prop->getName() . '[] = $' . $singularPropName . ';',
|
|
|
- ' $' . $singularPropName . '->' . $inverseSetterCall . ';',
|
|
|
+ 'if (!$this->'.$prop->getName().'->contains($'.$singularPropName.')) {',
|
|
|
+ ' $this->'.$prop->getName().'[] = $'.$singularPropName.';',
|
|
|
+ ' $'.$singularPropName.'->'.$inverseSetterCall.';',
|
|
|
'}',
|
|
|
'',
|
|
|
'return $this;',
|
|
|
]));
|
|
|
+
|
|
|
return $method;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Make a 'remover' method for the given property
|
|
|
- *
|
|
|
- * @param Property $prop
|
|
|
- * @return Method
|
|
|
+ * Make a 'remover' method for the given property.
|
|
|
*/
|
|
|
- protected function makeSnippetRemoverForCollection(Property $prop): Method {
|
|
|
+ protected function makeSnippetRemoverForCollection(Property $prop): Method
|
|
|
+ {
|
|
|
$singularPropName = $this->singularize($prop->getName());
|
|
|
|
|
|
- $method = new Method('remove' . ucfirst($singularPropName));
|
|
|
+ $method = new Method('remove'.ucfirst($singularPropName));
|
|
|
|
|
|
$targetEntityName = $this->getTargetEntityNameFromCollectionProp($prop);
|
|
|
|
|
|
@@ -746,29 +719,28 @@ class SchemaSnippetsMaker
|
|
|
implode(
|
|
|
"\n",
|
|
|
[
|
|
|
- 'if ($this->' . $prop->getName() . '->removeElement($' . $singularPropName . ')) {',
|
|
|
- ' $' . $singularPropName . '->' . $inverseSetterCall . ';',
|
|
|
+ 'if ($this->'.$prop->getName().'->removeElement($'.$singularPropName.')) {',
|
|
|
+ ' $'.$singularPropName.'->'.$inverseSetterCall.';',
|
|
|
'}',
|
|
|
'',
|
|
|
'return $this;',
|
|
|
]
|
|
|
)
|
|
|
);
|
|
|
+
|
|
|
return $method;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Perform some post-fixes on the file content
|
|
|
- *
|
|
|
- * @param string $content
|
|
|
- * @return string
|
|
|
+ * Perform some post-fixes on the file content.
|
|
|
*/
|
|
|
protected function postProcessFileContent(string $content): string
|
|
|
{
|
|
|
- return preg_replace("/targetEntity: '(\w+)::class'/", "targetEntity: $1::class", $content);
|
|
|
+ return preg_replace("/targetEntity: '(\w+)::class'/", 'targetEntity: $1::class', $content);
|
|
|
}
|
|
|
|
|
|
- protected function singularize(string $name): string {
|
|
|
+ protected function singularize(string $name): string
|
|
|
+ {
|
|
|
$exceptions = ['access'];
|
|
|
if (in_array(strtolower($name), $exceptions)) {
|
|
|
return $name;
|