Skip to content

Commit

Permalink
Handle void return type in custom collection's methods
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Dec 20, 2020
1 parent d8be1b9 commit 9b97d26
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ private function generateMethod(ReflectionMethod $method) : string
$parametersString = $this->buildParametersString($method);
$callParamsString = implode(', ', $this->getParameterNamesForDecoratedCall($method->getParameters()));

$return = 'return ';
if ($method->getReturnType() !== null && $this->formatType($method->getReturnType(), $method) === 'void') {
$return = '';
}

return <<<CODE
/**
Expand All @@ -201,7 +206,7 @@ public function {$method->name}($parametersString){$this->getMethodReturnType($m
if (\$this->needsSchedulingForSynchronization()) {
\$this->changed();
}
return \$this->coll->{$method->name}($callParamsString);
{$return}\$this->coll->{$method->name}($callParamsString);
}
CODE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ public function testModifyingCollectionInChangeTrackingNotifyDocument()
$this->assertEquals($f2->getId(), $profile->getImages()[0]->getId());
$this->assertEquals($f1->getId(), $profile->getImages()[1]->getId());
}

/**
* @doesNotPerformAssertions
*/
public function testMethodWithVoidReturnType()
{
$d = new DocumentWithCustomCollection();
$this->dm->persist($d);
$this->dm->flush();

$d = $this->dm->find(get_class($d), $d->id);
$d->coll->nothingReally();
}
}

/**
Expand Down Expand Up @@ -260,6 +273,11 @@ public function move($i, $j)
$this->set($i, $this->get($j));
$this->set($j, $tmp);
}

public function nothingReally(): void
{

}
}

class MyDocumentsCollection extends ArrayCollection
Expand Down

0 comments on commit 9b97d26

Please sign in to comment.