Skip to content

Use a different image for PHP CS Fixer to get latest and upgrade config #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,13 @@ jobs:

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: Ubuntu-20.04

runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache PhpCsFixer
uses: actions/cache@v2
with:
path: .github/.cache/php-cs-fixer/
key: php-cs-fixer-${{ github.sha }}
restore-keys: php-cs-fixer-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none

- name: Download dependencies
uses: ramsey/composer-install@v1
with:
composer-options: --no-interaction --prefer-dist --optimize-autoloader

- name: Download PHP CS Fixer
run: composer bin php-cs-fixer update --no-interaction --no-progress

- name: Execute PHP CS Fixer
run: vendor/bin/php-cs-fixer fix --diff-format udiff --dry-run
- uses: actions/checkout@v2
- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --diff --dry-run

psalm:
name: Psalm
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/phpunit.xml
/vendor/
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
21 changes: 21 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude(__DIR__.'/vendor')
->name('*.php')
->in(__DIR__)
;

$config = new PhpCsFixer\Config();
return $config->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'native_function_invocation' => true,
'ordered_imports' => true,
'declare_strict_types' => false,
'single_import_per_statement' => false,
])
->setRiskyAllowed(true)
->setFinder($finder)
;
22 changes: 0 additions & 22 deletions .php_cs

This file was deleted.

2 changes: 1 addition & 1 deletion Catalogue/CatalogueFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getCatalogues(Configuration $config, array $locales = []): array
foreach ($locales as $locale) {
$currentCatalogue = new MessageCatalogue($locale);
foreach ($dirs as $path) {
if (\is_dir($path)) {
if (is_dir($path)) {
$this->reader->read($path, $currentCatalogue);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Catalogue/CatalogueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function load(array $catalogues): void
public function getDomains(): array
{
/** @var MessageCatalogueInterface $c */
$c = \reset($this->catalogues);
$c = reset($this->catalogues);

return $c->getDomains();
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public function findMessages(array $config = []): array
}
}

$messages = \array_filter($messages, static function (CatalogueMessage $m) use ($isNew, $isObsolete, $isApproved, $isEmpty) {
$messages = array_filter($messages, static function (CatalogueMessage $m) use ($isNew, $isObsolete, $isApproved, $isEmpty) {
if (null !== $isNew && $m->isNew() !== $isNew) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions Catalogue/Operation/ReplaceOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function processDomain($domain): void
'new' => [],
'obsolete' => [],
];
if (\defined(\sprintf('%s::INTL_DOMAIN_SUFFIX', MessageCatalogueInterface::class))) {
if (\defined(sprintf('%s::INTL_DOMAIN_SUFFIX', MessageCatalogueInterface::class))) {
$intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
} else {
$intlDomain = $domain;
Expand Down Expand Up @@ -160,6 +160,6 @@ public function isArrayAssociative(array $arr): bool
return false;
}

return \array_keys($arr) !== \range(0, \count($arr) - 1);
return array_keys($arr) !== range(0, \count($arr) - 1);
}
}
8 changes: 4 additions & 4 deletions Command/BundleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ trait BundleTrait
private function configureBundleDirs(InputInterface $input, Configuration $config): void
{
if ($bundleName = $input->getOption('bundle')) {
if (0 === \strpos($bundleName, '@')) {
if (false === $pos = \strpos($bundleName, '/')) {
$bundleName = \substr($bundleName, 1);
if (0 === strpos($bundleName, '@')) {
if (false === $pos = strpos($bundleName, '/')) {
$bundleName = substr($bundleName, 1);
} else {
$bundleName = \substr($bundleName, 1, $pos - 2);
$bundleName = substr($bundleName, 1, $pos - 2);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Command/CheckMissingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);

if ($newMessages > 0) {
$io->error(\sprintf('%d new message(s) have been found, run bin/console translation:extract', $newMessages));
$io->error(sprintf('%d new message(s) have been found, run bin/console translation:extract', $newMessages));

return 1;
}
Expand All @@ -100,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($emptyTranslations > 0) {
$io->error(
\sprintf('%d messages have empty translations, please provide translations for them', $emptyTranslations)
sprintf('%d messages have empty translations, please provide translations for them', $emptyTranslations)
);

return 1;
Expand Down Expand Up @@ -132,7 +132,7 @@ private function countEmptyTranslations(MessageCatalogueInterface $catalogue): i
$total = 0;

foreach ($catalogue->getDomains() as $domain) {
$emptyTranslations = \array_filter(
$emptyTranslations = array_filter(
$catalogue->all($domain),
function (string $message = null): bool {
return null === $message || '' === $message;
Expand Down
4 changes: 2 additions & 2 deletions Command/DeleteEmptyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($input->isInteractive()) {
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion(\sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false);
$question = new ConfirmationQuestion(sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false);
if (!$helper->ask($input, $output, $question)) {
return 0;
}
Expand All @@ -109,7 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($messages as $message) {
$storage->delete($message->getLocale(), $message->getDomain(), $message->getKey());
if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
$output->writeln(\sprintf(
$output->writeln(sprintf(
'Deleted empty message "<info>%s</info>" from domain "<info>%s</info>" and locale "<info>%s</info>"',
$message->getKey(),
$message->getDomain(),
Expand Down
4 changes: 2 additions & 2 deletions Command/DeleteObsoleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($input->isInteractive()) {
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion(\sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false);
$question = new ConfirmationQuestion(sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false);
if (!$helper->ask($input, $output, $question)) {
return 0;
}
Expand All @@ -110,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($messages as $message) {
$storage->delete($message->getLocale(), $message->getDomain(), $message->getKey());
if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
$output->writeln(\sprintf(
$output->writeln(sprintf(
'Deleted obsolete message "<info>%s</info>" from domain "<info>%s</info>" and locale "<info>%s</info>"',
$message->getKey(),
$message->getDomain(),
Expand Down
12 changes: 6 additions & 6 deletions Command/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$message = 'The --cache option is deprecated as it\'s now the default behaviour of this command.';

$io->note($message);
@\trigger_error($message, \E_USER_DEPRECATED);
@trigger_error($message, \E_USER_DEPRECATED);
}

$configName = $input->getArgument('configuration');
Expand Down Expand Up @@ -117,19 +117,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
*/
private function hashDirectory(string $directory)
{
if (!\is_dir($directory)) {
if (!is_dir($directory)) {
return false;
}

$finder = new Finder();
$finder->files()->in($directory)->notName('/~$/')->sortByName();

$hash = \hash_init('md5');
$hash = hash_init('md5');
foreach ($finder as $file) {
\hash_update_file($hash, $file->getRealPath());
hash_update_file($hash, $file->getRealPath());
}

return \hash_final($hash);
return hash_final($hash);
}

public function cleanParameters(array $raw)
Expand All @@ -138,7 +138,7 @@ public function cleanParameters(array $raw)

foreach ($raw as $string) {
// Assert $string looks like "foo:bar"
list($key, $value) = \explode(':', $string, 2);
list($key, $value) = explode(':', $string, 2);
$config[$key][] = $value;
}

Expand Down
2 changes: 1 addition & 1 deletion Command/ExtractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var Error $error */
foreach ($errors as $error) {
$io->error(
\sprintf("%s\nLine: %s\nMessage: %s", $error->getPath(), $error->getLine(), $error->getMessage())
sprintf("%s\nLine: %s\nMessage: %s", $error->getPath(), $error->getLine(), $error->getMessage())
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if ($input->getOption('json')) {
$output->writeln(\json_encode($stats));
$output->writeln(json_encode($stats));

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion Command/StorageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private function getStorage($configName): StorageService
if (null === $storage = $this->storageManager->getStorage($configName)) {
$availableStorages = $this->storageManager->getNames();

throw new \InvalidArgumentException(\sprintf('Unknown storage "%s". Available storages are "%s".', $configName, \implode('", "', $availableStorages)));
throw new \InvalidArgumentException(sprintf('Unknown storage "%s". Available storages are "%s".', $configName, implode('", "', $availableStorages)));
}

return $storage;
Expand Down
4 changes: 2 additions & 2 deletions Command/SyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

break;
default:
$output->writeln(\sprintf('Direction must be either "up" or "down". Not "%s".', $input->getArgument('direction')));
$output->writeln(sprintf('Direction must be either "up" or "down". Not "%s".', $input->getArgument('direction')));

return 0;
}
Expand All @@ -78,7 +78,7 @@ public function cleanParameters(array $raw)

foreach ($raw as $string) {
// Assert $string looks like "foo:bar"
list($key, $value) = \explode(':', $string, 2);
list($key, $value) = explode(':', $string, 2);
$config[$key][] = $value;
}

Expand Down
4 changes: 2 additions & 2 deletions Controller/EditInPlaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public function editAction(Request $request, string $configName, string $locale)
private function getMessages(Request $request, string $locale, array $validationGroups = []): array
{
$json = $request->getContent();
$data = \json_decode($json, true);
$data = json_decode($json, true);
$messages = [];

foreach ($data as $key => $value) {
[$domain, $translationKey] = \explode('|', $key);
[$domain, $translationKey] = explode('|', $key);

$message = new Message($translationKey, $domain, $locale, $value);

Expand Down
10 changes: 5 additions & 5 deletions Controller/SymfonyProfilerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function createAssetsAction(Request $request, string $token): Response
$uploaded[] = $message;
}

return new Response(\sprintf('%s new assets created!', \count($uploaded)));
return new Response(sprintf('%s new assets created!', \count($uploaded)));
}

private function getMessage(Request $request, string $token): SfProfilerMessage
Expand All @@ -142,7 +142,7 @@ private function getMessage(Request $request, string $token): SfProfilerMessage
$collectorMessages = $this->getMessages($token);

if (!isset($collectorMessages[$messageId])) {
throw new NotFoundHttpException(\sprintf('No message with key "%s" was found.', $messageId));
throw new NotFoundHttpException(sprintf('No message with key "%s" was found.', $messageId));
}
$message = SfProfilerMessage::create($collectorMessages[$messageId]);

Expand All @@ -152,7 +152,7 @@ private function getMessage(Request $request, string $token): SfProfilerMessage

$message
->setLocale($requestCollector->getLocale())
->setTranslation(\sprintf('[%s]', $message->getTranslation()))
->setTranslation(sprintf('[%s]', $message->getTranslation()))
;
}

Expand All @@ -172,7 +172,7 @@ protected function getSelectedMessages(Request $request, string $token): array
return [];
}

$toSave = \array_intersect_key($this->getMessages($token), \array_flip($selected));
$toSave = array_intersect_key($this->getMessages($token), array_flip($selected));

$messages = [];
foreach ($toSave as $data) {
Expand All @@ -195,7 +195,7 @@ private function getMessages(string $token, string $profileName = 'translation')

$messages = $dataCollector->getMessages();

if (\class_exists(Data::class) && $messages instanceof Data) {
if (class_exists(Data::class) && $messages instanceof Data) {
return $messages->getValue(true);
}

Expand Down
Loading