Skip to content

Commit b1794e1

Browse files
authored
Merge pull request #532 from franmomu/apply_cs
Apply cs
2 parents 3290fbe + a430ada commit b1794e1

File tree

78 files changed

+778
-717
lines changed

Some content is hidden

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

78 files changed

+778
-717
lines changed

Annotation/Desc.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* Copyright 2011 Johannes M. Schmitt <[email protected]>
57
*

Annotation/Ignore.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* Copyright 2011 Johannes M. Schmitt <[email protected]>
57
*

Annotation/Meaning.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* Copyright 2011 Johannes M. Schmitt <[email protected]>
57
*
@@ -30,9 +32,6 @@ final class Meaning
3032
/** @var string @Required */
3133
public $text;
3234

33-
/**
34-
* Meaning constructor.
35-
*/
3635
public function __construct()
3736
{
3837
if (0 === func_num_args()) {

Command/ExtractTranslationCommand.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* Copyright 2011 Johannes M. Schmitt <[email protected]>
57
*
@@ -18,14 +20,14 @@
1820

1921
namespace JMS\TranslationBundle\Command;
2022

23+
use JMS\TranslationBundle\Logger\OutputLogger;
2124
use JMS\TranslationBundle\Translation\ConfigBuilder;
2225
use JMS\TranslationBundle\Translation\ConfigFactory;
2326
use JMS\TranslationBundle\Translation\Updater;
2427
use Symfony\Component\Console\Command\Command;
2528
use Symfony\Component\Console\Input\InputArgument;
26-
use JMS\TranslationBundle\Logger\OutputLogger;
27-
use Symfony\Component\Console\Input\InputOption;
2829
use Symfony\Component\Console\Input\InputInterface;
30+
use Symfony\Component\Console\Input\InputOption;
2931
use Symfony\Component\Console\Output\OutputInterface;
3032

3133
/**
@@ -82,14 +84,9 @@ protected function configure()
8284
->addOption('output-format', null, InputOption::VALUE_REQUIRED, 'The output format that should be used (in most cases, it is better to change only the default-output-format).')
8385
->addOption('default-output-format', null, InputOption::VALUE_REQUIRED, 'The default output format (defaults to xlf).')
8486
->addOption('keep', null, InputOption::VALUE_NONE, 'Define if the updater service should keep the old translation (defaults to false).')
85-
->addOption('external-translations-dir', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Load external translation resources')
86-
;
87+
->addOption('external-translations-dir', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Load external translation resources');
8788
}
8889

89-
/**
90-
* @param InputInterface $input
91-
* @param OutputInterface $output
92-
*/
9390
protected function execute(InputInterface $input, OutputInterface $output): int
9491
{
9592
$builder = $input->getOption('config') ?
@@ -116,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
116113
$output->writeln(sprintf('Directories: <info>%s</info>', implode(', ', $config->getScanDirs())));
117114
$output->writeln(sprintf('Excluded Directories: <info>%s</info>', $config->getExcludedDirs() ? implode(', ', $config->getExcludedDirs()) : '# none #'));
118115
$output->writeln(sprintf('Excluded Names: <info>%s</info>', $config->getExcludedNames() ? implode(', ', $config->getExcludedNames()) : '# none #'));
119-
$output->writeln(sprintf('Output-Format: <info>%s</info>', $config->getOutputFormat() ? $config->getOutputFormat() : '# whatever is present, if nothing then '.$config->getDefaultOutputFormat().' #'));
116+
$output->writeln(sprintf('Output-Format: <info>%s</info>', $config->getOutputFormat() ? $config->getOutputFormat() : '# whatever is present, if nothing then ' . $config->getDefaultOutputFormat() . ' #'));
120117
$output->writeln(sprintf('Custom Extractors: <info>%s</info>', $config->getEnabledExtractors() ? implode(', ', array_keys($config->getEnabledExtractors())) : '# none #'));
121118
$output->writeln('============================================================');
122119

@@ -129,20 +126,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
129126
if ($input->getOption('dry-run')) {
130127
$changeSet = $this->updater->getChangeSet($config);
131128

132-
$output->writeln('Added Messages: '.count($changeSet->getAddedMessages()));
129+
$output->writeln('Added Messages: ' . count($changeSet->getAddedMessages()));
133130
if ($input->hasParameterOption('--verbose')) {
134131
foreach ($changeSet->getAddedMessages() as $message) {
135-
$output->writeln($message->getId(). '-> '.$message->getDesc());
132+
$output->writeln($message->getId() . '-> ' . $message->getDesc());
136133
}
137134
}
138135

139136
if ($config->isKeepOldMessages()) {
140137
$output->writeln('Deleted Messages: # none as "Keep Old Translations" is true #');
141138
} else {
142-
$output->writeln('Deleted Messages: '.count($changeSet->getDeletedMessages()));
139+
$output->writeln('Deleted Messages: ' . count($changeSet->getDeletedMessages()));
143140
if ($input->hasParameterOption('--verbose')) {
144141
foreach ($changeSet->getDeletedMessages() as $message) {
145-
$output->writeln($message->getId(). '-> '.$message->getDesc());
142+
$output->writeln($message->getId() . '-> ' . $message->getDesc());
146143
}
147144
}
148145
}
@@ -158,10 +155,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
158155
return 0;
159156
}
160157

161-
/**
162-
* @param InputInterface $input
163-
* @param ConfigBuilder $builder
164-
*/
165158
private function updateWithInput(InputInterface $input, ConfigBuilder $builder)
166159
{
167160
if ($bundle = $input->getOption('bundle')) {
@@ -170,8 +163,8 @@ private function updateWithInput(InputInterface $input, ConfigBuilder $builder)
170163
}
171164

172165
$bundle = $this->getApplication()->getKernel()->getBundle($bundle);
173-
$builder->setTranslationsDir($bundle->getPath().'/Resources/translations');
174-
$builder->setScanDirs(array($bundle->getPath()));
166+
$builder->setTranslationsDir($bundle->getPath() . '/Resources/translations');
167+
$builder->setScanDirs([$bundle->getPath()]);
175168
}
176169

177170
if ($dirs = $input->getOption('dir')) {

Command/ResourcesListCommand.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* Copyright 2011 Johannes M. Schmitt <[email protected]>
57
*
@@ -18,11 +20,11 @@
1820

1921
namespace JMS\TranslationBundle\Command;
2022

23+
use JMS\TranslationBundle\Util\FileUtils;
2124
use Symfony\Component\Console\Command\Command;
22-
use Symfony\Component\Console\Input\InputOption;
2325
use Symfony\Component\Console\Input\InputInterface;
26+
use Symfony\Component\Console\Input\InputOption;
2427
use Symfony\Component\Console\Output\OutputInterface;
25-
use JMS\TranslationBundle\Util\FileUtils;
2628

2729
/**
2830
* @author Fabien Potencier <[email protected]>
@@ -62,14 +64,9 @@ protected function configure()
6264
$this
6365
->setName('translation:list-resources')
6466
->setDescription('List translation resources available.')
65-
->addOption('files', null, InputOption::VALUE_OPTIONAL, 'Display only files')
66-
;
67+
->addOption('files', null, InputOption::VALUE_OPTIONAL, 'Display only files');
6768
}
6869

69-
/**
70-
* @param \Symfony\Component\Console\Input\InputInterface $input
71-
* @param \Symfony\Component\Console\Output\OutputInterface $output
72-
*/
7370
protected function execute(InputInterface $input, OutputInterface $output): int
7471
{
7572
$directoriesToSearch = [];
@@ -113,11 +110,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
113110

114111
/**
115112
* @param array $dirs
113+
*
116114
* @return array
117115
*/
118116
private function retrieveFiles(array $dirs)
119117
{
120-
$files = array();
118+
$files = [];
121119
// Register translation resources
122120
foreach ($dirs as $dir) {
123121
foreach (FileUtils::findTranslationFiles($dir) as $catalogue => $locales) {
@@ -138,21 +136,21 @@ private function retrieveFiles(array $dirs)
138136
private function retrieveDirs()
139137
{
140138
// Discover translation directories
141-
$dirs = array();
139+
$dirs = [];
142140
foreach ($this->bundles as $bundle) {
143141
$reflection = new \ReflectionClass($bundle);
144-
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) {
142+
if (is_dir($dir = dirname($reflection->getFilename()) . '/Resources/translations')) {
145143
$dirs[] = $dir;
146144
}
147145
}
148146

149147
// TODO: Remove this block when dropping support of Symfony 4
150148
if ($this->rootDir !== null &&
151-
is_dir($dir = $this->rootDir.'/Resources/translations')) {
149+
is_dir($dir = $this->rootDir . '/Resources/translations')) {
152150
$dirs[] = $dir;
153151
}
154152

155-
if (is_dir($dir = $this->projectDir.'/translations')) {
153+
if (is_dir($dir = $this->projectDir . '/translations')) {
156154
$dirs[] = $dir;
157155
}
158156

Controller/ApiController.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* Copyright 2011 Johannes M. Schmitt <[email protected]>
57
*
@@ -21,15 +23,15 @@
2123
use JMS\TranslationBundle\Exception\RuntimeException;
2224
use JMS\TranslationBundle\Translation\ConfigFactory;
2325
use JMS\TranslationBundle\Translation\Updater;
24-
use Symfony\Component\HttpFoundation\Response;
2526
use JMS\TranslationBundle\Util\FileUtils;
2627
use Symfony\Component\HttpFoundation\Request;
28+
use Symfony\Component\HttpFoundation\Response;
2729
use Symfony\Component\Routing\Annotation\Route;
2830

2931
/**
30-
* @Route("/api")
31-
*
3232
* @author Johannes M. Schmitt <[email protected]>
33+
*
34+
* @Route("/api")
3335
*/
3436
class ApiController
3537
{
@@ -43,30 +45,25 @@ class ApiController
4345
*/
4446
private $updater;
4547

46-
/**
47-
* ApiController constructor.
48-
*
49-
* @param ConfigFactory $configFactory
50-
* @param Updater $updater
51-
*/
5248
public function __construct(ConfigFactory $configFactory, Updater $updater)
5349
{
5450
$this->configFactory = $configFactory;
5551
$this->updater = $updater;
5652
}
5753

5854
/**
59-
* @Route("/configs/{config}/domains/{domain}/locales/{locale}/messages",
60-
* methods={"PUT"},
61-
* name="jms_translation_update_message",
62-
* defaults = {"id" = null},
63-
* options = {"i18n" = false})
6455
* @param Request $request
6556
* @param string $config
6657
* @param string $domain
6758
* @param string $locale
6859
*
6960
* @return Response
61+
*
62+
* @Route("/configs/{config}/domains/{domain}/locales/{locale}/messages",
63+
* methods={"PUT"},
64+
* name="jms_translation_update_message",
65+
* defaults = {"id" = null},
66+
* options = {"i18n" = false})
7067
*/
7168
public function updateMessageAction(Request $request, $config, $domain, $locale)
7269
{
@@ -86,7 +83,11 @@ public function updateMessageAction(Request $request, $config, $domain, $locale)
8683
[$format, $file] = $files[$domain][$locale];
8784

8885
$this->updater->updateTranslation(
89-
$file, $format, $domain, $locale, $id,
86+
$file->getPathname(),
87+
$format,
88+
$domain,
89+
$locale,
90+
$id,
9091
$request->request->get('message')
9192
);
9293

Controller/TranslateController.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* Copyright 2011 Johannes M. Schmitt <[email protected]>
57
*
@@ -48,12 +50,6 @@ class TranslateController
4850
*/
4951
private $sourceLanguage;
5052

51-
/**
52-
* TranslateController constructor.
53-
*
54-
* @param ConfigFactory $configFactory
55-
* @param LoaderManager $loader
56-
*/
5753
public function __construct(ConfigFactory $configFactory, LoaderManager $loader)
5854
{
5955
$this->configFactory = $configFactory;
@@ -69,10 +65,12 @@ public function setSourceLanguage($lang)
6965
}
7066

7167
/**
72-
* @Route("/", name="jms_translation_index", options = {"i18n" = false})
73-
* @Template("@JMSTranslation/Translate/index.html.twig")
7468
* @param Request $request
69+
*
7570
* @return array
71+
*
72+
* @Route("/", name="jms_translation_index", options = {"i18n" = false})
73+
* @Template("@JMSTranslation/Translate/index.html.twig")
7674
*/
7775
public function indexAction(Request $request)
7876
{
@@ -111,7 +109,7 @@ public function indexAction(Request $request)
111109
// create alternative messages
112110
// TODO: We should probably also add these to the XLIFF file for external translators,
113111
// and the specification already supports it
114-
$alternativeMessages = array();
112+
$alternativeMessages = [];
115113
foreach ($locales as $otherLocale) {
116114
if ($locale === $otherLocale) {
117115
continue;
@@ -128,7 +126,7 @@ public function indexAction(Request $request)
128126
}
129127
}
130128

131-
$newMessages = $existingMessages = array();
129+
$newMessages = $existingMessages = [];
132130
foreach ($catalogue->getDomain($domain)->all() as $id => $message) {
133131
if ($message->isNew()) {
134132
$newMessages[$id] = $message;
@@ -138,7 +136,7 @@ public function indexAction(Request $request)
138136
$existingMessages[$id] = $message;
139137
}
140138

141-
return array(
139+
return [
142140
'selectedConfig' => $config,
143141
'configs' => $configs,
144142
'selectedDomain' => $domain,
@@ -149,9 +147,9 @@ public function indexAction(Request $request)
149147
'newMessages' => $newMessages,
150148
'existingMessages' => $existingMessages,
151149
'alternativeMessages' => $alternativeMessages,
152-
'isWriteable' => is_writeable($files[$domain][$locale][1]),
150+
'isWriteable' => is_writable((string) $files[$domain][$locale][1]),
153151
'file' => (string) $files[$domain][$locale][1],
154152
'sourceLanguage' => $this->sourceLanguage,
155-
);
153+
];
156154
}
157155
}

DependencyInjection/Compiler/IntegrationPass.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* Copyright 2011 Johannes M. Schmitt <[email protected]>
57
*
@@ -18,8 +20,8 @@
1820

1921
namespace JMS\TranslationBundle\DependencyInjection\Compiler;
2022

21-
use Symfony\Component\DependencyInjection\ContainerBuilder;
2223
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
24+
use Symfony\Component\DependencyInjection\ContainerBuilder;
2325

2426
class IntegrationPass implements CompilerPassInterface
2527
{

0 commit comments

Comments
 (0)