Skip to content

Commit

Permalink
improve memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
jBernavaPrah committed Jun 5, 2022
1 parent e51a54f commit 686d4b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Errors/ValidationError.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ValidationError extends Error

public static function definition(): string
{
$codes = implode("\n\n", app(GenerateValidationCodeEnum::class)->generate());
$codes = implode("\n\n", app(GenerateValidationCodeEnum::class)->generate());

return /** @lang GraphQL */ <<<GRAPHQL
Expand Down
33 changes: 19 additions & 14 deletions src/GenerateValidationCodeEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,38 @@

class GenerateValidationCodeEnum
{

protected array $codes = [];

/**
* @return array
*/
public function generate(): array
{
$codes = [];
foreach ((new ReflectionClass(Validator::class))->getMethods() as $reflectionMethod) {
if (
$reflectionMethod->getShortName() === "validated" ||
! Str::of($reflectionMethod->getShortName())->startsWith('validate') ||
!($code = $this->validationCodeString($reflectionMethod->getShortName()))
) {
continue;
}

$description = (new PhpdocParser(new TagSet([new Summery()])))->parse($reflectionMethod->getDocComment())['description'];


$codes[] = <<<GRAPHQL
if (!$this->codes) {
foreach ((new ReflectionClass(Validator::class))->getMethods() as $reflectionMethod) {
if (
$reflectionMethod->getShortName() === "validated" ||
!Str::of($reflectionMethod->getShortName())->startsWith('validate') ||
!($code = $this->validationCodeString($reflectionMethod->getShortName()))
) {
continue;
}

$description = (new PhpdocParser(new TagSet([new Summery()])))->parse($reflectionMethod->getDocComment())['description'];
$this->codes[] = <<<GRAPHQL
"""
$description
"""
$code
GRAPHQL;
}

}

return $codes;

return $this->codes;
}

/**
Expand Down

0 comments on commit 686d4b6

Please sign in to comment.