Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Dec 8, 2023
1 parent 5f435c2 commit 0a737f3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
20 changes: 0 additions & 20 deletions src/Command/Acsf/AcsfApiBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Acquia\Cli\Command\Api\ApiBaseCommand;
use Acquia\Cli\Exception\AcquiaCliException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;

#[AsCommand(name: 'acsf:base')]
class AcsfApiBaseCommand extends ApiBaseCommand {
Expand All @@ -19,23 +18,4 @@ protected function checkAuthentication(): void {
}
}

/**
* @todo Remove this method when CLI-791 is resolved.
*/
protected function getRequestPath(InputInterface $input): string {
$path = $this->path;

$arguments = $input->getArguments();
// The command itself is the first argument. Remove it.
array_shift($arguments);
foreach ($arguments as $key => $value) {
$token = '%' . $key;
if (str_contains($path, $token)) {
return str_replace($token, $value, $path);
}
}

return parent::getRequestPath($input);
}

}
7 changes: 3 additions & 4 deletions src/Command/Api/ApiBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ private function castParamType(array $paramSpec, array|string|bool|int $value):
}
$types[] = $type['type'];
}
$isInt = (in_array('integer', $types, TRUE) || in_array('int', $types, TRUE));
if ($isInt && ctype_digit($value)) {
if (in_array('integer', $types, TRUE) && ctype_digit($value)) {

Check warning on line 190 in src/Command/Api/ApiBaseCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ } $types[] = $type['type']; } - if (in_array('integer', $types, TRUE) && ctype_digit($value)) { + if (in_array('integer', $types, TRUE) || ctype_digit($value)) { return $this->doCastParamType('integer', $value); } } elseif ($paramSpec['type'] === 'array') {

Check warning on line 190 in src/Command/Api/ApiBaseCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndNegation": --- Original +++ New @@ @@ } $types[] = $type['type']; } - if (in_array('integer', $types, TRUE) && ctype_digit($value)) { + if (!(in_array('integer', $types, TRUE) && ctype_digit($value))) { return $this->doCastParamType('integer', $value); } } elseif ($paramSpec['type'] === 'array') {

Check warning on line 190 in src/Command/Api/ApiBaseCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": --- Original +++ New @@ @@ } $types[] = $type['type']; } - if (in_array('integer', $types, TRUE) && ctype_digit($value)) { + if (!in_array('integer', $types, TRUE) && ctype_digit($value)) { return $this->doCastParamType('integer', $value); } } elseif ($paramSpec['type'] === 'array') {

Check warning on line 190 in src/Command/Api/ApiBaseCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndAllSubExprNegation": --- Original +++ New @@ @@ } $types[] = $type['type']; } - if (in_array('integer', $types, TRUE) && ctype_digit($value)) { + if (!in_array('integer', $types, TRUE) && !ctype_digit($value)) { return $this->doCastParamType('integer', $value); } } elseif ($paramSpec['type'] === 'array') {

Check warning on line 190 in src/Command/Api/ApiBaseCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": --- Original +++ New @@ @@ } $types[] = $type['type']; } - if (in_array('integer', $types, TRUE) && ctype_digit($value)) { + if (in_array('integer', $types, TRUE) && !ctype_digit($value)) { return $this->doCastParamType('integer', $value); } } elseif ($paramSpec['type'] === 'array') {
return $this->doCastParamType('integer', $value);
}
}
Expand All @@ -210,8 +209,8 @@ private function castParamType(array $paramSpec, array|string|bool|int $value):

private function doCastParamType(string $type, mixed $value): array|bool|int|string|object {
return match ($type) {

Check warning on line 211 in src/Command/Api/ApiBaseCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "MatchArmRemoval": --- Original +++ New @@ @@ 'array' => is_string($value) ? explode(',', $value) : (array) $value, 'string' => (string) $value, 'object' => json_decode($value, FALSE, 512, JSON_THROW_ON_ERROR), - 'mixed' => $value, }; } public function castBool(mixed $val) : bool
'int', 'integer' => (int) $value,
'bool', 'boolean' => $this->castBool($value),
'integer' => (int) $value,
'boolean' => $this->castBool($value),
'array' => is_string($value) ? explode(',', $value) : (array) $value,
'string' => (string) $value,
'object' => json_decode($value, FALSE, 512, JSON_THROW_ON_ERROR),

Check warning on line 216 in src/Command/Api/ApiBaseCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ 'boolean' => $this->castBool($value), 'array' => is_string($value) ? explode(',', $value) : (array) $value, 'string' => (string) $value, - 'object' => json_decode($value, FALSE, 512, JSON_THROW_ON_ERROR), + 'object' => json_decode($value, FALSE, 511, JSON_THROW_ON_ERROR), 'mixed' => $value, }; }
Expand Down
8 changes: 3 additions & 5 deletions tests/phpunit/src/Commands/Api/ApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,20 @@ public function testArgumentsInteractionValidation(): void {
'AH_SOMETHING',
]);
}
catch (MissingInputException $exception) {

catch (MissingInputException) {
}
$output = $this->getDisplay();
$this->assertStringContainsString('It must match the pattern', $output);
}

public function testArgumentsInteractionValdationFormat(): void {
public function testArgumentsInteractionValidationFormat(): void {
$this->command = $this->getApiCommandByName('api:notifications:find');
try {
$this->executeCommand([], [
'test',
]);
}
catch (MissingInputException $exception) {

catch (MissingInputException) {
}
$output = $this->getDisplay();
$this->assertStringContainsString('This is not a valid UUID', $output);
Expand Down

0 comments on commit 0a737f3

Please sign in to comment.