Skip to content

Commit a4d42c4

Browse files
committed
better docs
1 parent 0ad9e99 commit a4d42c4

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

src/Util/ClassNameDetails.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public function getRelativeNameWithoutSuffix(): string
5555
return Str::removeSuffix($this->getRelativeName(), $this->suffix);
5656
}
5757

58+
/**
59+
* Returns the Short Name of the class with the substitute prefix.
60+
*
61+
* E.g. \Doctrine\ORM\Mapping\Column::class and the substitutePrefix = ORM,
62+
* the ORM\Column will be returned.
63+
*/
5864
public function getShortNameWithSubstitutePrefix(): string
5965
{
6066
return sprintf('%s\\%s', $this->substitutePrefix, $this->getShortName());

src/Util/ClassSourceManipulator.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,6 @@ public function addProperty(string $name, array $annotationLines = [], $defaultV
352352

353353
$newPropertyBuilder = (new Builder\Property($name))->makePrivate();
354354

355-
// if ($annotationLines && $this->useAnnotations) {
356-
// $newPropertyBuilder->setDocComment($this->createDocBlock($annotationLines));
357-
// }
358-
359355
if ($this->useAttributesForDoctrineMapping) {
360356
foreach ($attributes as $attribute) {
361357
$newPropertyBuilder->addAttribute($attribute);
@@ -929,6 +925,31 @@ public function addUseStatementIfNecessary(string $class): string
929925
return $shortClassName;
930926
}
931927

928+
/**
929+
* Builds a PHPParser attribute node.
930+
*
931+
* @param ClassNameDetails $attributeClass The attribute class which should be used for the attribute. If the class has a substitute
932+
* prefix, the node is built using the prefix. E.g. #[ORM\Column()] Otherwise, the
933+
* short name is used. E.g. #[Column()]
934+
* @param array $options the named arguments for the attribute ($key = argument name, $value = argument value)
935+
*/
936+
public function buildAttributeNode(ClassNameDetails $attributeClass, array $options): Node\Attribute
937+
{
938+
$options = $this->sortOptionsByClassConstructorParameters($options, $attributeClass->getFullName());
939+
940+
$context = $this;
941+
$nodeArguments = array_map(static function ($option, $value) use ($context) {
942+
return new Node\Arg($context->buildNodeExprByValue($value), false, false, [], new Node\Identifier($option));
943+
}, array_keys($options), array_values($options));
944+
945+
$class = $attributeClass->hasSubstitutePrefix() ? $attributeClass->getShortNameWithSubstitutePrefix() : $attributeClass->getShortName();
946+
947+
return new Node\Attribute(
948+
new Node\Name($class),
949+
$nodeArguments
950+
);
951+
}
952+
932953
private function updateSourceCodeFromNewStmts(): void
933954
{
934955
$newCode = $this->printer->printFormatPreserving(
@@ -1450,29 +1471,6 @@ private function buildNodeExprByValue($value): Node\Expr
14501471
return $nodeValue;
14511472
}
14521473

1453-
/**
1454-
* builds an PHPParser attribute node.
1455-
*
1456-
* @param ClassNameDetails $attributeClass the attribute class which should be used for the attribute
1457-
* @param array $options the named arguments for the attribute ($key = argument name, $value = argument value)
1458-
*/
1459-
public function buildAttributeNode(ClassNameDetails $attributeClass, array $options): Node\Attribute
1460-
{
1461-
$options = $this->sortOptionsByClassConstructorParameters($options, $attributeClass->getFullName());
1462-
1463-
$context = $this;
1464-
$nodeArguments = array_map(static function ($option, $value) use ($context) {
1465-
return new Node\Arg($context->buildNodeExprByValue($value), false, false, [], new Node\Identifier($option));
1466-
}, array_keys($options), array_values($options));
1467-
1468-
$class = $attributeClass->hasSubstitutePrefix() ? $attributeClass->getShortNameWithSubstitutePrefix() : $attributeClass->getShortName();
1469-
1470-
return new Node\Attribute(
1471-
new Node\Name($class),
1472-
$nodeArguments
1473-
);
1474-
}
1475-
14761474
/**
14771475
* sort the given options based on the constructor parameters for the given $classString
14781476
* this prevents code inspections warnings for IDEs like intellij/phpstorm.

0 commit comments

Comments
 (0)