Skip to content

Commit

Permalink
chore: use named RegEx group
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed Sep 9, 2024
1 parent b839acb commit f107c33
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function handleEnablingCoverage(array &$arguments): void
private function handleMinCoverage(array &$arguments): void
{
$coverageMinRegex = /** @lang RegExp */
'/^--gql-min=(\d+)$/';
'/^--gql-min=(?<value>\d+)$/';
$min = preg_grep($coverageMinRegex, $arguments);

if ($min === false || count($min) === 0) {
Expand All @@ -84,17 +84,17 @@ private function handleMinCoverage(array &$arguments): void

preg_match($coverageMinRegex, array_pop($min), $matches);

if (! isset($matches[1])) {
if (! isset($matches['value'])) {
return;
}

$this->coverageMin = (int) $matches[1];
$this->coverageMin = (int) $matches['value'];
}

private function handleSchemaCommand(array &$arguments): void
{
$schemaCommandRegex = /** @lang RegExp */
'/^--schema-command=(.*)$/';
'/^--schema-command=(?<value>.*)$/';
$command = preg_grep($schemaCommandRegex, $arguments);

if ($command === false || count($command) === 0) {
Expand All @@ -105,17 +105,17 @@ private function handleSchemaCommand(array &$arguments): void

preg_match($schemaCommandRegex, array_pop($command), $matches);

if (! isset($matches[1])) {
if (! isset($matches['value'])) {
return;
}

$this->schemaCommand = $matches[1];
$this->schemaCommand = $matches['value'];
}

private function handleMaxUntestedFields(array &$arguments): void
{
$maxUntestedFieldsRegex = /** @lang RegExp */
'/^--gql-untested-count=(.*)$/';
'/^--gql-untested-count=(?<value>.*)$/';
$command = preg_grep($maxUntestedFieldsRegex, $arguments);

if ($command === false || count($command) === 0) {
Expand All @@ -126,11 +126,13 @@ private function handleMaxUntestedFields(array &$arguments): void

preg_match($maxUntestedFieldsRegex, array_pop($command), $matches);

if (! isset($matches[1])) {
if (! isset($matches['value'])) {
return;
}

$this->maxUntestedFieldsCount = is_numeric($matches[1]) ? (int) $matches[1] : $this->maxUntestedFieldsCount;
$this->maxUntestedFieldsCount = is_numeric($matches['value'])
? (int) $matches['value']
: $this->maxUntestedFieldsCount;
}

public function addOutput(int $exitCode): int
Expand Down

0 comments on commit f107c33

Please sign in to comment.