Skip to content

Commit 830cc04

Browse files
authored
Use a different image for PHP CS Fixer to get latest and upgrade config (#471)
* Use a different image for PHP CS Fixer to get latest and upgrade config * Add new cache file from PHP CS Fixer to gitignore * Brake styles * Add --dry-run and --diff * Revert "Brake styles" This reverts commit 5285d20. * Fix all code styles with the new version of PHP CS Fixer * Fix missing: DomXpath -> DOMXPath * Fix some code styles after master rebase
1 parent 255a9f6 commit 830cc04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+152
-174
lines changed

.github/workflows/static.yml

+6-28
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,13 @@ jobs:
3838

3939
php-cs-fixer:
4040
name: PHP-CS-Fixer
41-
runs-on: Ubuntu-20.04
42-
41+
runs-on: ubuntu-latest
4342
steps:
44-
- name: Checkout code
45-
uses: actions/checkout@v2
46-
47-
- name: Cache PhpCsFixer
48-
uses: actions/cache@v2
49-
with:
50-
path: .github/.cache/php-cs-fixer/
51-
key: php-cs-fixer-${{ github.sha }}
52-
restore-keys: php-cs-fixer-
53-
54-
- name: Setup PHP
55-
uses: shivammathur/setup-php@v2
56-
with:
57-
php-version: '7.4'
58-
coverage: none
59-
60-
- name: Download dependencies
61-
uses: ramsey/composer-install@v1
62-
with:
63-
composer-options: --no-interaction --prefer-dist --optimize-autoloader
64-
65-
- name: Download PHP CS Fixer
66-
run: composer bin php-cs-fixer update --no-interaction --no-progress
67-
68-
- name: Execute PHP CS Fixer
69-
run: vendor/bin/php-cs-fixer fix --diff-format udiff --dry-run
43+
- uses: actions/checkout@v2
44+
- name: PHP-CS-Fixer
45+
uses: docker://oskarstark/php-cs-fixer-ga
46+
with:
47+
args: --diff --dry-run
7048

7149
psalm:
7250
name: Psalm

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/phpunit.xml
66
/vendor/
77
.php_cs.cache
8+
.php-cs-fixer.cache
89
.phpunit.result.cache

.php-cs-fixer.dist.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude(__DIR__.'/vendor')
5+
->name('*.php')
6+
->in(__DIR__)
7+
;
8+
9+
$config = new PhpCsFixer\Config();
10+
return $config->setRules([
11+
'@Symfony' => true,
12+
'@Symfony:risky' => true,
13+
'array_syntax' => ['syntax' => 'short'],
14+
'native_function_invocation' => true,
15+
'ordered_imports' => true,
16+
'declare_strict_types' => false,
17+
'single_import_per_statement' => false,
18+
])
19+
->setRiskyAllowed(true)
20+
->setFinder($finder)
21+
;

.php_cs

-22
This file was deleted.

Catalogue/CatalogueFetcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getCatalogues(Configuration $config, array $locales = []): array
4646
foreach ($locales as $locale) {
4747
$currentCatalogue = new MessageCatalogue($locale);
4848
foreach ($dirs as $path) {
49-
if (\is_dir($path)) {
49+
if (is_dir($path)) {
5050
$this->reader->read($path, $currentCatalogue);
5151
}
5252
}

Catalogue/CatalogueManager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function load(array $catalogues): void
4242
public function getDomains(): array
4343
{
4444
/** @var MessageCatalogueInterface $c */
45-
$c = \reset($this->catalogues);
45+
$c = reset($this->catalogues);
4646

4747
return $c->getDomains();
4848
}
@@ -107,7 +107,7 @@ public function findMessages(array $config = []): array
107107
}
108108
}
109109

110-
$messages = \array_filter($messages, static function (CatalogueMessage $m) use ($isNew, $isObsolete, $isApproved, $isEmpty) {
110+
$messages = array_filter($messages, static function (CatalogueMessage $m) use ($isNew, $isObsolete, $isApproved, $isEmpty) {
111111
if (null !== $isNew && $m->isNew() !== $isNew) {
112112
return false;
113113
}

Catalogue/Operation/ReplaceOperation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function processDomain($domain): void
3737
'new' => [],
3838
'obsolete' => [],
3939
];
40-
if (\defined(\sprintf('%s::INTL_DOMAIN_SUFFIX', MessageCatalogueInterface::class))) {
40+
if (\defined(sprintf('%s::INTL_DOMAIN_SUFFIX', MessageCatalogueInterface::class))) {
4141
$intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
4242
} else {
4343
$intlDomain = $domain;
@@ -160,6 +160,6 @@ public function isArrayAssociative(array $arr): bool
160160
return false;
161161
}
162162

163-
return \array_keys($arr) !== \range(0, \count($arr) - 1);
163+
return array_keys($arr) !== range(0, \count($arr) - 1);
164164
}
165165
}

Command/BundleTrait.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ trait BundleTrait
2020
private function configureBundleDirs(InputInterface $input, Configuration $config): void
2121
{
2222
if ($bundleName = $input->getOption('bundle')) {
23-
if (0 === \strpos($bundleName, '@')) {
24-
if (false === $pos = \strpos($bundleName, '/')) {
25-
$bundleName = \substr($bundleName, 1);
23+
if (0 === strpos($bundleName, '@')) {
24+
if (false === $pos = strpos($bundleName, '/')) {
25+
$bundleName = substr($bundleName, 1);
2626
} else {
27-
$bundleName = \substr($bundleName, 1, $pos - 2);
27+
$bundleName = substr($bundleName, 1, $pos - 2);
2828
}
2929
}
3030

Command/CheckMissingCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9191
$io = new SymfonyStyle($input, $output);
9292

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

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

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

106106
return 1;
@@ -132,7 +132,7 @@ private function countEmptyTranslations(MessageCatalogueInterface $catalogue): i
132132
$total = 0;
133133

134134
foreach ($catalogue->getDomains() as $domain) {
135-
$emptyTranslations = \array_filter(
135+
$emptyTranslations = array_filter(
136136
$catalogue->all($domain),
137137
function (string $message = null): bool {
138138
return null === $message || '' === $message;

Command/DeleteEmptyCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9696

9797
if ($input->isInteractive()) {
9898
$helper = $this->getHelper('question');
99-
$question = new ConfirmationQuestion(\sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false);
99+
$question = new ConfirmationQuestion(sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false);
100100
if (!$helper->ask($input, $output, $question)) {
101101
return 0;
102102
}
@@ -109,7 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
109109
foreach ($messages as $message) {
110110
$storage->delete($message->getLocale(), $message->getDomain(), $message->getKey());
111111
if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
112-
$output->writeln(\sprintf(
112+
$output->writeln(sprintf(
113113
'Deleted empty message "<info>%s</info>" from domain "<info>%s</info>" and locale "<info>%s</info>"',
114114
$message->getKey(),
115115
$message->getDomain(),

Command/DeleteObsoleteCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9797

9898
if ($input->isInteractive()) {
9999
$helper = $this->getHelper('question');
100-
$question = new ConfirmationQuestion(\sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false);
100+
$question = new ConfirmationQuestion(sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false);
101101
if (!$helper->ask($input, $output, $question)) {
102102
return 0;
103103
}
@@ -110,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
110110
foreach ($messages as $message) {
111111
$storage->delete($message->getLocale(), $message->getDomain(), $message->getKey());
112112
if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
113-
$output->writeln(\sprintf(
113+
$output->writeln(sprintf(
114114
'Deleted obsolete message "<info>%s</info>" from domain "<info>%s</info>" and locale "<info>%s</info>"',
115115
$message->getKey(),
116116
$message->getDomain(),

Command/DownloadCommand.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7575
$message = 'The --cache option is deprecated as it\'s now the default behaviour of this command.';
7676

7777
$io->note($message);
78-
@\trigger_error($message, \E_USER_DEPRECATED);
78+
@trigger_error($message, \E_USER_DEPRECATED);
7979
}
8080

8181
$configName = $input->getArgument('configuration');
@@ -117,19 +117,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
117117
*/
118118
private function hashDirectory(string $directory)
119119
{
120-
if (!\is_dir($directory)) {
120+
if (!is_dir($directory)) {
121121
return false;
122122
}
123123

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

127-
$hash = \hash_init('md5');
127+
$hash = hash_init('md5');
128128
foreach ($finder as $file) {
129-
\hash_update_file($hash, $file->getRealPath());
129+
hash_update_file($hash, $file->getRealPath());
130130
}
131131

132-
return \hash_final($hash);
132+
return hash_final($hash);
133133
}
134134

135135
public function cleanParameters(array $raw)
@@ -138,7 +138,7 @@ public function cleanParameters(array $raw)
138138

139139
foreach ($raw as $string) {
140140
// Assert $string looks like "foo:bar"
141-
list($key, $value) = \explode(':', $string, 2);
141+
list($key, $value) = explode(':', $string, 2);
142142
$config[$key][] = $value;
143143
}
144144

Command/ExtractCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
128128
/** @var Error $error */
129129
foreach ($errors as $error) {
130130
$io->error(
131-
\sprintf("%s\nLine: %s\nMessage: %s", $error->getPath(), $error->getLine(), $error->getMessage())
131+
sprintf("%s\nLine: %s\nMessage: %s", $error->getPath(), $error->getLine(), $error->getMessage())
132132
);
133133
}
134134
}

Command/StatusCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8989
}
9090

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

9494
return 0;
9595
}

Command/StorageTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private function getStorage($configName): StorageService
3131
if (null === $storage = $this->storageManager->getStorage($configName)) {
3232
$availableStorages = $this->storageManager->getNames();
3333

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

3737
return $storage;

Command/SyncCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5959

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

6464
return 0;
6565
}
@@ -78,7 +78,7 @@ public function cleanParameters(array $raw)
7878

7979
foreach ($raw as $string) {
8080
// Assert $string looks like "foo:bar"
81-
list($key, $value) = \explode(':', $string, 2);
81+
list($key, $value) = explode(':', $string, 2);
8282
$config[$key][] = $value;
8383
}
8484

Controller/EditInPlaceController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public function editAction(Request $request, string $configName, string $locale)
6666
private function getMessages(Request $request, string $locale, array $validationGroups = []): array
6767
{
6868
$json = $request->getContent();
69-
$data = \json_decode($json, true);
69+
$data = json_decode($json, true);
7070
$messages = [];
7171

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

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

Controller/SymfonyProfilerController.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function createAssetsAction(Request $request, string $token): Response
130130
$uploaded[] = $message;
131131
}
132132

133-
return new Response(\sprintf('%s new assets created!', \count($uploaded)));
133+
return new Response(sprintf('%s new assets created!', \count($uploaded)));
134134
}
135135

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

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

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

153153
$message
154154
->setLocale($requestCollector->getLocale())
155-
->setTranslation(\sprintf('[%s]', $message->getTranslation()))
155+
->setTranslation(sprintf('[%s]', $message->getTranslation()))
156156
;
157157
}
158158

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

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

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

196196
$messages = $dataCollector->getMessages();
197197

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

0 commit comments

Comments
 (0)