Skip to content

Commit

Permalink
[TASK] Cleanup doc comments and use type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschaufi committed May 26, 2021
1 parent 8cac1b0 commit 38be428
Show file tree
Hide file tree
Showing 31 changed files with 153 additions and 524 deletions.
38 changes: 11 additions & 27 deletions Classes/Configuration/ExtensionBuilderConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ public function getExtensionBuilderSettings(): array
return GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extension_builder');
}

/**
* @param string $extensionKey
* @param string $extensionStoragePath
* @return array settings
*/
public function getExtensionSettings(string $extensionKey, string $extensionStoragePath): array
{
$settings = [];
Expand Down Expand Up @@ -180,12 +175,7 @@ public function getExtensionBuilderConfiguration(string $extensionKey, ?string $
return $result;
}

/**
* @param string $extensionKey
* @param string|null $storagePath
* @return mixed|null
*/
public static function getExtensionBuilderJson($extensionKey, $storagePath = null)
public static function getExtensionBuilderJson(string $extensionKey, ?string $storagePath = null)
{
$storagePath = $storagePath ?? Environment::getPublicPath() . '/typo3conf/ext/';
$jsonFile = $storagePath . $extensionKey . '/' . self::EXTENSION_BUILDER_SETTINGS_FILE;
Expand All @@ -201,7 +191,7 @@ public static function getExtensionBuilderJson($extensionKey, $storagePath = nul
* @return string
* @throws \TYPO3\CMS\Extbase\Object\Exception
*/
public function getPersistenceTable(string $className)
public function getPersistenceTable(string $className): string
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
return $objectManager->get(DataMapper::class)->getDataMap($className)->getTableName();
Expand Down Expand Up @@ -429,11 +419,15 @@ protected function reArrangeRelations(array $jsonConfig): array
* @param int $uid
* @param array $modules
* @param int $supposedModuleIndex
* @param int $supposedRelationIndex
* @param int|null $supposedRelationIndex
* @return array
*/
protected function findModuleIndexByRelationUid($uid, $modules, $supposedModuleIndex, $supposedRelationIndex = null)
{
protected function findModuleIndexByRelationUid(
int $uid,
array $modules,
int $supposedModuleIndex,
?int $supposedRelationIndex = null
): array {
$result = [
'moduleId' => $supposedModuleIndex
];
Expand Down Expand Up @@ -473,12 +467,7 @@ protected function findModuleIndexByRelationUid($uid, $modules, $supposedModuleI
return $result;
}

/**
* @param Extension $extension
*
* @return string
*/
public function getParentClassForValueObject(Extension $extension)
public function getParentClassForValueObject(Extension $extension): string
{
$settings = $this->getExtensionSettings($extension->getExtensionKey(), $extension->getStoragePath());
if (isset($settings['classBuilder']['Model']['AbstractValueObject']['parentClass'])) {
Expand All @@ -488,12 +477,7 @@ public function getParentClassForValueObject(Extension $extension)
return '\\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject';
}

/**
* @param Extension $extension
*
* @return string
*/
public function getParentClassForEntityObject(Extension $extension)
public function getParentClassForEntityObject(Extension $extension): string
{
$settings = $this->getExtensionSettings($extension->getExtensionKey(), $extension->getStoragePath());
if (isset($settings['classBuilder']['Model']['AbstractEntity']['parentClass'])) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/BuilderModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ protected function rpcActionSave(): array
}
if (!empty($validationConfigurationResult['errors'])) {
$errorMessage = '';
/** @var \Exception $exception */
foreach ($validationConfigurationResult['errors'] as $exception) {
/** @var \Exception $exception */
$errorMessage .= '<br />' . $exception->getMessage();
}
throw new \Exception($errorMessage);
Expand Down
57 changes: 13 additions & 44 deletions Classes/Domain/Model/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use EBT\ExtensionBuilder\Exception\SyntaxError;
use EBT\ExtensionBuilder\Parser\Utility\NodeConverter;
use InvalidArgumentException;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -49,7 +50,7 @@ abstract class AbstractObject
'final' => Class_::MODIFIER_FINAL
];
/**
* @var string|\PhpParser\Node\Identifier
* @var string|Identifier
*/
protected $name = '';

Expand Down Expand Up @@ -96,12 +97,6 @@ abstract class AbstractObject
*/
protected $isModified = false;

/**
* Setter for name
*
* @param string $name name
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
Expand All @@ -111,7 +106,7 @@ public function setName(string $name): self
/**
* Getter for name
*
* @return string|\PhpParser\Node\Identifier name
* @return string|Identifier
*/
public function getName()
{
Expand Down Expand Up @@ -145,9 +140,6 @@ public function getTags(): array
return $this->tags;
}

/**
* @return bool
*/
public function hasTags(): bool
{
return count($this->getTags()) > 0;
Expand All @@ -159,7 +151,7 @@ public function hasTags(): bool
*
* @return $this;
*/
public function setTags($tags): self
public function setTags(array $tags): self
{
$this->tags = $tags;
return $this;
Expand Down Expand Up @@ -238,7 +230,7 @@ public function getTagValue(string $tagName): string
*
* @return array
*/
public function getAnnotations()
public function getAnnotations(): array
{
$annotations = [];
$tags = $this->getTags();
Expand Down Expand Up @@ -302,9 +294,6 @@ public function setDescription(string $description): self
return $this;
}

/**
* @return bool true if the description isn't empty
*/
public function hasDescription(): bool
{
return !empty($this->description);
Expand All @@ -329,8 +318,8 @@ public function setModifiers(int $modifiers): self
* @param string $modifierName
*
* @return $this (for fluid interface)
* @throws \EBT\ExtensionBuilder\Exception\FileNotFoundException
* @throws \EBT\ExtensionBuilder\Exception\SyntaxError
* @throws FileNotFoundException
* @throws SyntaxError
*/
public function addModifier(string $modifierName): self
{
Expand All @@ -349,8 +338,8 @@ public function addModifier(string $modifierName): self
* @param string $modifierName
*
* @return $this (for fluid interface)
* @throws \EBT\ExtensionBuilder\Exception\FileNotFoundException
* @throws \EBT\ExtensionBuilder\Exception\SyntaxError
* @throws FileNotFoundException
* @throws SyntaxError
*/
public function setModifier(string $modifierName): self
{
Expand All @@ -371,40 +360,23 @@ public function setModifier(string $modifierName): self
return $this;
}

/**
* @param string $modifierName
* @return $this (for fluid interface)
*/
public function removeModifier(string $modifierName): self
{
$this->modifiers ^= $this->mapModifierNames[$modifierName];
return $this;
}

/**
* @return $this (for fluid interface)
*/
public function removeAllModifiers(): self
{
$this->modifiers = 0;
return $this;
}

/**
* Getter for modifiers
*
* @return int
*/
public function getModifiers(): int
{
return $this->modifiers;
}

/**
* getModifierNames
*
* @return array
*/
public function getModifierNames(): array
{
$modifiers = $this->getModifiers();
Expand All @@ -415,10 +387,10 @@ public function getModifierNames(): array
* validate if the modifier can be added to the current modifiers or not
*
* @param int $modifier
* @throws \EBT\ExtensionBuilder\Exception\FileNotFoundException
* @throws \EBT\ExtensionBuilder\Exception\SyntaxError
* @throws FileNotFoundException
* @throws SyntaxError
*/
protected function validateModifier($modifier): void
protected function validateModifier(int $modifier): void
{
if (($modifier == Class_::MODIFIER_FINAL && $this->isAbstract())
|| ($modifier == Class_::MODIFIER_ABSTRACT && $this->isFinal())
Expand Down Expand Up @@ -486,7 +458,7 @@ public function setDocComment(string $docComment): void
*
* @param string $line A line of a doc comment which starts with an @-sign
*/
protected function parseTag($line): void
protected function parseTag(string $line): void
{
$tagAndValue = [];
if (preg_match('/@([A-Za-z0-9\\\-]+)(\(.*\))? ?(.*)/', $line, $tagAndValue) === 0) {
Expand Down Expand Up @@ -567,9 +539,6 @@ public function hasDocComment(): bool
return !empty($this->docComment);
}

/**
* @param string $commentText
*/
public function addComment(string $commentText): void
{
// parsed comments have no line at the end
Expand Down
39 changes: 6 additions & 33 deletions Classes/Domain/Model/ClassObject/ClassObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use EBT\ExtensionBuilder\Domain\Model\Container;
use PhpParser\Node;
use PhpParser\Node\Stmt\TraitUse;

/**
* Class schema representing a "PHP class" in the context of software development
Expand Down Expand Up @@ -89,10 +90,7 @@ class ClassObject extends Container
*/
protected $isTemplate = false;

/**
* @param string $name
*/
public function __construct($name)
public function __construct(string $name)
{
$this->name = $name;
}
Expand Down Expand Up @@ -255,9 +253,6 @@ public function getProperty(string $propertyName): ?Property
return null;
}

/**
* @param array $properties
*/
public function setProperties(array $properties): void
{
$this->properties = $properties;
Expand All @@ -271,10 +266,6 @@ public function getProperties(): array
return $this->properties;
}

/**
* @param string $propertyName
* @return bool true if successfully removed
*/
public function removeProperty(string $propertyName): bool
{
if ($this->propertyExists($propertyName)) {
Expand Down Expand Up @@ -309,10 +300,6 @@ public function propertyExists(string $propertyName): bool
return is_array($this->methods) && in_array($propertyName, $this->getPropertyNames(), true);
}

/**
* @param Property $classProperty
* @return bool true if successfully added
*/
public function addProperty(Property $classProperty): bool
{
if (!$this->propertyExists($classProperty->getName())) {
Expand Down Expand Up @@ -387,7 +374,7 @@ public function getInfo(): array
}

/**
* @param $alias
* @param string $alias
*/
public function addAliasDeclaration($alias): void
{
Expand All @@ -396,25 +383,14 @@ public function addAliasDeclaration($alias): void
}
}

/**
* @return array
*/
public function getAliasDeclarations()
{
return $this->aliasDeclarations;
}

public function addUseTraitStatement(string $statement): void
public function addUseTraitStatement(TraitUse $statement): void
{
if (!in_array($statement, $this->useTraitStatements)) {
$this->useTraitStatements[] = $statement;
}
}

/**
* @return array
*/
public function getUseTraitStatement()
public function getUseTraitStatement(): array
{
return $this->useTraitStatements;
}
Expand Down Expand Up @@ -442,10 +418,7 @@ public function hasInterface(string $interfaceName): bool
return in_array($interfaceName, $this->interfaceNames);
}

/**
* @param $interfaceNameToRemove
*/
public function removeInterface($interfaceNameToRemove): void
public function removeInterface(string $interfaceNameToRemove): void
{
$interfaceNames = [];
foreach ($this->interfaceNames as $interfaceName) {
Expand Down
6 changes: 0 additions & 6 deletions Classes/Domain/Model/ClassObject/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,11 @@ public function __construct($text, $line = -1)
$this->line = $line;
}

/**
* @param string $text
*/
public function setText(string $text): void
{
$this->text = $text;
}

/**
* @return string
*/
public function getText(): string
{
return $this->text;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/ClassObject/DocComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(string $text)
*
* @param string $docComment
*/
public function initialize($docComment): void
public function initialize(string $docComment): void
{
$lines = explode(chr(10), $docComment);
foreach ($lines as $line) {
Expand Down
Loading

0 comments on commit 38be428

Please sign in to comment.