Skip to content

Commit

Permalink
php-csifxer native_function_invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
wickedOne committed Aug 16, 2024
1 parent e4a86ea commit ad5d192
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/Command/AbstractPhraseKeyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function list(OutputInterface $output, ?string $key, array $tags): int
try {
$result = $this->tagService->list($key, $tags);
} catch (ProviderException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
$output->writeln(\sprintf('<error>%s</error>', $e->getMessage()));

return Command::FAILURE;
}
Expand All @@ -91,7 +91,7 @@ private function list(OutputInterface $output, ?string $key, array $tags): int
$output->writeln('<info>your query would match the following keys (sample):</info>');

foreach ($result as $item) {
$output->writeln(sprintf('<comment>></comment> <info>%s</info>', $item));
$output->writeln(\sprintf('<comment>></comment> <info>%s</info>', $item));
}

return Command::SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions src/Command/PhraseKeyTagCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
try {
$keys = $this->tagService->tag($queryKey, $queryTag, $tag);
} catch (ProviderException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
$output->writeln(\sprintf('<error>%s</error>', $e->getMessage()));

return Command::FAILURE;
}

$output->writeln(sprintf('<info>successfully tagged %d keys with "%s"</info>', $keys, implode(', ', $tag)));
$output->writeln(sprintf('<info>successfully tagged %d keys with "%s"</info>', $keys, \implode(', ', $tag)));

return Command::SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/PhraseKeyUntagCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
return Command::FAILURE;
}

$output->writeln(sprintf('<info>successfully untagged %d keys with "%s"</info>', $keys, implode(', ', $tag)));
$output->writeln(\sprintf('<info>successfully untagged %d keys with "%s"</info>', $keys, \implode(', ', $tag)));

return Command::SUCCESS;
}
Expand Down
20 changes: 10 additions & 10 deletions src/Service/PhraseTagService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public function list(?string $key, array $tags): array
]);

if (200 !== $statusCode = $response->getStatusCode()) {
throw new ProviderException(sprintf('phrase replied with an error (%d): "%s"', $statusCode, $response->getContent(false)), $response);
throw new ProviderException(\sprintf('phrase replied with an error (%d): "%s"', $statusCode, $response->getContent(false)), $response);
}

/** @var array{name: string} $arr */
$arr = $response->toArray();

return array_column($arr, 'name');
return \array_column($arr, 'name');
}

/**
Expand All @@ -66,19 +66,19 @@ public function tag(?string $key, array $tags, array $addTags): int
],
'body' => [
'q' => $query,
'tags' => implode(',', $addTags),
'tags' => \implode(',', $addTags),
],
]);

if (200 !== $statusCode = $response->getStatusCode()) {
throw new ProviderException(sprintf('phrase replied with an error (%d): "%s"', $statusCode, $response->getContent(false)), $response);
throw new ProviderException(\sprintf('phrase replied with an error (%d): "%s"', $statusCode, $response->getContent(false)), $response);
}

/** @var array{records_affected: string} $arr */
$arr = $response->toArray();
$records = $arr['records_affected'];

$this->logger->info(sprintf('tagged %d keys matching "%s" with tag(s) "%s"', $records, $query, implode(', ', $addTags)));
$this->logger->info(\sprintf('tagged %d keys matching "%s" with tag(s) "%s"', $records, $query, \implode(', ', $addTags)));

return (int) $records;
}
Expand All @@ -97,19 +97,19 @@ public function untag(?string $key, array $tags, array $removeTags): int
],
'body' => [
'q' => $query,
'tags' => implode(',', $removeTags),
'tags' => \implode(',', $removeTags),
],
]);

if (200 !== $statusCode = $response->getStatusCode()) {
throw new ProviderException(sprintf('phrase replied with an error (%d): "%s"', $statusCode, $response->getContent(false)), $response);
throw new ProviderException(\sprintf('phrase replied with an error (%d): "%s"', $statusCode, $response->getContent(false)), $response);
}

/** @var array{records_affected: string} $arr */
$arr = $response->toArray();
$records = $arr['records_affected'];

$this->logger->info(sprintf('untagged %d keys matching "%s" with tag(s) "%s"', $records, $query, implode(', ', $removeTags)));
$this->logger->info(\sprintf('untagged %d keys matching "%s" with tag(s) "%s"', $records, $query, \implode(', ', $removeTags)));

return (int) $records;
}
Expand All @@ -120,8 +120,8 @@ public function untag(?string $key, array $tags, array $removeTags): int
private function createQuery(?string $key, array $tags): string
{
$query = $key ?? '';
$query .= [] !== $tags ? ' tags:'.implode(',', $tags) : '';
$query .= [] !== $tags ? ' tags:'.\implode(',', $tags) : '';

return trim($query);
return \trim($query);
}
}
20 changes: 10 additions & 10 deletions tests/Unit/Service/PhraseTagServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ public function testTag(?string $key, array $tags, array $newTags): void
$this->getLogger()
->expects(self::once())
->method('info')
->with(sprintf('tagged 10 keys matching "%s" with tag(s) "%s"', $this->query($key, $tags), implode(', ', $newTags)));
->with(\sprintf('tagged 10 keys matching "%s" with tag(s) "%s"', $this->query($key, $tags), \implode(', ', $newTags)));

$responses = [
'tag keys' => function (string $method, string $url, array $options = []) use ($key, $tags, $newTags): ResponseInterface {
$body = ['q' => $this->query($key, $tags), 'tags' => implode(',', $newTags)];
$body = ['q' => $this->query($key, $tags), 'tags' => \implode(',', $newTags)];
$this->assertSame('PATCH', $method);
$this->assertSame('https://api.phrase.com/api/v2/projects/1/keys/tag?page=1&per_page=100', $url);
$this->assertSame(http_build_query($body), $options['body']);
$this->assertSame(\http_build_query($body), $options['body']);

return new MockResponse(json_encode(['records_affected' => '10'], \JSON_THROW_ON_ERROR));
return new MockResponse(\json_encode(['records_affected' => '10'], \JSON_THROW_ON_ERROR));
},
];

Expand Down Expand Up @@ -158,16 +158,16 @@ public function testUnTag(?string $key, array $tags, array $newTags): void
$this->getLogger()
->expects(self::once())
->method('info')
->with(sprintf('untagged 10 keys matching "%s" with tag(s) "%s"', $this->query($key, $tags), implode(', ', $newTags)));
->with(\sprintf('untagged 10 keys matching "%s" with tag(s) "%s"', $this->query($key, $tags), \implode(', ', $newTags)));

$responses = [
'untag keys' => function (string $method, string $url, array $options = []) use ($key, $tags, $newTags): ResponseInterface {
$body = ['q' => $this->query($key, $tags), 'tags' => implode(',', $newTags)];
$body = ['q' => $this->query($key, $tags), 'tags' => \implode(',', $newTags)];
$this->assertSame('PATCH', $method);
$this->assertSame('https://api.phrase.com/api/v2/projects/1/keys/untag?page=1&per_page=100', $url);
$this->assertSame(http_build_query($body), $options['body']);
$this->assertSame(\http_build_query($body), $options['body']);

return new MockResponse(json_encode(['records_affected' => '10'], \JSON_THROW_ON_ERROR));
return new MockResponse(\json_encode(['records_affected' => '10'], \JSON_THROW_ON_ERROR));
},
];

Expand Down Expand Up @@ -294,8 +294,8 @@ private function getLogger(): LoggerInterface&MockObject
private function query(?string $key, array $tags): string
{
$query = $key ?? '';
$query .= [] !== $tags ? ' tags:'.implode(',', $tags) : '';
$query .= [] !== $tags ? ' tags:'.\implode(',', $tags) : '';

return trim($query);
return \trim($query);
}
}

0 comments on commit ad5d192

Please sign in to comment.