Skip to content

Commit

Permalink
Fix incorrect method name
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienClairembault authored and trasher committed Dec 4, 2024
1 parent d8a9111 commit 92bb3bb
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 31 deletions.
12 changes: 0 additions & 12 deletions .phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -3007,12 +3007,6 @@
'count' => 1,
'path' => __DIR__ . '/src/Glpi/Form/Form.php',
];
$ignoreErrors[] = [
'message' => '#^Return type \\(array\\<Glpi\\\\Form\\\\Comment\\>\\) of method Glpi\\\\Form\\\\Form\\:\\:getComments\\(\\) should be compatible with return type \\(string\\) of method CommonDBTM\\:\\:getComments\\(\\)$#',
'identifier' => 'method.childReturnType',
'count' => 1,
'path' => __DIR__ . '/src/Glpi/Form/Form.php',
];
$ignoreErrors[] = [
'message' => '#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#',
'identifier' => 'function.alreadyNarrowedType',
Expand Down Expand Up @@ -3061,12 +3055,6 @@
'count' => 1,
'path' => __DIR__ . '/src/Glpi/Form/QuestionType/QuestionTypesManager.php',
];
$ignoreErrors[] = [
'message' => '#^Return type \\(array\\<Glpi\\\\Form\\\\Comment\\>\\) of method Glpi\\\\Form\\\\Section\\:\\:getComments\\(\\) should be compatible with return type \\(string\\) of method CommonDBTM\\:\\:getComments\\(\\)$#',
'identifier' => 'method.childReturnType',
'count' => 1,
'path' => __DIR__ . '/src/Glpi/Form/Section.php',
];
$ignoreErrors[] = [
'message' => '#^Method Glpi\\\\Form\\\\ServiceCatalog\\\\ServiceCatalog\\:\\:getTabNameForItem\\(\\) never returns array\\<string\\> so it can be removed from the return type\\.$#',
'identifier' => 'return.unusedType',
Expand Down
2 changes: 1 addition & 1 deletion phpunit/functional/Glpi/Form/Export/FormSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function testExportAndImportComments(): void
$form_copy = $this->exportAndImportForm($form);

// Assert: validate comments fields
$comments = array_values($form_copy->getComments());
$comments = array_values($form_copy->getFormComments());
$comments_data = array_map(function (Comment $comment) {
return [
'name' => $comment->fields['name'],
Expand Down
12 changes: 6 additions & 6 deletions phpunit/functional/Glpi/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ public function testPost_getFromDB(): void
);
$this->assertCount(2, $form->getSections());
$this->assertCount(3, $form->getQuestions());
$this->assertCount(2, $form->getComments());
$this->assertCount(2, $form->getFormComments());

// Delete content
foreach ($form->getSections() as $section) {
foreach ($section->getQuestions() as $question) {
$this->deleteItem(Question::class, $question->getID());
}
foreach ($section->getComments() as $comment) {
foreach ($section->getFormComments() as $comment) {
$this->deleteItem(Comment::class, $comment->getID());
}
$this->deleteItem(Section::class, $section->getID());
Expand All @@ -184,13 +184,13 @@ public function testPost_getFromDB(): void
// shouldn't change
$this->assertCount(2, $form->getSections());
$this->assertCount(3, $form->getQuestions());
$this->assertCount(2, $form->getComments());
$this->assertCount(2, $form->getFormComments());

// Reload form
$form->getFromDB($form->getID());
$this->assertCount(0, $form->getSections());
$this->assertCount(0, $form->getQuestions());
$this->assertCount(0, $form->getComments());
$this->assertCount(0, $form->getFormComments());
}

/**
Expand Down Expand Up @@ -269,7 +269,7 @@ public function testPrepareInputForUpdate(): void
],
]);
$this->assertCount(1, $form->getQuestions());
$this->assertCount(1, $form->getComments());
$this->assertCount(1, $form->getFormComments());

$id = $form->getID();
$this->hasSessionMessages(INFO, ['Item successfully updated: <a href="/glpi/front/form/form.form.php?id=' . $id . '" title="Form with first section">Form with first section</a>']);
Expand Down Expand Up @@ -360,7 +360,7 @@ private function checkGetComments(
array $expected_comment_names,
array $expected_comment_descriptions
): void {
$comments = $form->getComments();
$comments = $form->getFormComments();
$names = array_map(fn($comment) => $comment->getName(), $comments);
$names = array_values($names); // Strip keys
$this->assertEquals($expected_comment_names, $names);
Expand Down
2 changes: 1 addition & 1 deletion src/Glpi/Form/Export/Serializer/FormSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private function exportComments(
Form $form,
FormContentSpecification $form_spec,
): FormContentSpecification {
foreach ($form->getComments() as $comment) {
foreach ($form->getFormComments() as $comment) {
$comment_spec = new CommentContentSpecification();
$comment_spec->name = $comment->fields['name'];
$comment_spec->rank = $comment->fields['rank'];
Expand Down
4 changes: 2 additions & 2 deletions src/Glpi/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@ public function getQuestions(): array
*
* @return Comment[]
*/
public function getComments(): array
public function getFormComments(): array
{
$comments = [];
foreach ($this->getSections() as $section) {
// Its important to use the "+" operator here and not array_merge
// because the keys must be preserved
$comments = $comments + $section->getComments();
$comments = $comments + $section->getFormComments();
}
return $comments;
}
Expand Down
9 changes: 3 additions & 6 deletions src/Glpi/Form/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class Section extends CommonDBChild

/**
* Lazy loaded array of comments
* Should always be accessed through getComments()
* Should always be accessed through getFormComments()
* @var Comment[]|null
*/
protected ?array $comments = null;
Expand Down Expand Up @@ -93,7 +93,7 @@ public function cleanDBonPurge()
*/
public function getBlocks(): array
{
$blocks = array_merge($this->getQuestions(), $this->getComments());
$blocks = array_merge($this->getQuestions(), $this->getFormComments());
usort($blocks, fn($a, $b) => $a->fields['rank'] <=> $b->fields['rank']);

return $blocks;
Expand Down Expand Up @@ -137,11 +137,8 @@ public function getQuestions(): array
*
* @return Comment[]
*/
public function getComments(): array
public function getFormComments(): array
{
// TODO: getComments is already a method part of the CommonDBTM interface.
// We need another name for this.

// Lazy loading
if ($this->comments === null) {
$this->comments = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Glpi/Form/Tag/CommentDescriptionTagProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getTagColor(): string
public function getTags(Form $form): array
{
$tags = [];
foreach ($form->getComments() as $comment) {
foreach ($form->getFormComments() as $comment) {
$tags[] = $this->getDescriptionTagForComment($comment);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Glpi/Form/Tag/CommentTitleTagProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getTagColor(): string
public function getTags(Form $form): array
{
$tags = [];
foreach ($form->getComments() as $comment) {
foreach ($form->getFormComments() as $comment) {
$tags[] = $this->getTitleTagForComment($comment);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/FormTesterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ protected function getCommentId(
$form->getFromDB($form->getID());

// Get comments
$comments = $form->getComments();
$comments = $form->getFormComments();

if ($section_name === null) {
// Search by name
Expand Down

0 comments on commit 92bb3bb

Please sign in to comment.