diff --git a/Annotation/Desc.php b/Annotation/Desc.php
index a352fb89..35da5695 100644
--- a/Annotation/Desc.php
+++ b/Annotation/Desc.php
@@ -1,5 +1,7 @@
*
diff --git a/Annotation/Ignore.php b/Annotation/Ignore.php
index 3e933310..f0dfb49a 100644
--- a/Annotation/Ignore.php
+++ b/Annotation/Ignore.php
@@ -1,5 +1,7 @@
*
diff --git a/Annotation/Meaning.php b/Annotation/Meaning.php
index 79ffd775..05dd0931 100644
--- a/Annotation/Meaning.php
+++ b/Annotation/Meaning.php
@@ -1,5 +1,7 @@
*
@@ -30,9 +32,6 @@ final class Meaning
/** @var string @Required */
public $text;
- /**
- * Meaning constructor.
- */
public function __construct()
{
if (0 === func_num_args()) {
diff --git a/Command/ExtractTranslationCommand.php b/Command/ExtractTranslationCommand.php
index c696de30..c7c726e4 100644
--- a/Command/ExtractTranslationCommand.php
+++ b/Command/ExtractTranslationCommand.php
@@ -1,5 +1,7 @@
*
@@ -18,14 +20,14 @@
namespace JMS\TranslationBundle\Command;
+use JMS\TranslationBundle\Logger\OutputLogger;
use JMS\TranslationBundle\Translation\ConfigBuilder;
use JMS\TranslationBundle\Translation\ConfigFactory;
use JMS\TranslationBundle\Translation\Updater;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
-use JMS\TranslationBundle\Logger\OutputLogger;
-use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
@@ -82,14 +84,9 @@ protected function configure()
->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).')
->addOption('default-output-format', null, InputOption::VALUE_REQUIRED, 'The default output format (defaults to xlf).')
->addOption('keep', null, InputOption::VALUE_NONE, 'Define if the updater service should keep the old translation (defaults to false).')
- ->addOption('external-translations-dir', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Load external translation resources')
- ;
+ ->addOption('external-translations-dir', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Load external translation resources');
}
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- */
protected function execute(InputInterface $input, OutputInterface $output): int
{
$builder = $input->getOption('config') ?
@@ -116,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln(sprintf('Directories: %s', implode(', ', $config->getScanDirs())));
$output->writeln(sprintf('Excluded Directories: %s', $config->getExcludedDirs() ? implode(', ', $config->getExcludedDirs()) : '# none #'));
$output->writeln(sprintf('Excluded Names: %s', $config->getExcludedNames() ? implode(', ', $config->getExcludedNames()) : '# none #'));
- $output->writeln(sprintf('Output-Format: %s', $config->getOutputFormat() ? $config->getOutputFormat() : '# whatever is present, if nothing then '.$config->getDefaultOutputFormat().' #'));
+ $output->writeln(sprintf('Output-Format: %s', $config->getOutputFormat() ? $config->getOutputFormat() : '# whatever is present, if nothing then ' . $config->getDefaultOutputFormat() . ' #'));
$output->writeln(sprintf('Custom Extractors: %s', $config->getEnabledExtractors() ? implode(', ', array_keys($config->getEnabledExtractors())) : '# none #'));
$output->writeln('============================================================');
@@ -129,20 +126,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($input->getOption('dry-run')) {
$changeSet = $this->updater->getChangeSet($config);
- $output->writeln('Added Messages: '.count($changeSet->getAddedMessages()));
+ $output->writeln('Added Messages: ' . count($changeSet->getAddedMessages()));
if ($input->hasParameterOption('--verbose')) {
foreach ($changeSet->getAddedMessages() as $message) {
- $output->writeln($message->getId(). '-> '.$message->getDesc());
+ $output->writeln($message->getId() . '-> ' . $message->getDesc());
}
}
if ($config->isKeepOldMessages()) {
$output->writeln('Deleted Messages: # none as "Keep Old Translations" is true #');
} else {
- $output->writeln('Deleted Messages: '.count($changeSet->getDeletedMessages()));
+ $output->writeln('Deleted Messages: ' . count($changeSet->getDeletedMessages()));
if ($input->hasParameterOption('--verbose')) {
foreach ($changeSet->getDeletedMessages() as $message) {
- $output->writeln($message->getId(). '-> '.$message->getDesc());
+ $output->writeln($message->getId() . '-> ' . $message->getDesc());
}
}
}
@@ -158,10 +155,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}
- /**
- * @param InputInterface $input
- * @param ConfigBuilder $builder
- */
private function updateWithInput(InputInterface $input, ConfigBuilder $builder)
{
if ($bundle = $input->getOption('bundle')) {
@@ -170,8 +163,8 @@ private function updateWithInput(InputInterface $input, ConfigBuilder $builder)
}
$bundle = $this->getApplication()->getKernel()->getBundle($bundle);
- $builder->setTranslationsDir($bundle->getPath().'/Resources/translations');
- $builder->setScanDirs(array($bundle->getPath()));
+ $builder->setTranslationsDir($bundle->getPath() . '/Resources/translations');
+ $builder->setScanDirs([$bundle->getPath()]);
}
if ($dirs = $input->getOption('dir')) {
diff --git a/Command/ResourcesListCommand.php b/Command/ResourcesListCommand.php
index ba7acb9f..8f1d3aba 100644
--- a/Command/ResourcesListCommand.php
+++ b/Command/ResourcesListCommand.php
@@ -1,5 +1,7 @@
*
@@ -18,11 +20,11 @@
namespace JMS\TranslationBundle\Command;
+use JMS\TranslationBundle\Util\FileUtils;
use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use JMS\TranslationBundle\Util\FileUtils;
/**
* @author Fabien Potencier
@@ -62,14 +64,9 @@ protected function configure()
$this
->setName('translation:list-resources')
->setDescription('List translation resources available.')
- ->addOption('files', null, InputOption::VALUE_OPTIONAL, 'Display only files')
- ;
+ ->addOption('files', null, InputOption::VALUE_OPTIONAL, 'Display only files');
}
- /**
- * @param \Symfony\Component\Console\Input\InputInterface $input
- * @param \Symfony\Component\Console\Output\OutputInterface $output
- */
protected function execute(InputInterface $input, OutputInterface $output): int
{
$directoriesToSearch = [];
@@ -113,11 +110,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/**
* @param array $dirs
+ *
* @return array
*/
private function retrieveFiles(array $dirs)
{
- $files = array();
+ $files = [];
// Register translation resources
foreach ($dirs as $dir) {
foreach (FileUtils::findTranslationFiles($dir) as $catalogue => $locales) {
@@ -138,21 +136,21 @@ private function retrieveFiles(array $dirs)
private function retrieveDirs()
{
// Discover translation directories
- $dirs = array();
+ $dirs = [];
foreach ($this->bundles as $bundle) {
$reflection = new \ReflectionClass($bundle);
- if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) {
+ if (is_dir($dir = dirname($reflection->getFilename()) . '/Resources/translations')) {
$dirs[] = $dir;
}
}
// TODO: Remove this block when dropping support of Symfony 4
if ($this->rootDir !== null &&
- is_dir($dir = $this->rootDir.'/Resources/translations')) {
+ is_dir($dir = $this->rootDir . '/Resources/translations')) {
$dirs[] = $dir;
}
- if (is_dir($dir = $this->projectDir.'/translations')) {
+ if (is_dir($dir = $this->projectDir . '/translations')) {
$dirs[] = $dir;
}
diff --git a/Controller/ApiController.php b/Controller/ApiController.php
index 81226492..2765c768 100644
--- a/Controller/ApiController.php
+++ b/Controller/ApiController.php
@@ -1,5 +1,7 @@
*
@@ -21,15 +23,15 @@
use JMS\TranslationBundle\Exception\RuntimeException;
use JMS\TranslationBundle\Translation\ConfigFactory;
use JMS\TranslationBundle\Translation\Updater;
-use Symfony\Component\HttpFoundation\Response;
use JMS\TranslationBundle\Util\FileUtils;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
- * @Route("/api")
- *
* @author Johannes M. Schmitt
+ *
+ * @Route("/api")
*/
class ApiController
{
@@ -43,12 +45,6 @@ class ApiController
*/
private $updater;
- /**
- * ApiController constructor.
- *
- * @param ConfigFactory $configFactory
- * @param Updater $updater
- */
public function __construct(ConfigFactory $configFactory, Updater $updater)
{
$this->configFactory = $configFactory;
@@ -56,17 +52,18 @@ public function __construct(ConfigFactory $configFactory, Updater $updater)
}
/**
- * @Route("/configs/{config}/domains/{domain}/locales/{locale}/messages",
- * methods={"PUT"},
- * name="jms_translation_update_message",
- * defaults = {"id" = null},
- * options = {"i18n" = false})
* @param Request $request
* @param string $config
* @param string $domain
* @param string $locale
*
* @return Response
+ *
+ * @Route("/configs/{config}/domains/{domain}/locales/{locale}/messages",
+ * methods={"PUT"},
+ * name="jms_translation_update_message",
+ * defaults = {"id" = null},
+ * options = {"i18n" = false})
*/
public function updateMessageAction(Request $request, $config, $domain, $locale)
{
@@ -86,7 +83,11 @@ public function updateMessageAction(Request $request, $config, $domain, $locale)
[$format, $file] = $files[$domain][$locale];
$this->updater->updateTranslation(
- $file, $format, $domain, $locale, $id,
+ $file->getPathname(),
+ $format,
+ $domain,
+ $locale,
+ $id,
$request->request->get('message')
);
diff --git a/Controller/TranslateController.php b/Controller/TranslateController.php
index 15f4a4f8..8ce17d85 100644
--- a/Controller/TranslateController.php
+++ b/Controller/TranslateController.php
@@ -1,5 +1,7 @@
*
@@ -48,12 +50,6 @@ class TranslateController
*/
private $sourceLanguage;
- /**
- * TranslateController constructor.
- *
- * @param ConfigFactory $configFactory
- * @param LoaderManager $loader
- */
public function __construct(ConfigFactory $configFactory, LoaderManager $loader)
{
$this->configFactory = $configFactory;
@@ -69,10 +65,12 @@ public function setSourceLanguage($lang)
}
/**
- * @Route("/", name="jms_translation_index", options = {"i18n" = false})
- * @Template("@JMSTranslation/Translate/index.html.twig")
* @param Request $request
+ *
* @return array
+ *
+ * @Route("/", name="jms_translation_index", options = {"i18n" = false})
+ * @Template("@JMSTranslation/Translate/index.html.twig")
*/
public function indexAction(Request $request)
{
@@ -111,7 +109,7 @@ public function indexAction(Request $request)
// create alternative messages
// TODO: We should probably also add these to the XLIFF file for external translators,
// and the specification already supports it
- $alternativeMessages = array();
+ $alternativeMessages = [];
foreach ($locales as $otherLocale) {
if ($locale === $otherLocale) {
continue;
@@ -128,7 +126,7 @@ public function indexAction(Request $request)
}
}
- $newMessages = $existingMessages = array();
+ $newMessages = $existingMessages = [];
foreach ($catalogue->getDomain($domain)->all() as $id => $message) {
if ($message->isNew()) {
$newMessages[$id] = $message;
@@ -138,7 +136,7 @@ public function indexAction(Request $request)
$existingMessages[$id] = $message;
}
- return array(
+ return [
'selectedConfig' => $config,
'configs' => $configs,
'selectedDomain' => $domain,
@@ -149,9 +147,9 @@ public function indexAction(Request $request)
'newMessages' => $newMessages,
'existingMessages' => $existingMessages,
'alternativeMessages' => $alternativeMessages,
- 'isWriteable' => is_writeable($files[$domain][$locale][1]),
+ 'isWriteable' => is_writable((string) $files[$domain][$locale][1]),
'file' => (string) $files[$domain][$locale][1],
'sourceLanguage' => $this->sourceLanguage,
- );
+ ];
}
}
diff --git a/DependencyInjection/Compiler/IntegrationPass.php b/DependencyInjection/Compiler/IntegrationPass.php
index 996dcb3b..b25c9b32 100644
--- a/DependencyInjection/Compiler/IntegrationPass.php
+++ b/DependencyInjection/Compiler/IntegrationPass.php
@@ -1,5 +1,7 @@
*
@@ -18,8 +20,8 @@
namespace JMS\TranslationBundle\DependencyInjection\Compiler;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
class IntegrationPass implements CompilerPassInterface
{
diff --git a/DependencyInjection/Compiler/MountDumpersPass.php b/DependencyInjection/Compiler/MountDumpersPass.php
index 86e3e5ac..a53061b2 100644
--- a/DependencyInjection/Compiler/MountDumpersPass.php
+++ b/DependencyInjection/Compiler/MountDumpersPass.php
@@ -1,5 +1,7 @@
*
@@ -20,9 +22,9 @@
use JMS\TranslationBundle\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ChildDefinition;
-use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
class MountDumpersPass implements CompilerPassInterface
{
@@ -32,7 +34,7 @@ public function process(ContainerBuilder $container)
return;
}
- $dumpers = array();
+ $dumpers = [];
$i = 0;
foreach ($container->findTaggedServiceIds('translation.dumper') as $id => $attr) {
if (!isset($attr[0]['alias'])) {
@@ -41,7 +43,7 @@ public function process(ContainerBuilder $container)
$def = new ChildDefinition('jms_translation.dumper.symfony_adapter');
$def->addArgument(new Reference($id))->addArgument($attr[0]['alias']);
- $container->setDefinition($id = 'jms_translation.dumper.wrapped_symfony_dumper.'.($i++), $def);
+ $container->setDefinition($id = 'jms_translation.dumper.wrapped_symfony_dumper.' . ($i++), $def);
$dumpers[$attr[0]['alias']] = new Reference($id);
}
@@ -56,7 +58,6 @@ public function process(ContainerBuilder $container)
$container
->getDefinition('jms_translation.file_writer')
- ->addArgument($dumpers)
- ;
+ ->addArgument($dumpers);
}
}
diff --git a/DependencyInjection/Compiler/MountExtractorsPass.php b/DependencyInjection/Compiler/MountExtractorsPass.php
index 21656520..7b40c7e5 100644
--- a/DependencyInjection/Compiler/MountExtractorsPass.php
+++ b/DependencyInjection/Compiler/MountExtractorsPass.php
@@ -1,5 +1,7 @@
*
@@ -19,9 +21,9 @@
namespace JMS\TranslationBundle\DependencyInjection\Compiler;
use JMS\TranslationBundle\Exception\RuntimeException;
-use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
class MountExtractorsPass implements CompilerPassInterface
{
@@ -32,7 +34,7 @@ public function process(ContainerBuilder $container)
}
$def = $container->getDefinition('jms_translation.extractor_manager');
- $extractors = array();
+ $extractors = [];
foreach ($container->findTaggedServiceIds('jms_translation.extractor') as $id => $attr) {
if (!isset($attr[0]['alias'])) {
throw new RuntimeException(sprintf('The "alias" attribute must be set for tag "jms_translation.extractor" of service "%s".', $id));
diff --git a/DependencyInjection/Compiler/MountFileVisitorsPass.php b/DependencyInjection/Compiler/MountFileVisitorsPass.php
index 3226197c..d303e7ca 100644
--- a/DependencyInjection/Compiler/MountFileVisitorsPass.php
+++ b/DependencyInjection/Compiler/MountFileVisitorsPass.php
@@ -1,5 +1,7 @@
*
@@ -18,9 +20,9 @@
namespace JMS\TranslationBundle\DependencyInjection\Compiler;
-use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
class MountFileVisitorsPass implements CompilerPassInterface
{
@@ -31,7 +33,7 @@ public function process(ContainerBuilder $container)
}
$def = $container->getDefinition('jms_translation.extractor.file_extractor');
- $visitors = array();
+ $visitors = [];
foreach ($container->findTaggedServiceIds('jms_translation.file_visitor') as $id => $attr) {
$visitors[] = new Reference($id);
}
diff --git a/DependencyInjection/Compiler/MountLoadersPass.php b/DependencyInjection/Compiler/MountLoadersPass.php
index 97a84c20..f69ad68e 100644
--- a/DependencyInjection/Compiler/MountLoadersPass.php
+++ b/DependencyInjection/Compiler/MountLoadersPass.php
@@ -1,5 +1,7 @@
*
@@ -20,19 +22,19 @@
use JMS\TranslationBundle\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ChildDefinition;
-use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
class MountLoadersPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
- if (!$container->hasDefinition(('jms_translation.loader_manager'))) {
+ if (!$container->hasDefinition('jms_translation.loader_manager')) {
return;
}
- $loaders = array();
+ $loaders = [];
$i = 0;
foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attr) {
if (!isset($attr[0]['alias'])) {
@@ -41,7 +43,7 @@ public function process(ContainerBuilder $container)
$def = new ChildDefinition('jms_translation.loader.symfony_adapter');
$def->addArgument(new Reference($id));
- $container->setDefinition($id = 'jms_translation.loader.wrapped_symfony_loader.'.($i++), $def);
+ $container->setDefinition($id = 'jms_translation.loader.wrapped_symfony_loader.' . ($i++), $def);
$loaders[$attr[0]['alias']] = new Reference($id);
if (isset($attr[0]['legacy_alias'])) {
@@ -59,7 +61,6 @@ public function process(ContainerBuilder $container)
$container
->getDefinition('jms_translation.loader_manager')
- ->addArgument($loaders)
- ;
+ ->addArgument($loaders);
}
}
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 83aa392e..01d694be 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -1,5 +1,7 @@
*
@@ -19,8 +21,8 @@
namespace JMS\TranslationBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
class Configuration implements ConfigurationInterface
{
@@ -42,7 +44,7 @@ public function getConfigTreeBuilder()
} else {
$rootNode = $tb->getRootNode();
}
-
+
$rootNode
->fixXmlConfig('config')
->children()
@@ -75,7 +77,7 @@ public function getConfigTreeBuilder()
->requiresAtLeastOneElement()
->prototype('scalar')
->validate()
- ->always(function ($v) use ($c) {
+ ->always(static function ($v) use ($c) {
$v = str_replace(DIRECTORY_SEPARATOR, '/', $v);
if ('@' === $v[0]) {
@@ -91,7 +93,7 @@ public function getConfigTreeBuilder()
}
$ref = new \ReflectionClass($bundles[$bundleName]);
- $v = false === $pos ? dirname($ref->getFileName()) : dirname($ref->getFileName()).substr($v, $pos);
+ $v = false === $pos ? dirname($ref->getFileName()) : dirname($ref->getFileName()) . substr($v, $pos);
}
if (!is_dir($v)) {
@@ -125,8 +127,7 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
- ->end()
- ;
+ ->end();
return $tb;
}
diff --git a/DependencyInjection/JMSTranslationExtension.php b/DependencyInjection/JMSTranslationExtension.php
index d692ecbe..5cf981f0 100644
--- a/DependencyInjection/JMSTranslationExtension.php
+++ b/DependencyInjection/JMSTranslationExtension.php
@@ -1,5 +1,7 @@
*
@@ -18,12 +20,12 @@
namespace JMS\TranslationBundle\DependencyInjection;
-use Symfony\Component\DependencyInjection\Definition;
+use JMS\TranslationBundle\Translation\ConfigBuilder;
use Symfony\Component\Config\FileLocator;
-use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Definition;
+use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
-use JMS\TranslationBundle\Translation\ConfigBuilder;
class JMSTranslationExtension extends Extension
{
@@ -31,7 +33,7 @@ public function load(array $configs, ContainerBuilder $container)
{
$config = $this->processConfiguration(new Configuration($container), $configs);
- $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
$loader->load('console.xml');
@@ -39,64 +41,64 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('jms_translation.locales', $config['locales']);
foreach ($config['dumper'] as $option => $value) {
- $container->setParameter("jms_translation.dumper.{$option}", $value);
+ $container->setParameter("jms_translation.dumper.${option}", $value);
}
- $requests = array();
+ $requests = [];
foreach ($config['configs'] as $name => $extractConfig) {
$def = new Definition(ConfigBuilder::class);
- $def->addMethodCall('setTranslationsDir', array($extractConfig['output_dir']));
- $def->addMethodCall('setScanDirs', array($extractConfig['dirs']));
+ $def->addMethodCall('setTranslationsDir', [$extractConfig['output_dir']]);
+ $def->addMethodCall('setScanDirs', [$extractConfig['dirs']]);
if (isset($extractConfig['ignored_domains'])) {
- $ignored = array();
+ $ignored = [];
foreach ($extractConfig['ignored_domains'] as $domain) {
$ignored[$domain] = true;
}
- $def->addMethodCall('setIgnoredDomains', array($ignored));
+ $def->addMethodCall('setIgnoredDomains', [$ignored]);
}
if (isset($extractConfig['domains'])) {
- $domains = array();
+ $domains = [];
foreach ($extractConfig['domains'] as $domain) {
$domains[$domain] = true;
}
- $def->addMethodCall('setDomains', array($domains));
+ $def->addMethodCall('setDomains', [$domains]);
}
if (isset($extractConfig['extractors'])) {
- $extractors = array();
+ $extractors = [];
foreach ($extractConfig['extractors'] as $alias) {
$extractors[$alias] = true;
}
- $def->addMethodCall('setEnabledExtractors', array($extractors));
+ $def->addMethodCall('setEnabledExtractors', [$extractors]);
}
if (isset($extractConfig['excluded_dirs'])) {
- $def->addMethodCall('setExcludedDirs', array($extractConfig['excluded_dirs']));
+ $def->addMethodCall('setExcludedDirs', [$extractConfig['excluded_dirs']]);
}
if (isset($extractConfig['excluded_names'])) {
- $def->addMethodCall('setExcludedNames', array($extractConfig['excluded_names']));
+ $def->addMethodCall('setExcludedNames', [$extractConfig['excluded_names']]);
}
if (isset($extractConfig['output_format'])) {
- $def->addMethodCall('setOutputFormat', array($extractConfig['output_format']));
+ $def->addMethodCall('setOutputFormat', [$extractConfig['output_format']]);
}
if (isset($extractConfig['default_output_format'])) {
- $def->addMethodCall('setDefaultOutputFormat', array($extractConfig['default_output_format']));
+ $def->addMethodCall('setDefaultOutputFormat', [$extractConfig['default_output_format']]);
}
if (isset($extractConfig['keep'])) {
- $def->addMethodCall('setKeepOldTranslations', array($extractConfig['keep']));
+ $def->addMethodCall('setKeepOldTranslations', [$extractConfig['keep']]);
}
if (isset($extractConfig['external_translations_dirs'])) {
- $def->addMethodCall('setLoadResources', array($extractConfig['external_translations_dirs']));
+ $def->addMethodCall('setLoadResources', [$extractConfig['external_translations_dirs']]);
}
$requests[$name] = $def;
@@ -104,7 +106,6 @@ public function load(array $configs, ContainerBuilder $container)
$container
->getDefinition('jms_translation.config_factory')
- ->addArgument($requests)
- ;
+ ->addArgument($requests);
}
}
diff --git a/Exception/Exception.php b/Exception/Exception.php
index 0991f7b9..535aeaf0 100644
--- a/Exception/Exception.php
+++ b/Exception/Exception.php
@@ -1,5 +1,7 @@
*
diff --git a/Exception/InvalidArgumentException.php b/Exception/InvalidArgumentException.php
index 04ef6cf9..c36fcd49 100644
--- a/Exception/InvalidArgumentException.php
+++ b/Exception/InvalidArgumentException.php
@@ -1,5 +1,7 @@
*
diff --git a/Exception/RuntimeException.php b/Exception/RuntimeException.php
index fcef20bf..65d172aa 100644
--- a/Exception/RuntimeException.php
+++ b/Exception/RuntimeException.php
@@ -1,5 +1,7 @@
*
diff --git a/Logger/LoggerAwareInterface.php b/Logger/LoggerAwareInterface.php
index 82e7715c..37513ad5 100644
--- a/Logger/LoggerAwareInterface.php
+++ b/Logger/LoggerAwareInterface.php
@@ -1,5 +1,7 @@
*
@@ -25,8 +27,5 @@
*/
interface LoggerAwareInterface
{
- /**
- * @param LoggerInterface $logger
- */
public function setLogger(LoggerInterface $logger);
}
diff --git a/Logger/OutputLogger.php b/Logger/OutputLogger.php
index 83edd6a4..484bab9e 100644
--- a/Logger/OutputLogger.php
+++ b/Logger/OutputLogger.php
@@ -1,5 +1,7 @@
*
@@ -18,20 +20,20 @@
namespace JMS\TranslationBundle\Logger;
-use Symfony\Component\Console\Output\OutputInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\Console\Output\OutputInterface;
class OutputLogger implements LoggerInterface
{
- const EMERG = 1;
- const ALERT = 2;
- const CRIT = 4;
- const ERR = 8;
- const WARN = 16;
- const NOTICE = 32;
- const INFO = 64;
- const DEBUG = 128;
- const ALL = 255;
+ public const EMERG = 1;
+ public const ALERT = 2;
+ public const CRIT = 4;
+ public const ERR = 8;
+ public const WARN = 16;
+ public const NOTICE = 32;
+ public const INFO = 64;
+ public const DEBUG = 128;
+ public const ALL = 255;
/**
* @var OutputInterface
@@ -43,10 +45,6 @@ class OutputLogger implements LoggerInterface
*/
private $level = self::ALL;
- /**
- * OutputLogger constructor.
- * @param OutputInterface $output
- */
public function __construct(OutputInterface $output)
{
$this->output = $output;
@@ -63,9 +61,10 @@ public function setLevel($level)
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function emergency($message, array $context = array())
+ public function emergency($message, array $context = [])
{
$this->emerg($message, $context);
}
@@ -73,37 +72,40 @@ public function emergency($message, array $context = array())
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function emerg($message, array $context = array())
+ public function emerg($message, array $context = [])
{
if (0 === ($this->level & self::EMERG)) {
return;
}
- $this->output->writeln(''.$message.'');
+ $this->output->writeln('' . $message . '');
}
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function alert($message, array $context = array())
+ public function alert($message, array $context = [])
{
if (0 === ($this->level & self::ALERT)) {
return;
}
- $this->output->writeln(''.$message.'');
+ $this->output->writeln('' . $message . '');
}
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function critical($message, array $context = array())
+ public function critical($message, array $context = [])
{
$this->crit($message, $context);
}
@@ -111,23 +113,25 @@ public function critical($message, array $context = array())
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function crit($message, array $context = array())
+ public function crit($message, array $context = [])
{
if (0 === ($this->level & self::CRIT)) {
return;
}
- $this->output->writeln(''.$message.'');
+ $this->output->writeln('' . $message . '');
}
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function error($message, array $context = array())
+ public function error($message, array $context = [])
{
$this->err($message, $context);
}
@@ -135,33 +139,36 @@ public function error($message, array $context = array())
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function err($message, array $context = array())
+ public function err($message, array $context = [])
{
if (0 === ($this->level & self::ERR)) {
return;
}
- $this->output->writeln(''.$message.'');
+ $this->output->writeln('' . $message . '');
}
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function warning($message, array $context = array())
+ public function warning($message, array $context = [])
{
$this->warn($message, $context);
}
/**
- * @param $message
+ * @param string $message
* @param array $context
+ *
* @return void
*/
- public function warn($message, array $context = array())
+ public function warn($message, array $context = [])
{
if (0 === ($this->level & self::WARN)) {
return;
@@ -173,9 +180,10 @@ public function warn($message, array $context = array())
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function notice($message, array $context = array())
+ public function notice($message, array $context = [])
{
if (0 === ($this->level & self::NOTICE)) {
return;
@@ -187,9 +195,10 @@ public function notice($message, array $context = array())
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function info($message, array $context = array())
+ public function info($message, array $context = [])
{
if (0 === ($this->level & self::INFO)) {
return;
@@ -201,9 +210,10 @@ public function info($message, array $context = array())
/**
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function debug($message, array $context = array())
+ public function debug($message, array $context = [])
{
if (0 === ($this->level & self::DEBUG)) {
return;
@@ -216,9 +226,10 @@ public function debug($message, array $context = array())
* @param mixed $level
* @param string $message
* @param array $context
+ *
* @return void
*/
- public function log($level, $message, array $context = array())
+ public function log($level, $message, array $context = [])
{
if (0 === ($this->level & $level)) {
return;
diff --git a/Model/FileSource.php b/Model/FileSource.php
index c6c29258..11448a24 100644
--- a/Model/FileSource.php
+++ b/Model/FileSource.php
@@ -1,5 +1,7 @@
*
@@ -36,10 +38,9 @@ class FileSource implements SourceInterface
private $column;
/**
- * FileSource constructor.
- * @param $path string
- * @param null|int $line
- * @param null|int $column
+ * @param string $path
+ * @param int|null $line
+ * @param int|null $column
*/
public function __construct($path, $line = null, $column = null)
{
@@ -57,7 +58,7 @@ public function getPath()
}
/**
- * @return null|int
+ * @return int|null
*/
public function getLine()
{
@@ -65,7 +66,7 @@ public function getLine()
}
/**
- * @return null|int
+ * @return int|null
*/
public function getColumn()
{
@@ -74,6 +75,7 @@ public function getColumn()
/**
* @param SourceInterface $source
+ *
* @return bool
*/
public function equals(SourceInterface $source)
@@ -90,11 +92,7 @@ public function equals(SourceInterface $source)
return false;
}
- if ($this->column !== $source->getColumn()) {
- return false;
- }
-
- return true;
+ return $this->column === $source->getColumn();
}
/**
@@ -105,10 +103,10 @@ public function __toString()
$str = $this->path;
if (null !== $this->line) {
- $str .= ' on line '.$this->line;
+ $str .= ' on line ' . $this->line;
if (null !== $this->column) {
- $str .= ' at column '.$this->column;
+ $str .= ' at column ' . $this->column;
}
}
diff --git a/Model/Message.php b/Model/Message.php
index 2c33452a..b11fe1a6 100644
--- a/Model/Message.php
+++ b/Model/Message.php
@@ -1,5 +1,7 @@
*
@@ -70,17 +72,17 @@ class Message
*
* @var array
*/
- private $sources = array();
+ private $sources = [];
/**
- * @static
+ * @deprecated Will be removed in 2.0. Use the FileSourceFactory
*
- * @param $id
+ * @param string $id
* @param string $domain
*
* @return Message
*
- * @deprecated Will be removed in 2.0. Use the FileSourceFactory
+ * @static
*/
public static function forThisFile($id, $domain = 'messages')
{
@@ -95,12 +97,12 @@ public static function forThisFile($id, $domain = 'messages')
}
/**
- * @static
- *
- * @param $id
+ * @param string $id
* @param string $domain
*
* @return Message
+ *
+ * @static
*/
public static function create($id, $domain = 'messages')
{
@@ -168,7 +170,7 @@ public function isNew()
*/
public function getLocaleString()
{
- return $this->localeString !== null ? $this->localeString : ($this->new ? ($this->desc !== null ? $this->desc : $this->id) : '');
+ return $this->localeString ?? ($this->new ? ($this->desc ?? $this->id) : '');
}
/**
@@ -256,7 +258,7 @@ public function setLocaleString($str)
return $this;
}
- public function setSources(array $sources = array())
+ public function setSources(array $sources = [])
{
$this->sources = $sources;
@@ -318,9 +320,9 @@ public function merge(Message $message)
* Do not use this if you want to merge a message from an extracted catalogue.
* In these cases, use merge() instead.
*
- * @param Message $message
- *
* @deprecated not in use atm
+ *
+ * @param Message $message
*/
public function mergeExisting(Message $message)
{
@@ -351,9 +353,9 @@ public function mergeExisting(Message $message)
* The result of both methods is the same, except that the result will end up in the existing message,
* instead of the scanned message, so extra information read from the existing message is not discarded.
*
- * @param Message $message
- *
* @author Dieter Peeters
+ *
+ * @param Message $message
*/
public function mergeScanned(Message $message)
{
@@ -369,7 +371,7 @@ public function mergeScanned(Message $message)
$this->desc = $message->getDesc();
}
- $this->sources = array();
+ $this->sources = [];
foreach ($message->getSources() as $source) {
$this->addSource($source);
}
diff --git a/Model/Message/XliffMessage.php b/Model/Message/XliffMessage.php
index c6b9f855..d272d19b 100644
--- a/Model/Message/XliffMessage.php
+++ b/Model/Message/XliffMessage.php
@@ -1,5 +1,7 @@
*
@@ -23,34 +25,34 @@
/**
* Represents an _existing_ message from an XLIFF-file.
- *
+ *
* Currently supports preservation of:
* - note-elements (as child of trans-unit element)
* - attribute trans-unit['approved']
* - attribute target['state']
- *
- * @see http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html
*
* @author Dieter Peeters
+ *
+ * @see http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html
*/
class XliffMessage extends Message
{
- protected static $states = array();
- const STATE_NONE = null;
- const STATE_FINAL = 'final';
- const STATE_NEEDS_ADAPTATION = 'needs-adaptation';
- const STATE_NEEDS_L10N = 'needs-l10n';
- const STATE_NEEDS_REVIEW_ADAPTATION = 'needs-review-adaptation';
- const STATE_NEEDS_REVIEW_L10N = 'needs-review-l10n';
- const STATE_NEEDS_REVIEW_TRANSLATION = 'needs-review-translation';
- const STATE_NEEDS_TRANSLATION = 'needs-translation';
- const STATE_NEW = 'new';
- const STATE_SIGNED_OFF = 'signed-off';
- const STATE_TRANSLATED = 'translated';
+ protected static $states = [];
+ public const STATE_NONE = null;
+ public const STATE_FINAL = 'final';
+ public const STATE_NEEDS_ADAPTATION = 'needs-adaptation';
+ public const STATE_NEEDS_L10N = 'needs-l10n';
+ public const STATE_NEEDS_REVIEW_ADAPTATION = 'needs-review-adaptation';
+ public const STATE_NEEDS_REVIEW_L10N = 'needs-review-l10n';
+ public const STATE_NEEDS_REVIEW_TRANSLATION = 'needs-review-translation';
+ public const STATE_NEEDS_TRANSLATION = 'needs-translation';
+ public const STATE_NEW = 'new';
+ public const STATE_SIGNED_OFF = 'signed-off';
+ public const STATE_TRANSLATED = 'translated';
protected $approved = false;
protected $state;
- protected $notes = array();
+ protected $notes = [];
/**
* @return bool
@@ -61,7 +63,7 @@ public function isApproved()
}
/**
- * @param $approved
+ * @param bool $approved
*
* @return $this
*/
@@ -151,16 +153,16 @@ public function getNotes()
}
/**
- * @param $text
+ * @param string $text
* @param null $from
*
* @return $this
*/
public function addNote($text, $from = null)
{
- $note = array(
+ $note = [
'text' => (string) $text,
- );
+ ];
if (isset($from)) {
$note['from'] = (string) $from;
}
@@ -174,7 +176,7 @@ public function addNote($text, $from = null)
*
* @return $this
*/
- public function setNotes(array $notes = array())
+ public function setNotes(array $notes = [])
{
$this->notes = $notes;
diff --git a/Model/Message/XliffMessageState.php b/Model/Message/XliffMessageState.php
index f0bef7cc..51599053 100755
--- a/Model/Message/XliffMessageState.php
+++ b/Model/Message/XliffMessageState.php
@@ -1,5 +1,7 @@
*
@@ -27,15 +29,15 @@
*/
class XliffMessageState extends Message
{
- const STATE_NONE = null;
- const STATE_FINAL = 'final';
- const STATE_NEEDS_ADAPTATION = 'needs-adaptation';
- const STATE_NEEDS_L10N = 'needs-l10n';
- const STATE_NEEDS_REVIEW_ADAPTATION = 'needs-review-adaptation';
- const STATE_NEEDS_REVIEW_L10N = 'needs-review-l10n';
- const STATE_NEEDS_REVIEW_TRANSLATION = 'needs-review-translation';
- const STATE_NEEDS_TRANSLATION = 'needs-translation';
- const STATE_NEW = 'new';
- const STATE_SIGNED_OFF = 'signed-off';
- const STATE_TRANSLATED = 'translated';
+ public const STATE_NONE = null;
+ public const STATE_FINAL = 'final';
+ public const STATE_NEEDS_ADAPTATION = 'needs-adaptation';
+ public const STATE_NEEDS_L10N = 'needs-l10n';
+ public const STATE_NEEDS_REVIEW_ADAPTATION = 'needs-review-adaptation';
+ public const STATE_NEEDS_REVIEW_L10N = 'needs-review-l10n';
+ public const STATE_NEEDS_REVIEW_TRANSLATION = 'needs-review-translation';
+ public const STATE_NEEDS_TRANSLATION = 'needs-translation';
+ public const STATE_NEW = 'new';
+ public const STATE_SIGNED_OFF = 'signed-off';
+ public const STATE_TRANSLATED = 'translated';
}
diff --git a/Model/MessageCatalogue.php b/Model/MessageCatalogue.php
index 7f6a3ce7..d2bdeeb9 100644
--- a/Model/MessageCatalogue.php
+++ b/Model/MessageCatalogue.php
@@ -1,5 +1,7 @@
*
@@ -42,11 +44,8 @@ class MessageCatalogue
/**
* @var array
*/
- private $domains = array();
+ private $domains = [];
- /**
- * @param $locale
- */
public function setLocale($locale)
{
$this->locale = $locale;
@@ -60,33 +59,27 @@ public function getLocale()
return $this->locale;
}
- /**
- * @param Message $message
- */
public function add(Message $message)
{
$this
->getOrCreateDomain($message->getDomain())
- ->add($message)
- ;
+ ->add($message);
}
- /**
- * @param Message $message
- */
public function set(Message $message, $force = false)
{
$this
->getOrCreateDomain($message->getDomain())
- ->set($message, $force)
- ;
+ ->set($message, $force);
}
/**
- * @param $id
- * @param $domain
- * @throws \JMS\TranslationBundle\Exception\InvalidArgumentException
+ * @param string $id
+ * @param string $domain
+ *
* @return Message
+ *
+ * @throws InvalidArgumentException
*/
public function get($id, $domain = 'messages')
{
@@ -95,6 +88,7 @@ public function get($id, $domain = 'messages')
/**
* @param Message $message
+ *
* @return bool
*/
public function has(Message $message)
@@ -106,9 +100,6 @@ public function has(Message $message)
return $this->getDomain($message->getDomain())->has($message->getId());
}
- /**
- * @param MessageCatalogue $catalogue
- */
public function merge(MessageCatalogue $catalogue)
{
foreach ($catalogue->getDomains() as $name => $domainCatalogue) {
@@ -118,6 +109,7 @@ public function merge(MessageCatalogue $catalogue)
/**
* @param string $domain
+ *
* @return bool
*/
public function hasDomain($domain)
@@ -127,6 +119,7 @@ public function hasDomain($domain)
/**
* @param string $domain
+ *
* @return MessageCollection
*/
public function getDomain($domain)
@@ -148,6 +141,7 @@ public function getDomains()
/**
* @param string $domain
+ *
* @return MessageCollection
*/
private function getOrCreateDomain($domain)
diff --git a/Model/MessageCollection.php b/Model/MessageCollection.php
index d412418e..907a244b 100644
--- a/Model/MessageCollection.php
+++ b/Model/MessageCollection.php
@@ -1,5 +1,7 @@
*
@@ -39,11 +41,8 @@ class MessageCollection
/**
* @var array
*/
- private $messages = array();
+ private $messages = [];
- /**
- * @param MessageCatalogue $catalogue
- */
public function setCatalogue(MessageCatalogue $catalogue)
{
$this->catalogue = $catalogue;
@@ -57,9 +56,6 @@ public function getCatalogue()
return $this->catalogue;
}
- /**
- * @param Message $message
- */
public function add(Message $message)
{
if (isset($this->messages[$id = $message->getId()])) {
@@ -72,9 +68,6 @@ public function add(Message $message)
$this->messages[$id] = $message;
}
- /**
- * @param Message $message
- */
public function set(Message $message, $force = false)
{
$id = $message->getId();
@@ -86,9 +79,11 @@ public function set(Message $message, $force = false)
}
/**
- * @param $id
+ * @param string $id
+ *
* @return mixed
- * @throws \JMS\TranslationBundle\Exception\InvalidArgumentException
+ *
+ * @throws InvalidArgumentException
*/
public function get($id)
{
@@ -100,8 +95,9 @@ public function get($id)
}
/**
- * @param $id
- * @return Boolean
+ * @param string $id
+ *
+ * @return bool
*/
public function has($id)
{
@@ -109,8 +105,9 @@ public function has($id)
}
/**
- * @param $callback
- * @throws \JMS\TranslationBundle\Exception\InvalidArgumentException
+ * @param callable $callback
+ *
+ * @throws InvalidArgumentException
*/
public function sort($callback)
{
@@ -122,8 +119,9 @@ public function sort($callback)
}
/**
- * @param $callback
- * @throws \JMS\TranslationBundle\Exception\InvalidArgumentException
+ * @param callable $callback
+ *
+ * @throws InvalidArgumentException
*/
public function filter($callback)
{
@@ -150,9 +148,6 @@ public function all()
return $this->messages;
}
- /**
- * @param MessageCollection $domain
- */
public function merge(MessageCollection $domain)
{
foreach ($domain->all() as $id => $message) {
@@ -160,16 +155,12 @@ public function merge(MessageCollection $domain)
}
}
- /**
- * @param Message $oldMessage
- * @param Message $newMessage
- */
private function checkConsistency(Message $oldMessage, Message $newMessage)
{
$oldDesc = $oldMessage->getDesc();
$newDesc = $newMessage->getDesc();
- if (0 < strlen($oldDesc) && 0 < strlen($newDesc) && $oldDesc != $newDesc) {
+ if (0 < strlen((string) $oldDesc) && 0 < strlen((string) $newDesc) && $oldDesc !== $newDesc) {
throw new \RuntimeException(sprintf("The message '%s' exists with two different descs: '%s' in %s, and '%s' in %s", $oldMessage->getId(), $oldMessage->getDesc(), current($oldMessage->getSources()), $newMessage->getDesc(), current($newMessage->getSources())));
}
}
diff --git a/Model/SourceInterface.php b/Model/SourceInterface.php
index ac926739..1a7a8d62 100644
--- a/Model/SourceInterface.php
+++ b/Model/SourceInterface.php
@@ -1,5 +1,7 @@
*
@@ -21,5 +23,6 @@
interface SourceInterface
{
public function equals(SourceInterface $source);
+
public function __toString();
}
diff --git a/Tests/Functional/Fixture/TestBundle/Controller/AppleController.php b/Tests/Functional/Fixture/TestBundle/Controller/AppleController.php
index fbe6f1b8..ea7af4d4 100644
--- a/Tests/Functional/Fixture/TestBundle/Controller/AppleController.php
+++ b/Tests/Functional/Fixture/TestBundle/Controller/AppleController.php
@@ -8,8 +8,9 @@
use Symfony\Component\Routing\Annotation\Route;
/**
- * @Route("/apples")
* @author Johannes
+ *
+ * @Route("/apples")
*/
class AppleController
{
diff --git a/Tests/Model/FileSourceTest.php b/Tests/Model/FileSourceTest.php
index 74d5d531..bd6b2776 100644
--- a/Tests/Model/FileSourceTest.php
+++ b/Tests/Model/FileSourceTest.php
@@ -21,6 +21,7 @@
namespace JMS\TranslationBundle\Tests\Model;
use JMS\TranslationBundle\Model\FileSource;
+use JMS\TranslationBundle\Model\SourceInterface;
use PHPUnit\Framework\TestCase;
class FileSourceTest extends TestCase
@@ -104,7 +105,7 @@ public function getEqualityTests()
false,
];
- $source = $this->createMock('JMS\TranslationBundle\Model\SourceInterface');
+ $source = $this->createMock(SourceInterface::class);
$source
->expects($this->once())
->method('equals')
diff --git a/Tests/Model/Message/XliffMessageTest.php b/Tests/Model/Message/XliffMessageTest.php
index 2000d7f4..12c5060d 100644
--- a/Tests/Model/Message/XliffMessageTest.php
+++ b/Tests/Model/Message/XliffMessageTest.php
@@ -23,6 +23,7 @@
use JMS\TranslationBundle\Model\FileSource;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\Message\XliffMessage;
+use JMS\TranslationBundle\Model\SourceInterface;
use JMS\TranslationBundle\Tests\Model\MessageTest;
class XliffMessageTest extends MessageTest
@@ -108,13 +109,13 @@ public function testMerge()
$messageWrite = new XliffMessage('foo');
$messageWrite->setDesc('foo');
$messageWrite->setMeaning('foo');
- $messageWrite->addSource($s1 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
+ $messageWrite->addSource($s1 = $this->createMock(SourceInterface::class));
$messageRead = new XliffMessage('foo');
$messageRead->setDesc('bar');
$messageRead->setApproved(true);
$messageRead->setState(XliffMessage::STATE_TRANSLATED);
- $messageRead->addSource($s2 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
+ $messageRead->addSource($s2 = $this->createMock(SourceInterface::class));
$messageRead2 = new Message('foo');
$messageRead2->setDesc('bar');
diff --git a/Tests/Model/MessageCatalogueTest.php b/Tests/Model/MessageCatalogueTest.php
index f67131c8..9cdf629e 100644
--- a/Tests/Model/MessageCatalogueTest.php
+++ b/Tests/Model/MessageCatalogueTest.php
@@ -22,6 +22,7 @@
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
+use JMS\TranslationBundle\Model\MessageCollection;
use PHPUnit\Framework\TestCase;
class MessageCatalogueTest extends TestCase
@@ -76,7 +77,7 @@ public function testGetDomain()
$catalogue->add(new Message('foo'));
$col = $catalogue->getDomain('messages');
- $this->assertInstanceOf('JMS\TranslationBundle\Model\MessageCollection', $col);
+ $this->assertInstanceOf(MessageCollection::class, $col);
$this->assertEquals(['foo'], array_keys($col->all()));
}
@@ -95,7 +96,7 @@ public function testGetDomains()
$cat->add(new Message('foo', 'foo'));
$this->assertEquals(['messages', 'foo'], array_keys($domains = $cat->getDomains()));
- $this->assertInstanceOf('JMS\TranslationBundle\Model\MessageCollection', $domains['foo']);
+ $this->assertInstanceOf(MessageCollection::class, $domains['foo']);
}
public function testMerge()
diff --git a/Tests/Model/MessageCollectionTest.php b/Tests/Model/MessageCollectionTest.php
index 3fbef019..39e15c3f 100644
--- a/Tests/Model/MessageCollectionTest.php
+++ b/Tests/Model/MessageCollectionTest.php
@@ -37,9 +37,9 @@ public function testAdd()
public function testAddMerges()
{
- $m2 = $this->createMock('JMS\TranslationBundle\Model\Message');
+ $m2 = $this->createMock(Message::class);
- $m1 = $this->createMock('JMS\TranslationBundle\Model\Message');
+ $m1 = $this->createMock(Message::class);
$m1->expects($this->once())
->method('merge')
->with($m2);
@@ -77,12 +77,12 @@ public function testSet()
public function testSetDoesNotMerge()
{
- $m2 = $this->createMock('JMS\TranslationBundle\Model\Message');
+ $m2 = $this->createMock(Message::class);
$m2
->method('getId')
->willReturn('foo');
- $m1 = $this->createMock('JMS\TranslationBundle\Model\Message');
+ $m1 = $this->createMock(Message::class);
$m1->expects($this->never())
->method('merge');
$m1
diff --git a/Tests/Model/MessageTest.php b/Tests/Model/MessageTest.php
index 2616eae9..2934f7a4 100644
--- a/Tests/Model/MessageTest.php
+++ b/Tests/Model/MessageTest.php
@@ -22,6 +22,7 @@
use JMS\TranslationBundle\Model\FileSource;
use JMS\TranslationBundle\Model\Message;
+use JMS\TranslationBundle\Model\SourceInterface;
use PHPUnit\Framework\TestCase;
class MessageTest extends TestCase
@@ -30,7 +31,7 @@ public function testCreate()
{
$message = Message::create('id', 'foo');
- $this->assertInstanceOf('JMS\TranslationBundle\Model\Message', $message);
+ $this->assertInstanceOf(Message::class, $message);
$this->assertEquals('id', $message->getId());
$this->assertEquals('foo', $message->getDomain());
}
@@ -39,7 +40,7 @@ public function testForThisFile()
{
$message = Message::forThisFile('foo', 'bar');
- $this->assertInstanceOf('JMS\TranslationBundle\Model\Message', $message);
+ $this->assertInstanceOf(Message::class, $message);
$this->assertEquals('foo', $message->getId());
$this->assertEquals('bar', $message->getDomain());
@@ -82,9 +83,9 @@ public function testGetSources()
$message = new Message('foo');
$this->assertEquals([], $message->getSources());
- $this->assertSame($message, $message->addSource($source = $this->createMock('JMS\TranslationBundle\Model\SourceInterface')));
+ $this->assertSame($message, $message->addSource($source = $this->createMock(SourceInterface::class)));
$this->assertSame([$source], $message->getSources());
- $this->assertSame($message, $message->setSources([$source2 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface')]));
+ $this->assertSame($message, $message->setSources([$source2 = $this->createMock(SourceInterface::class)]));
$this->assertSame([$source2], $message->getSources());
}
@@ -93,11 +94,11 @@ public function testMerge()
$message = new Message('foo');
$message->setDesc('foo');
$message->setMeaning('foo');
- $message->addSource($s1 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
+ $message->addSource($s1 = $this->createMock(SourceInterface::class));
$message2 = new Message('foo');
$message2->setDesc('bar');
- $message2->addSource($s2 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
+ $message2->addSource($s2 = $this->createMock(SourceInterface::class));
$message->merge($message2);
@@ -111,11 +112,11 @@ public function testMergeRememberDesc()
$message = new Message('foo_id');
$message->setDesc('foo_desc');
$message->setMeaning('foo_meaning');
- $message->addSource($s1 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
+ $message->addSource($s1 = $this->createMock(SourceInterface::class));
$message2 = new Message('foo_id');
$message2->setMeaning('bar_meaning');
- $message2->addSource($s2 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
+ $message2->addSource($s2 = $this->createMock(SourceInterface::class));
$message->merge($message2);
@@ -179,9 +180,9 @@ public function hasSource()
{
$message = new Message('foo');
- $s2 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface');
+ $s2 = $this->createMock(SourceInterface::class);
- $s1 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface');
+ $s1 = $this->createMock(SourceInterface::class);
$s1
->expects($this->once())
->method('equals')
diff --git a/Tests/Translation/Dumper/ArrayStructureDumperTest.php b/Tests/Translation/Dumper/ArrayStructureDumperTest.php
index 071405e1..91407c7b 100644
--- a/Tests/Translation/Dumper/ArrayStructureDumperTest.php
+++ b/Tests/Translation/Dumper/ArrayStructureDumperTest.php
@@ -22,6 +22,7 @@
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
+use JMS\TranslationBundle\Translation\Dumper\ArrayStructureDumper;
use PHPUnit\Framework\TestCase;
class ArrayStructureDumperTest extends TestCase
@@ -50,6 +51,6 @@ public function testPathWithSubPath()
private function getDumper()
{
- return $this->getMockForAbstractClass('JMS\TranslationBundle\Translation\Dumper\ArrayStructureDumper');
+ return $this->getMockForAbstractClass(ArrayStructureDumper::class);
}
}
diff --git a/Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php b/Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php
index 5726ecbe..56fe06a2 100644
--- a/Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php
+++ b/Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php
@@ -21,6 +21,9 @@
namespace JMS\TranslationBundle\Tests\Translation\Extractor\File;
use Doctrine\Common\Annotations\DocParser;
+use JMS\TranslationBundle\Annotation\Desc;
+use JMS\TranslationBundle\Annotation\Ignore;
+use JMS\TranslationBundle\Annotation\Meaning;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
use JMS\TranslationBundle\Translation\FileSourceFactory;
@@ -43,7 +46,7 @@ final protected function extract($file, ?FileVisitorInterface $extractor = null)
}
$lexer = new Lexer();
- if (class_exists('PhpParser\ParserFactory')) {
+ if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
} else {
@@ -64,9 +67,9 @@ final protected function getDocParser()
{
$docParser = new DocParser();
$docParser->setImports([
- 'desc' => 'JMS\TranslationBundle\Annotation\Desc',
- 'meaning' => 'JMS\TranslationBundle\Annotation\Meaning',
- 'ignore' => 'JMS\TranslationBundle\Annotation\Ignore',
+ 'desc' => Desc::class,
+ 'meaning' => Meaning::class,
+ 'ignore' => Ignore::class,
]);
$docParser->setIgnoreNotImportedAnnotations(true);
diff --git a/Tests/Translation/Extractor/File/TranslationContainerExtractorTest.php b/Tests/Translation/Extractor/File/TranslationContainerExtractorTest.php
index b3702253..b2dbc221 100644
--- a/Tests/Translation/Extractor/File/TranslationContainerExtractorTest.php
+++ b/Tests/Translation/Extractor/File/TranslationContainerExtractorTest.php
@@ -60,7 +60,7 @@ private function extract($file, ?TranslationContainerExtractor $extractor = null
}
$lexer = new Lexer();
- if (class_exists('PhpParser\ParserFactory')) {
+ if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
} else {
diff --git a/Tests/Translation/Extractor/File/ValidationExtractorTest.php b/Tests/Translation/Extractor/File/ValidationExtractorTest.php
index 4fe206fc..18136c3f 100644
--- a/Tests/Translation/Extractor/File/ValidationExtractorTest.php
+++ b/Tests/Translation/Extractor/File/ValidationExtractorTest.php
@@ -60,7 +60,7 @@ private function extract($file, ?ValidationExtractor $extractor = null)
}
$lexer = new Lexer();
- if (class_exists('PhpParser\ParserFactory')) {
+ if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
} else {
diff --git a/Tests/Translation/Extractor/FileExtractorTest.php b/Tests/Translation/Extractor/FileExtractorTest.php
index 514b358c..f82e4e39 100644
--- a/Tests/Translation/Extractor/FileExtractorTest.php
+++ b/Tests/Translation/Extractor/FileExtractorTest.php
@@ -22,6 +22,9 @@
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\DocParser;
+use JMS\TranslationBundle\Annotation\Desc;
+use JMS\TranslationBundle\Annotation\Ignore;
+use JMS\TranslationBundle\Annotation\Meaning;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\Extractor\File\DefaultPhpFileExtractor;
use JMS\TranslationBundle\Translation\Extractor\File\FormExtractor;
@@ -106,9 +109,9 @@ private function extract($directory)
$docParser = new DocParser();
$docParser->setImports([
- 'desc' => 'JMS\TranslationBundle\Annotation\Desc',
- 'meaning' => 'JMS\TranslationBundle\Annotation\Meaning',
- 'ignore' => 'JMS\TranslationBundle\Annotation\Ignore',
+ 'desc' => Desc::class,
+ 'meaning' => Meaning::class,
+ 'ignore' => Ignore::class,
]);
$docParser->setIgnoreNotImportedAnnotations(true);
diff --git a/Tests/Translation/ExtractorManagerTest.php b/Tests/Translation/ExtractorManagerTest.php
index 87ae6a9b..8ad39250 100644
--- a/Tests/Translation/ExtractorManagerTest.php
+++ b/Tests/Translation/ExtractorManagerTest.php
@@ -23,6 +23,7 @@
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Extractor\FileExtractor;
+use JMS\TranslationBundle\Translation\ExtractorInterface;
use JMS\TranslationBundle\Translation\ExtractorManager;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
@@ -42,14 +43,14 @@ public function testSetEnabledCustomExtractorsThrowsExceptionWhenAliasInvalid()
public function testOnlySomeExtractorsEnabled()
{
- $foo = $this->createMock('JMS\TranslationBundle\Translation\ExtractorInterface');
+ $foo = $this->createMock(ExtractorInterface::class);
$foo
->expects($this->never())
->method('extract');
$catalogue = new MessageCatalogue();
$catalogue->add(new Message('foo'));
- $bar = $this->createMock('JMS\TranslationBundle\Translation\ExtractorInterface');
+ $bar = $this->createMock(ExtractorInterface::class);
$bar
->expects($this->once())
->method('extract')
@@ -66,7 +67,7 @@ public function testOnlySomeExtractorsEnabled()
public function testReset()
{
- $foo = $this->createMock('JMS\TranslationBundle\Translation\ExtractorInterface');
+ $foo = $this->createMock(ExtractorInterface::class);
$logger = new NullLogger();
$extractor = new FileExtractor(new Environment(new ArrayLoader([])), $logger, []);
diff --git a/Tests/Translation/FileWriterTest.php b/Tests/Translation/FileWriterTest.php
index 3c2d296b..32267b5b 100644
--- a/Tests/Translation/FileWriterTest.php
+++ b/Tests/Translation/FileWriterTest.php
@@ -22,6 +22,7 @@
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
+use JMS\TranslationBundle\Translation\Dumper\DumperInterface;
use JMS\TranslationBundle\Translation\FileWriter;
use PHPUnit\Framework\TestCase;
@@ -29,7 +30,7 @@ class FileWriterTest extends TestCase
{
public function testCatalogueIsSortedBeforeBeingDumped()
{
- $dumper = $this->createMock('JMS\TranslationBundle\Translation\Dumper\DumperInterface');
+ $dumper = $this->createMock(DumperInterface::class);
$self = $this;
$dumper
diff --git a/Tests/Translation/Loader/SymfonyLoaderAdapterTest.php b/Tests/Translation/Loader/SymfonyLoaderAdapterTest.php
index 04ff3bd1..b7043c9c 100644
--- a/Tests/Translation/Loader/SymfonyLoaderAdapterTest.php
+++ b/Tests/Translation/Loader/SymfonyLoaderAdapterTest.php
@@ -20,18 +20,20 @@
namespace JMS\TranslationBundle\Tests\Translation\Loader;
+use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Loader\SymfonyLoaderAdapter;
use PHPUnit\Framework\TestCase;
-use Symfony\Component\Translation\MessageCatalogue;
+use Symfony\Component\Translation\Loader\LoaderInterface;
+use Symfony\Component\Translation\MessageCatalogue as SymfonyMessageCatalogue;
class SymfonyLoaderAdapterTest extends TestCase
{
public function testLoad()
{
- $symfonyCatalogue = new MessageCatalogue('en');
+ $symfonyCatalogue = new SymfonyMessageCatalogue('en');
$symfonyCatalogue->add(['foo' => 'bar']);
- $symfonyLoader = $this->createMock('Symfony\Component\Translation\Loader\LoaderInterface');
+ $symfonyLoader = $this->createMock(LoaderInterface::class);
$symfonyLoader->expects($this->once())
->method('load')
->with('foo', 'en', 'messages')
@@ -39,7 +41,7 @@ public function testLoad()
$adapter = new SymfonyLoaderAdapter($symfonyLoader);
$bundleCatalogue = $adapter->load('foo', 'en', 'messages');
- $this->assertInstanceOf('JMS\TranslationBundle\Model\MessageCatalogue', $bundleCatalogue);
+ $this->assertInstanceOf(MessageCatalogue::class, $bundleCatalogue);
$this->assertEquals('en', $bundleCatalogue->getLocale());
$this->assertTrue($bundleCatalogue->hasDomain('messages'));
$this->assertTrue($bundleCatalogue->getDomain('messages')->has('foo'));
diff --git a/Translation/Comparison/CatalogueComparator.php b/Translation/Comparison/CatalogueComparator.php
index 4494d256..175ab22e 100644
--- a/Translation/Comparison/CatalogueComparator.php
+++ b/Translation/Comparison/CatalogueComparator.php
@@ -1,5 +1,7 @@
*
@@ -27,8 +29,8 @@
*/
class CatalogueComparator
{
- private $domains = array();
- private $ignoredDomains = array();
+ private $domains = [];
+ private $ignoredDomains = [];
public function setDomains(array $domains)
{
@@ -48,11 +50,12 @@ public function setIgnoredDomains(array $domains)
*
* @param MessageCatalogue $current
* @param MessageCatalogue $new
+ *
* @return ChangeSet
*/
public function compare(MessageCatalogue $current, MessageCatalogue $new)
{
- $newMessages = array();
+ $newMessages = [];
foreach ($new->getDomains() as $name => $domain) {
if ($this->domains && !isset($this->domains[$name])) {
@@ -74,7 +77,7 @@ public function compare(MessageCatalogue $current, MessageCatalogue $new)
}
}
- $deletedMessages = array();
+ $deletedMessages = [];
foreach ($current->getDomains() as $name => $domain) {
if ($this->domains && !isset($this->domains[$name])) {
continue;
diff --git a/Translation/Comparison/ChangeSet.php b/Translation/Comparison/ChangeSet.php
index 2ea0bee4..baf0c6da 100644
--- a/Translation/Comparison/ChangeSet.php
+++ b/Translation/Comparison/ChangeSet.php
@@ -1,5 +1,7 @@
*
@@ -31,7 +33,6 @@ class ChangeSet
private $deletedMessages;
/**
- * ChangeSet constructor.
* @param array $addedMessages
* @param array $deletedMessages
*/
diff --git a/Translation/Config.php b/Translation/Config.php
index 0cf5d26b..442335b8 100644
--- a/Translation/Config.php
+++ b/Translation/Config.php
@@ -1,5 +1,7 @@
*
@@ -91,13 +93,12 @@ final class Config
private $loadResources;
/**
- * Config constructor.
- * @param $translationsDir
- * @param $locale
+ * @param string $translationsDir
+ * @param string $locale
* @param array $ignoredDomains
* @param array $domains
- * @param $outputFormat
- * @param $defaultOutputFormat
+ * @param string $outputFormat
+ * @param string $defaultOutputFormat
* @param array $scanDirs
* @param array $excludedDirs
* @param array $excludedNames
@@ -156,7 +157,8 @@ public function getTranslationsDir()
}
/**
- * @param $domain
+ * @param string $domain
+ *
* @return bool
*/
public function isIgnoredDomain($domain)
@@ -173,7 +175,8 @@ public function getIgnoredDomains()
}
/**
- * @param $domain
+ * @param string $domain
+ *
* @return bool
*/
public function hasDomain($domain)
diff --git a/Translation/ConfigBuilder.php b/Translation/ConfigBuilder.php
index 9839bd24..4a3df544 100644
--- a/Translation/ConfigBuilder.php
+++ b/Translation/ConfigBuilder.php
@@ -1,5 +1,7 @@
*
@@ -33,12 +35,12 @@ final class ConfigBuilder
/**
* @var array
*/
- private $ignoredDomains = array();
+ private $ignoredDomains = [];
/**
* @var array
*/
- private $domains = array();
+ private $domains = [];
/**
* @var string
@@ -53,22 +55,22 @@ final class ConfigBuilder
/**
* @var array
*/
- private $scanDirs = array();
+ private $scanDirs = [];
/**
* @var array
*/
- private $excludedDirs = array('Tests');
+ private $excludedDirs = ['Tests'];
/**
* @var array
*/
- private $excludedNames = array('*Test.php', '*TestCase.php');
+ private $excludedNames = ['*Test.php', '*TestCase.php'];
/**
* @var array
*/
- private $enabledExtractors = array();
+ private $enabledExtractors = [];
/**
* @var bool
@@ -78,12 +80,14 @@ final class ConfigBuilder
/**
* @var array
*/
- private $loadResources = array();
+ private $loadResources = [];
/**
- * @static
* @param Config $config
+ *
* @return ConfigBuilder
+ *
+ * @static
*/
public static function fromConfig(Config $config)
{
@@ -111,6 +115,7 @@ public static function fromConfig(Config $config)
* - you haven't forced a format
*
* @param string $format
+ *
* @return $this
*/
public function setDefaultOutputFormat($format)
@@ -128,6 +133,7 @@ public function setDefaultOutputFormat($format)
* another format to be deleted.
*
* @param string $format
+ *
* @return $this
*/
public function setOutputFormat($format)
@@ -144,6 +150,7 @@ public function setOutputFormat($format)
* appear in the change set calculated by getChangeSet().
*
* @param array $domains an array of the form array('domain' => true, 'another_domain' => true)
+ *
* @return $this
*/
public function setIgnoredDomains(array $domains)
@@ -155,6 +162,7 @@ public function setIgnoredDomains(array $domains)
/**
* @param string $domain
+ *
* @return $this
*/
public function addIgnoredDomain($domain)
@@ -166,6 +174,7 @@ public function addIgnoredDomain($domain)
/**
* @param array $domains
+ *
* @return $this
*/
public function setDomains(array $domains)
@@ -177,6 +186,7 @@ public function setDomains(array $domains)
/**
* @param string $domain
+ *
* @return $this
*/
public function addDomain($domain)
@@ -188,6 +198,7 @@ public function addDomain($domain)
/**
* @param string $locale
+ *
* @return $this
*/
public function setLocale($locale)
@@ -199,6 +210,7 @@ public function setLocale($locale)
/**
* @param string $dir
+ *
* @return $this
*/
public function setTranslationsDir($dir)
@@ -210,6 +222,7 @@ public function setTranslationsDir($dir)
/**
* @param array $dirs
+ *
* @return $this
*/
public function setScanDirs(array $dirs)
@@ -221,6 +234,7 @@ public function setScanDirs(array $dirs)
/**
* @param array $dirs
+ *
* @return $this
*/
public function setExcludedDirs(array $dirs)
@@ -232,6 +246,7 @@ public function setExcludedDirs(array $dirs)
/**
* @param array $names
+ *
* @return $this
*/
public function setExcludedNames(array $names)
@@ -243,6 +258,7 @@ public function setExcludedNames(array $names)
/**
* @param array $aliases
+ *
* @return $this
*/
public function setEnabledExtractors(array $aliases)
@@ -254,6 +270,7 @@ public function setEnabledExtractors(array $aliases)
/**
* @param string $alias
+ *
* @return $this
*/
public function enableExtractor($alias)
@@ -265,6 +282,7 @@ public function enableExtractor($alias)
/**
* @param string $alias
+ *
* @return $this
*/
public function disableExtractor($alias)
@@ -276,6 +294,7 @@ public function disableExtractor($alias)
/**
* @param bool $value
+ *
* @return $this
*/
public function setKeepOldTranslations($value)
@@ -308,6 +327,7 @@ public function getConfig()
/**
* @param array $loadResources
+ *
* @return $this
*/
public function setLoadResources(array $loadResources)
diff --git a/Translation/ConfigFactory.php b/Translation/ConfigFactory.php
index 6bce0a40..74b02e77 100644
--- a/Translation/ConfigFactory.php
+++ b/Translation/ConfigFactory.php
@@ -1,5 +1,7 @@
*
@@ -28,10 +30,9 @@ class ConfigFactory
private $builders;
/**
- * ConfigFactory constructor.
* @param array $builders ConfigBuilder
*/
- public function __construct(array $builders = array())
+ public function __construct(array $builders = [])
{
$this->builders = $builders;
}
@@ -45,8 +46,10 @@ public function getNames()
}
/**
- * @param $name
+ * @param string $name
+ *
* @return ConfigBuilder
+ *
* @throws InvalidArgumentException
*/
public function getBuilder($name)
@@ -59,8 +62,9 @@ public function getBuilder($name)
}
/**
- * @param $name
- * @param $locale
+ * @param string $name
+ * @param string $locale
+ *
* @return Config
*/
public function getConfig($name, $locale)
diff --git a/Translation/Dumper/ArrayStructureDumper.php b/Translation/Dumper/ArrayStructureDumper.php
index 172ab865..75fcee28 100644
--- a/Translation/Dumper/ArrayStructureDumper.php
+++ b/Translation/Dumper/ArrayStructureDumper.php
@@ -1,5 +1,7 @@
*
@@ -28,9 +30,6 @@ abstract class ArrayStructureDumper implements DumperInterface
*/
private $prettyPrint = true;
- /**
- * @param $bool
- */
public function setPrettyPrint($bool)
{
$this->prettyPrint = (bool) $bool;
@@ -39,6 +38,7 @@ public function setPrettyPrint($bool)
/**
* @param MessageCatalogue $catalogue
* @param string $domain
+ *
* @return string
*/
public function dump(MessageCatalogue $catalogue, $domain = 'messages')
@@ -46,7 +46,7 @@ public function dump(MessageCatalogue $catalogue, $domain = 'messages')
$structure = $catalogue->getDomain($domain)->all();
if ($this->prettyPrint) {
- $tmpStructure = array();
+ $tmpStructure = [];
foreach ($structure as $id => $message) {
$pointer = &$tmpStructure;
@@ -64,7 +64,7 @@ public function dump(MessageCatalogue $catalogue, $domain = 'messages')
}
if (!isset($pointer[$parts[$i]])) {
- $pointer[$parts[$i]] = array();
+ $pointer[$parts[$i]] = [];
}
if ($pointer[$parts[$i]] instanceof Message) {
@@ -86,6 +86,7 @@ public function dump(MessageCatalogue $catalogue, $domain = 'messages')
/**
* @param array $structure
+ *
* @return string
*/
abstract protected function dumpStructure(array $structure);
diff --git a/Translation/Dumper/DumperInterface.php b/Translation/Dumper/DumperInterface.php
index b7dbf4e8..11a839fd 100644
--- a/Translation/Dumper/DumperInterface.php
+++ b/Translation/Dumper/DumperInterface.php
@@ -1,5 +1,7 @@
*
@@ -35,6 +37,7 @@ interface DumperInterface
*
* @param MessageCatalogue $catalogue
* @param string $domain
+ *
* @return string
*/
public function dump(MessageCatalogue $catalogue, $domain = 'messages');
diff --git a/Translation/Dumper/PhpDumper.php b/Translation/Dumper/PhpDumper.php
index 20846e10..ef9dc784 100644
--- a/Translation/Dumper/PhpDumper.php
+++ b/Translation/Dumper/PhpDumper.php
@@ -1,5 +1,7 @@
*
@@ -28,9 +30,6 @@ class PhpDumper extends ArrayStructureDumper
*/
private $writer;
- /**
- * PhpDumper constructor.
- */
public function __construct()
{
$this->writer = new Writer();
@@ -38,6 +37,7 @@ public function __construct()
/**
* @param array $structure
+ *
* @return string
*/
protected function dumpStructure(array $structure)
@@ -46,8 +46,7 @@ protected function dumpStructure(array $structure)
->reset()
->writeln('writeln('return array(')
- ->indent()
- ;
+ ->indent();
$this->dumpStructureRecursively($structure);
@@ -71,10 +70,10 @@ private function dumpStructureRecursively(array $structure)
}
if ($desc) {
- $this->writer->writeln('// Desc: '.$desc);
+ $this->writer->writeln('// Desc: ' . $desc);
}
if ($meaning) {
- $this->writer->writeln('// Meaning: '.$meaning);
+ $this->writer->writeln('// Meaning: ' . $meaning);
}
} elseif (!$isFirst) {
$this->writer->write("\n");
@@ -82,10 +81,10 @@ private function dumpStructureRecursively(array $structure)
$isFirst = false;
$precededByMessage = $isMessage;
- $this->writer->write(var_export($k, true).' => ');
+ $this->writer->write(var_export($k, true) . ' => ');
if ($isMessage) {
- $this->writer->write(var_export($v->getLocaleString(), true).',');
+ $this->writer->write(var_export($v->getLocaleString(), true) . ',');
if ($v->isNew()) {
$this->writer->write(' // FIXME');
@@ -98,15 +97,13 @@ private function dumpStructureRecursively(array $structure)
$this->writer
->write("array(\n")
- ->indent()
- ;
+ ->indent();
$this->dumpStructureRecursively($v);
$this->writer
->outdent()
- ->writeln('),')
- ;
+ ->writeln('),');
}
}
}
diff --git a/Translation/Dumper/SymfonyDumperAdapter.php b/Translation/Dumper/SymfonyDumperAdapter.php
index 3789d6c1..6591d6bd 100644
--- a/Translation/Dumper/SymfonyDumperAdapter.php
+++ b/Translation/Dumper/SymfonyDumperAdapter.php
@@ -1,5 +1,7 @@
*
@@ -19,10 +21,10 @@
namespace JMS\TranslationBundle\Translation\Dumper;
use JMS\TranslationBundle\Exception\RuntimeException;
+use JMS\TranslationBundle\Model\MessageCatalogue;
use Symfony\Component\Filesystem\Filesystem;
-use Symfony\Component\Translation\MessageCatalogue as SymfonyCatalogue;
use Symfony\Component\Translation\Dumper\DumperInterface as SymfonyDumper;
-use JMS\TranslationBundle\Model\MessageCatalogue;
+use Symfony\Component\Translation\MessageCatalogue as SymfonyCatalogue;
/**
* Adapter for Symfony's dumpers.
@@ -46,11 +48,6 @@ class SymfonyDumperAdapter implements DumperInterface
*/
private $format;
- /**
- * SymfonyDumperAdapter constructor.
- * @param SymfonyDumper $dumper
- * @param $format string
- */
public function __construct(SymfonyDumper $dumper, $format)
{
$this->dumper = $dumper;
@@ -60,7 +57,9 @@ public function __construct(SymfonyDumper $dumper, $format)
/**
* @param MessageCatalogue $catalogue
* @param string $domain
+ *
* @return string
+ *
* @throws RuntimeException
*/
public function dump(MessageCatalogue $catalogue, $domain = 'messages')
@@ -69,21 +68,19 @@ public function dump(MessageCatalogue $catalogue, $domain = 'messages')
foreach ($catalogue->getDomain($domain)->all() as $id => $message) {
$symfonyCatalogue->add(
- array($id => $message->getLocaleString()),
+ [$id => $message->getLocaleString()],
$domain
);
}
- $tmpPath = sys_get_temp_dir().'/'.uniqid('translation', false);
+ $tmpPath = sys_get_temp_dir() . '/' . uniqid('translation', false);
if (!is_dir($tmpPath) && false === @mkdir($tmpPath, 0777, true)) {
throw new RuntimeException(sprintf('Could not create temporary directory "%s".', $tmpPath));
}
- $this->dumper->dump($symfonyCatalogue, array(
- 'path' => $tmpPath,
- ));
+ $this->dumper->dump($symfonyCatalogue, ['path' => $tmpPath]);
- if (!is_file($tmpFile = $tmpPath.'/'.$domain.'.'.$catalogue->getLocale().'.'.$this->format)) {
+ if (!is_file($tmpFile = $tmpPath . '/' . $domain . '.' . $catalogue->getLocale() . '.' . $this->format)) {
throw new RuntimeException(sprintf('Could not find dumped translation file "%s".', $tmpFile));
}
diff --git a/Translation/Dumper/XliffDumper.php b/Translation/Dumper/XliffDumper.php
index c499570b..f61a27cd 100644
--- a/Translation/Dumper/XliffDumper.php
+++ b/Translation/Dumper/XliffDumper.php
@@ -1,5 +1,7 @@
*
@@ -18,18 +20,19 @@
namespace JMS\TranslationBundle\Translation\Dumper;
-use JMS\TranslationBundle\Model\FileSource;
use JMS\TranslationBundle\JMSTranslationBundle;
-use JMS\TranslationBundle\Model\MessageCatalogue;
+use JMS\TranslationBundle\Model\FileSource;
use JMS\TranslationBundle\Model\Message\XliffMessage;
+use JMS\TranslationBundle\Model\MessageCatalogue;
/**
* XLIFF dumper.
*
* This dumper uses version 1.2 of the specification.
*
- * @see http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html
* @author Johannes M. Schmitt
+ *
+ * @see http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html
*/
class XliffDumper implements DumperInterface
{
@@ -53,33 +56,21 @@ class XliffDumper implements DumperInterface
*/
private $addReferencePosition = true;
- /**
- * @param $bool
- */
public function setAddDate($bool)
{
$this->addDate = (bool) $bool;
}
- /**
- * @param $lang
- */
public function setSourceLanguage($lang)
{
$this->sourceLanguage = $lang;
}
- /**
- * @param $bool
- */
public function setAddReference($bool)
{
$this->addReference = $bool;
}
- /**
- * @param $bool
- */
public function setAddReferencePosition($bool)
{
$this->addReferencePosition = $bool;
@@ -88,6 +79,7 @@ public function setAddReferencePosition($bool)
/**
* @param MessageCatalogue $catalogue
* @param MessageCatalogue|string $domain
+ *
* @return string
*/
public function dump(MessageCatalogue $catalogue, $domain = 'messages')
@@ -119,7 +111,6 @@ public function dump(MessageCatalogue $catalogue, $domain = 'messages')
$tool->setAttribute('tool-name', 'JMSTranslationBundle');
$tool->setAttribute('tool-version', JMSTranslationBundle::VERSION);
-
$header->appendChild($note = $doc->createElement('note'));
$note->appendChild($doc->createTextNode('The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.'));
@@ -164,7 +155,7 @@ public function dump(MessageCatalogue $catalogue, $domain = 'messages')
foreach ($message->getNotes() as $note) {
$noteNode = $unit->appendChild($doc->createElement('note', $note['text']));
if (isset($note['from'])) {
- $noteNode->setAttribute('from', $note['from']);
+ $noteNode->setAttribute('from', $note['from']);
}
}
}
@@ -199,7 +190,7 @@ public function dump(MessageCatalogue $catalogue, $domain = 'messages')
}
if ($meaning = $message->getMeaning()) {
- $unit->setAttribute('extradata', 'Meaning: '.$meaning);
+ $unit->setAttribute('extradata', 'Meaning: ' . $meaning);
}
}
@@ -211,11 +202,12 @@ public function dump(MessageCatalogue $catalogue, $domain = 'messages')
* If the reference position are not used, the reference file will be write once
*
* @param array $sources
+ *
* @return FileSource
*/
protected function getSortedSources(array $sources)
{
- $indexedSources = array();
+ $indexedSources = [];
foreach ($sources as $source) {
if ($source instanceof FileSource) {
$index = $source->getPath();
diff --git a/Translation/Dumper/YamlDumper.php b/Translation/Dumper/YamlDumper.php
index 8f93ce40..a67b782c 100644
--- a/Translation/Dumper/YamlDumper.php
+++ b/Translation/Dumper/YamlDumper.php
@@ -1,5 +1,7 @@
*
@@ -18,8 +20,8 @@
namespace JMS\TranslationBundle\Translation\Dumper;
-use JMS\TranslationBundle\Util\Writer;
use JMS\TranslationBundle\Model\Message;
+use JMS\TranslationBundle\Util\Writer;
use Symfony\Component\Yaml\Inline;
class YamlDumper extends ArrayStructureDumper
@@ -29,9 +31,6 @@ class YamlDumper extends ArrayStructureDumper
*/
private $writer;
- /**
- * YamlDumper constructor.
- */
public function __construct()
{
$this->writer = new Writer();
@@ -39,6 +38,7 @@ public function __construct()
/**
* @param array $structure
+ *
* @return string
*/
protected function dumpStructure(array $structure)
@@ -66,11 +66,11 @@ private function dumpStructureRecursively(array $structure)
}
if ($desc) {
- $desc = str_replace(array("\r\n", "\n", "\r", "\t"), array('\r\n', '\n', '\r', '\t'), $desc);
- $this->writer->writeln('# Desc: '.$desc);
+ $desc = str_replace(["\r\n", "\n", "\r", "\t"], ['\r\n', '\n', '\r', '\t'], $desc);
+ $this->writer->writeln('# Desc: ' . $desc);
}
if ($meaning) {
- $this->writer->writeln('# Meaning: '.$meaning);
+ $this->writer->writeln('# Meaning: ' . $meaning);
}
} elseif (!$isFirst) {
$this->writer->write("\n");
@@ -78,10 +78,10 @@ private function dumpStructureRecursively(array $structure)
$isFirst = false;
$precededByMessage = $isMessage;
- $this->writer->write(Inline::dump($k).':');
+ $this->writer->write(Inline::dump($k) . ':');
if ($isMessage) {
- $this->writer->write(' '.Inline::dump($v->getLocaleString()));
+ $this->writer->write(' ' . Inline::dump($v->getLocaleString()));
if ($v->isNew()) {
$this->writer->write(' # FIXME');
diff --git a/Translation/Extractor/File/AuthenticationMessagesExtractor.php b/Translation/Extractor/File/AuthenticationMessagesExtractor.php
index d424f481..b320c458 100644
--- a/Translation/Extractor/File/AuthenticationMessagesExtractor.php
+++ b/Translation/Extractor/File/AuthenticationMessagesExtractor.php
@@ -1,5 +1,7 @@
*
@@ -18,20 +20,21 @@
namespace JMS\TranslationBundle\Translation\Extractor\File;
-use JMS\TranslationBundle\Exception\RuntimeException;
-use JMS\TranslationBundle\Model\Message;
-use JMS\TranslationBundle\Annotation\Meaning;
+use Doctrine\Common\Annotations\DocParser;
use JMS\TranslationBundle\Annotation\Desc;
use JMS\TranslationBundle\Annotation\Ignore;
+use JMS\TranslationBundle\Annotation\Meaning;
+use JMS\TranslationBundle\Exception\RuntimeException;
+use JMS\TranslationBundle\Logger\LoggerAwareInterface;
+use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
-use Doctrine\Common\Annotations\DocParser;
-use JMS\TranslationBundle\Logger\LoggerAwareInterface;
use JMS\TranslationBundle\Translation\FileSourceFactory;
use PhpParser\Node;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use Psr\Log\LoggerInterface;
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Twig\Node\Node as TwigNode;
class AuthenticationMessagesExtractor implements LoggerAwareInterface, FileVisitorInterface, NodeVisitor
@@ -86,11 +89,6 @@ class AuthenticationMessagesExtractor implements LoggerAwareInterface, FileVisit
*/
private $logger;
- /**
- * AuthenticationMessagesExtractor constructor.
- * @param DocParser $parser
- * @param FileSourceFactory $fileSourceFactory
- */
public function __construct(DocParser $parser, FileSourceFactory $fileSourceFactory)
{
$this->docParser = $parser;
@@ -99,17 +97,11 @@ public function __construct(DocParser $parser, FileSourceFactory $fileSourceFact
$this->traverser->addVisitor($this);
}
- /**
- * @param LoggerInterface $logger
- */
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
- /**
- * @param $domain
- */
public function setDomain($domain)
{
$this->domain = $domain;
@@ -117,6 +109,7 @@ public function setDomain($domain)
/**
* @param Node $node
+ *
* @return void
*/
public function enterNode(Node $node)
@@ -130,14 +123,14 @@ public function enterNode(Node $node)
}
if ($node instanceof Node\Stmt\Class_) {
- $name = '' === $this->namespace ? $node->name : $this->namespace.'\\'.$node->name;
+ $name = '' === $this->namespace ? (string) $node->name : $this->namespace . '\\' . $node->name;
if (!class_exists($name)) {
return;
}
$ref = new \ReflectionClass($name);
- if (!$ref->isSubclassOf('Symfony\Component\Security\Core\Exception\AuthenticationException')
+ if (!$ref->isSubclassOf(AuthenticationException::class)
&& $ref->name !== 'Symfony\Component\Security\Core\Exception\AuthenticationException') {
return;
}
@@ -155,7 +148,7 @@ public function enterNode(Node $node)
}
if ($node instanceof Node\Stmt\ClassMethod) {
- if ('getmessagekey' === strtolower($node->name)) {
+ if ('getmessagekey' === strtolower((string) $node->name)) {
$this->inGetMessageKey = true;
}
@@ -173,7 +166,7 @@ public function enterNode(Node $node)
$ignore = false;
$desc = $meaning = null;
if ($docComment = $node->getDocComment()) {
- foreach ($this->docParser->parse($docComment->getText(), 'file '.$this->file.' near line '.$node->getLine()) as $annot) {
+ foreach ($this->docParser->parse($docComment->getText(), 'file ' . $this->file . ' near line ' . $node->getLine()) as $annot) {
if ($annot instanceof Ignore) {
$ignore = true;
} elseif ($annot instanceof Desc) {
@@ -202,8 +195,7 @@ public function enterNode(Node $node)
$message = Message::create($node->expr->value, $this->domain)
->setDesc($desc)
->setMeaning($meaning)
- ->addSource($this->fileSourceFactory->create($this->file, $node->expr->getLine()))
- ;
+ ->addSource($this->fileSourceFactory->create($this->file, $node->expr->getLine()));
$this->catalogue->add($message);
}
@@ -223,7 +215,8 @@ public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, ar
/**
* @param Node $node
- * @return false|null|Node|\PhpParser\Node[]|void
+ *
+ * @return false|Node|Node[]|void|null
*/
public function leaveNode(Node $node)
{
@@ -242,7 +235,8 @@ public function leaveNode(Node $node)
/**
* @param array $nodes
- * @return null|\PhpParser\Node[]|void
+ *
+ * @return Node[]|void|null
*/
public function beforeTraverse(array $nodes)
{
@@ -250,25 +244,17 @@ public function beforeTraverse(array $nodes)
/**
* @param array $nodes
- * @return null|\PhpParser\Node[]|void
+ *
+ * @return Node[]|void|null
*/
public function afterTraverse(array $nodes)
{
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- */
public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue)
{
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- * @param TwigNode $ast
- */
public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, TwigNode $ast)
{
}
diff --git a/Translation/Extractor/File/DefaultPhpFileExtractor.php b/Translation/Extractor/File/DefaultPhpFileExtractor.php
index 0918b801..9cd80337 100644
--- a/Translation/Extractor/File/DefaultPhpFileExtractor.php
+++ b/Translation/Extractor/File/DefaultPhpFileExtractor.php
@@ -1,5 +1,7 @@
*
@@ -18,21 +20,21 @@
namespace JMS\TranslationBundle\Translation\Extractor\File;
-use JMS\TranslationBundle\Exception\RuntimeException;
use Doctrine\Common\Annotations\DocParser;
-use JMS\TranslationBundle\Model\Message;
-use JMS\TranslationBundle\Annotation\Meaning;
use JMS\TranslationBundle\Annotation\Desc;
use JMS\TranslationBundle\Annotation\Ignore;
-use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
-use JMS\TranslationBundle\Model\MessageCatalogue;
+use JMS\TranslationBundle\Annotation\Meaning;
+use JMS\TranslationBundle\Exception\RuntimeException;
use JMS\TranslationBundle\Logger\LoggerAwareInterface;
+use JMS\TranslationBundle\Model\Message;
+use JMS\TranslationBundle\Model\MessageCatalogue;
+use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
use JMS\TranslationBundle\Translation\FileSourceFactory;
use PhpParser\Comment\Doc;
use PhpParser\Node;
+use PhpParser\Node\Scalar\String_;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
-use PhpParser\Node\Scalar\String_;
use Psr\Log\LoggerInterface;
use Twig\Node\Node as TwigNode;
@@ -49,7 +51,7 @@ class DefaultPhpFileExtractor implements LoggerAwareInterface, FileVisitorInterf
* @var FileSourceFactory
*/
private $fileSourceFactory;
-
+
/**
* @var NodeTraverser
*/
@@ -85,16 +87,11 @@ class DefaultPhpFileExtractor implements LoggerAwareInterface, FileVisitorInterf
*
* @var array method => position of the "domain" parameter
*/
- protected $methodsToExtractFrom = array(
+ protected $methodsToExtractFrom = [
'trans' => 2,
'transchoice' => 3,
- );
+ ];
- /**
- * DefaultPhpFileExtractor constructor.
- * @param DocParser $docParser
- * @param FileSourceFactory $fileSourceFactory
- */
public function __construct(DocParser $docParser, FileSourceFactory $fileSourceFactory)
{
$this->docParser = $docParser;
@@ -103,9 +100,6 @@ public function __construct(DocParser $docParser, FileSourceFactory $fileSourceF
$this->traverser->addVisitor($this);
}
- /**
- * @param LoggerInterface $logger
- */
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
@@ -113,6 +107,7 @@ public function setLogger(LoggerInterface $logger)
/**
* @param Node $node
+ *
* @return void
*/
public function enterNode(Node $node)
@@ -124,6 +119,7 @@ public function enterNode(Node $node)
if (!is_string($methodCallNodeName)
|| !in_array(strtolower($methodCallNodeName), array_map('strtolower', array_keys($this->methodsToExtractFrom)))) {
$this->previousNode = $node;
+
return;
}
@@ -133,7 +129,7 @@ public function enterNode(Node $node)
if ($docComment instanceof Doc) {
$docComment = $docComment->getText();
}
- foreach ($this->docParser->parse($docComment, 'file '.$this->file.' near line '.$node->getLine()) as $annot) {
+ foreach ($this->docParser->parse($docComment, 'file ' . $this->file . ' near line ' . $node->getLine()) as $annot) {
if ($annot instanceof Ignore) {
$ignore = true;
} elseif ($annot instanceof Desc) {
@@ -153,6 +149,7 @@ public function enterNode(Node $node)
if ($this->logger) {
$this->logger->error($message);
+
return;
}
@@ -172,6 +169,7 @@ public function enterNode(Node $node)
if ($this->logger) {
$this->logger->error($message);
+
return;
}
@@ -204,6 +202,7 @@ public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, ar
/**
* @param array $nodes
+ *
* @return void
*/
public function beforeTraverse(array $nodes)
@@ -212,6 +211,7 @@ public function beforeTraverse(array $nodes)
/**
* @param Node $node
+ *
* @return void
*/
public function leaveNode(Node $node)
@@ -220,31 +220,25 @@ public function leaveNode(Node $node)
/**
* @param array $nodes
+ *
* @return void
*/
public function afterTraverse(array $nodes)
{
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- */
public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue)
{
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- */
public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, TwigNode $ast)
{
}
/**
* @param Node $node
- * @return null|string
+ *
+ * @return string|null
*/
private function getDocCommentForNode(Node $node)
{
@@ -262,6 +256,7 @@ private function getDocCommentForNode(Node $node)
return $comment->getText();
} elseif (null !== $this->previousNode && $this->previousNode->getDocComment() !== null) {
$comment = $this->previousNode->getDocComment();
+
return is_object($comment) ? $comment->getText() : $comment;
}
diff --git a/Translation/Extractor/File/FormExtractor.php b/Translation/Extractor/File/FormExtractor.php
index 8f8e862c..74704d22 100644
--- a/Translation/Extractor/File/FormExtractor.php
+++ b/Translation/Extractor/File/FormExtractor.php
@@ -1,5 +1,7 @@
*
@@ -18,22 +20,22 @@
namespace JMS\TranslationBundle\Translation\Extractor\File;
-use JMS\TranslationBundle\Exception\RuntimeException;
-use JMS\TranslationBundle\Model\Message;
-use JMS\TranslationBundle\Annotation\Meaning;
+use Doctrine\Common\Annotations\DocParser;
use JMS\TranslationBundle\Annotation\Desc;
use JMS\TranslationBundle\Annotation\Ignore;
-use Doctrine\Common\Annotations\DocParser;
+use JMS\TranslationBundle\Annotation\Meaning;
+use JMS\TranslationBundle\Exception\RuntimeException;
+use JMS\TranslationBundle\Logger\LoggerAwareInterface;
+use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
-use JMS\TranslationBundle\Logger\LoggerAwareInterface;
use JMS\TranslationBundle\Translation\FileSourceFactory;
use PhpParser\Comment\Doc;
use PhpParser\Node;
+use PhpParser\Node\Expr\ArrayItem;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use Psr\Log\LoggerInterface;
-use Symfony\Component\HttpKernel\Kernel;
use Twig\Node\Node as TwigNode;
class FormExtractor implements FileVisitorInterface, LoggerAwareInterface, NodeVisitor
@@ -78,11 +80,6 @@ class FormExtractor implements FileVisitorInterface, LoggerAwareInterface, NodeV
*/
private $defaultDomainMessages;
- /**
- * FormExtractor constructor.
- * @param DocParser $docParser
- * @param FileSourceFactory $fileSourceFactory
- */
public function __construct(DocParser $docParser, FileSourceFactory $fileSourceFactory)
{
$this->docParser = $docParser;
@@ -93,13 +90,14 @@ public function __construct(DocParser $docParser, FileSourceFactory $fileSourceF
/**
* @param Node $node
+ *
* @return null
*/
public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Class_) {
$this->defaultDomain = null;
- $this->defaultDomainMessages = array();
+ $this->defaultDomainMessages = [];
}
if ($node instanceof Node\Expr\MethodCall) {
@@ -111,6 +109,7 @@ public function enterNode(Node $node)
$name = strtolower($nodeName);
if ('setdefaults' === $name || 'replacedefaults' === $name || 'setdefault' === $name) {
$this->parseDefaultsCall($node);
+
return;
}
}
@@ -158,7 +157,8 @@ public function enterNode(Node $node)
/**
* @param Node $node
- * @return null|string
+ *
+ * @return string|null
*/
public function getDomain(Node $node)
{
@@ -187,10 +187,12 @@ public function getDomain(Node $node)
* Returning true means either that regardless of whether
* parsing has occurred or not, the enterNode function should move on to the next node item.
*
+ * @internal
+ *
* @param Node $item
- * @param $domain
+ * @param string $domain
+ *
* @return bool
- * @internal
*/
protected function parseEmptyValueNode(Node $item, $domain)
{
@@ -217,11 +219,13 @@ protected function parseEmptyValueNode(Node $item, $domain)
* Returning true means either that regardless of whether
* parsing has occurred or not, the enterNode function should move on to the next node item.
*
+ * @internal
+ *
* @param Node $item
* @param Node $node
- * @param $domain
+ * @param string $domain
+ *
* @return bool
- * @internal
*/
protected function parseChoiceNode(Node $item, Node $node, $domain)
{
@@ -247,10 +251,12 @@ protected function parseChoiceNode(Node $item, Node $node, $domain)
* Returning true means either that regardless of whether
* parsing has occurred or not, the enterNode function should move on to the next node item.
*
+ * @internal
+ *
* @param Node $item
- * @param $domain
+ * @param string $domain
+ *
* @return bool
- * @internal
*/
protected function parseAttrNode(Node $item, $domain)
{
@@ -259,10 +265,10 @@ protected function parseAttrNode(Node $item, $domain)
}
foreach ($item->value->items as $sitem) {
- if ('placeholder' == $sitem->key->value) {
+ if ('placeholder' === $sitem->key->value) {
$this->parseItem($sitem, $domain);
}
- if ('title' == $sitem->key->value) {
+ if ('title' === $sitem->key->value) {
$this->parseItem($sitem, $domain);
}
}
@@ -270,17 +276,19 @@ protected function parseAttrNode(Node $item, $domain)
return true;
}
-
- /**
- * @param Node $node
- */
private function parseDefaultsCall(Node $node)
{
- static $returningMethods = array(
- 'setdefaults' => true, 'replacedefaults' => true, 'setoptional' => true, 'setrequired' => true,
- 'setallowedvalues' => true, 'addallowedvalues' => true, 'setallowedtypes' => true,
- 'addallowedtypes' => true, 'setfilters' => true
- );
+ static $returningMethods = [
+ 'setdefaults' => true,
+ 'replacedefaults' => true,
+ 'setoptional' => true,
+ 'setrequired' => true,
+ 'setallowedvalues' => true,
+ 'addallowedvalues' => true,
+ 'setallowedtypes' => true,
+ 'addallowedtypes' => true,
+ 'setfilters' => true,
+ ];
$var = $node->var;
while ($var instanceof Node\Expr\MethodCall) {
@@ -306,6 +314,7 @@ private function parseDefaultsCall(Node $node)
&& 'translation_domain' === $node->args[0]->value->value
) {
$this->defaultDomain = $node->args[1]->value->value;
+
return;
}
@@ -332,7 +341,7 @@ private function parseDefaultsCall(Node $node)
}
/**
- * @param $item
+ * @param ArrayItem $item
* @param null $domain
*/
private function parseItem($item, $domain = null)
@@ -355,7 +364,7 @@ private function parseItem($item, $domain = null)
if ($docComment instanceof Doc) {
$docComment = $docComment->getText();
}
- foreach ($this->docParser->parse($docComment, 'file '.$this->file.' near line '.$item->value->getLine()) as $annot) {
+ foreach ($this->docParser->parse($docComment, 'file ' . $this->file . ' near line ' . $item->value->getLine()) as $annot) {
if ($annot instanceof Ignore) {
$ignore = true;
} elseif ($annot instanceof Desc) {
@@ -367,7 +376,7 @@ private function parseItem($item, $domain = null)
}
// check if the value is explicitly set to false => e.g. for FormField that should be rendered without label
- $ignore = $ignore || !$item->value instanceof Node\Scalar\String_ || $item->value->value == false;
+ $ignore = $ignore || !$item->value instanceof Node\Scalar\String_ || $item->value->value === false;
if (!$item->value instanceof Node\Scalar\String_ && !$item->value instanceof Node\Scalar\LNumber) {
if ($ignore) {
@@ -388,12 +397,12 @@ private function parseItem($item, $domain = null)
$id = $item->value->value;
if (null === $domain) {
- $this->defaultDomainMessages[] = array(
+ $this->defaultDomainMessages[] = [
'id' => $id,
'source' => $source,
'desc' => $desc,
- 'meaning' => $meaning
- );
+ 'meaning' => $meaning,
+ ];
} else {
$this->addToCatalogue($id, $source, $domain, $desc, $meaning);
}
@@ -402,9 +411,9 @@ private function parseItem($item, $domain = null)
/**
* @param string $id
* @param string $source
- * @param null|string $domain
- * @param null|string $desc
- * @param null|string $meaning
+ * @param string|null $domain
+ * @param string|null $desc
+ * @param string|null $meaning
*/
private function addToCatalogue($id, $source, $domain = null, $desc = null, $meaning = null)
{
@@ -447,7 +456,8 @@ public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, ar
/**
* @param Node $node
- * @return null|\PhpParser\Node[]|void
+ *
+ * @return Node[]|void|null
*/
public function leaveNode(Node $node)
{
@@ -455,7 +465,8 @@ public function leaveNode(Node $node)
/**
* @param array $nodes
- * @return null|\PhpParser\Node[]|void
+ *
+ * @return Node[]|void|null
*/
public function beforeTraverse(array $nodes)
{
@@ -463,32 +474,21 @@ public function beforeTraverse(array $nodes)
/**
* @param array $nodes
- * @return null|\PhpParser\Node[]|void
+ *
+ * @return Node[]|void|null
*/
public function afterTraverse(array $nodes)
{
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- */
public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue)
{
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- * @param TwigNode $ast
- */
public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, TwigNode $ast)
{
}
- /**
- * @param LoggerInterface $logger
- */
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
diff --git a/Translation/Extractor/File/TranslationContainerExtractor.php b/Translation/Extractor/File/TranslationContainerExtractor.php
index 54f46a6c..b2044883 100644
--- a/Translation/Extractor/File/TranslationContainerExtractor.php
+++ b/Translation/Extractor/File/TranslationContainerExtractor.php
@@ -1,5 +1,7 @@
*
@@ -42,11 +44,6 @@ class TranslationContainerExtractor implements FileVisitorInterface, NodeVisitor
*/
private $traverser;
- /**
- * @var string
- */
- private $file;
-
/**
* @var MessageCatalogue
*/
@@ -60,11 +57,8 @@ class TranslationContainerExtractor implements FileVisitorInterface, NodeVisitor
/**
* @var array
*/
- private $useStatements = array();
+ private $useStatements = [];
- /**
- * TranslationContainerExtractor constructor.
- */
public function __construct()
{
$this->traverser = new NodeTraverser();
@@ -73,7 +67,8 @@ public function __construct()
/**
* @param Node $node
- * @return null|Node|void
+ *
+ * @return Node|void|null
*/
public function enterNode(Node $node)
{
@@ -81,7 +76,7 @@ public function enterNode(Node $node)
if (isset($node->name)) {
$this->namespace = implode('\\', $node->name->parts);
}
- $this->useStatements = array();
+ $this->useStatements = [];
return;
}
@@ -114,14 +109,14 @@ public function enterNode(Node $node)
return;
}
- $messages = call_user_func(array($this->namespace.'\\'.$node->name, 'getTranslationMessages'));
+ $messages = call_user_func([$this->namespace . '\\' . $node->name, 'getTranslationMessages']);
if (!is_array($messages)) {
- throw new RuntimeException(sprintf('%s::getTranslationMessages() was expected to return an array of messages, but got %s.', $this->namespace.'\\'.$node->name, gettype($messages)));
+ throw new RuntimeException(sprintf('%s::getTranslationMessages() was expected to return an array of messages, but got %s.', $this->namespace . '\\' . $node->name, gettype($messages)));
}
foreach ($messages as $message) {
if (!$message instanceof Message) {
- throw new RuntimeException(sprintf('%s::getTranslationMessages() was expected to return an array of messages, but got an array which contains an item of type %s.', $this->namespace.'\\'.$node->name, gettype($message)));
+ throw new RuntimeException(sprintf('%s::getTranslationMessages() was expected to return an array of messages, but got an array which contains an item of type %s.', $this->namespace . '\\' . $node->name, gettype($message)));
}
$this->catalogue->add($message);
@@ -135,13 +130,13 @@ public function enterNode(Node $node)
*/
public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, array $ast)
{
- $this->file = $file;
$this->catalogue = $catalogue;
$this->traverser->traverse($ast);
}
/**
* @param array $nodes
+ *
* @return void
*/
public function beforeTraverse(array $nodes)
@@ -150,6 +145,7 @@ public function beforeTraverse(array $nodes)
/**
* @param Node $node
+ *
* @return void
*/
public function leaveNode(Node $node)
@@ -158,24 +154,17 @@ public function leaveNode(Node $node)
/**
* @param array $nodes
+ *
* @return void
*/
public function afterTraverse(array $nodes)
{
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- */
public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue)
{
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- */
public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, TwigNode $ast)
{
}
diff --git a/Translation/Extractor/File/TwigFileExtractor.php b/Translation/Extractor/File/TwigFileExtractor.php
index 6b310b78..be1268f9 100644
--- a/Translation/Extractor/File/TwigFileExtractor.php
+++ b/Translation/Extractor/File/TwigFileExtractor.php
@@ -1,5 +1,7 @@
*
@@ -19,17 +21,17 @@
namespace JMS\TranslationBundle\Translation\Extractor\File;
use JMS\TranslationBundle\Exception\RuntimeException;
-use JMS\TranslationBundle\Translation\FileSourceFactory;
-use Symfony\Bridge\Twig\Node\TransNode;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
+use JMS\TranslationBundle\Translation\FileSourceFactory;
+use Symfony\Bridge\Twig\Node\TransNode;
use Twig\Environment;
-use Twig\NodeTraverser;
-use Twig\NodeVisitor\AbstractNodeVisitor;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Node;
+use Twig\NodeTraverser;
+use Twig\NodeVisitor\AbstractNodeVisitor;
class TwigFileExtractor extends AbstractNodeVisitor implements FileVisitorInterface
{
@@ -56,17 +58,12 @@ class TwigFileExtractor extends AbstractNodeVisitor implements FileVisitorInterf
/**
* @var array
*/
- private $stack = array();
+ private $stack = [];
- /**
- * TwigFileExtractor constructor.
- * @param Environment $env
- * @param FileSourceFactory $fileSourceFactory
- */
public function __construct(Environment $env, FileSourceFactory $fileSourceFactory)
{
$this->fileSourceFactory = $fileSourceFactory;
- $this->traverser = new NodeTraverser($env, array($this));
+ $this->traverser = new NodeTraverser($env, [$this]);
}
/**
@@ -94,6 +91,7 @@ protected function doEnterNode(Node $node, Environment $env)
$idNode = $node->getNode('node');
if (!$idNode instanceof ConstantExpression) {
return $node;
+
// FIXME: see below
// throw new \RuntimeException(sprintf('Cannot infer translation id from node "%s". Please refactor to only translate constants.', get_class($idNode)));
}
@@ -106,6 +104,7 @@ protected function doEnterNode(Node $node, Environment $env)
$argument = $arguments[$index];
if (! $argument instanceof ConstantExpression) {
return $node;
+
// FIXME: Throw exception if there is some way for the user to turn this off
// on a case-by-case basis, similar to @Ignore in PHP
}
@@ -133,7 +132,7 @@ protected function doEnterNode(Node $node, Environment $env)
throw new RuntimeException(sprintf('The first argument of the "%s" filter must be a constant expression, such as a string.', $name));
}
- $message->{'set'.$name}($text->getAttribute('value'));
+ $message->{'set' . $name}($text->getAttribute('value'));
} elseif ('trans' === $name) {
break;
}
@@ -154,10 +153,6 @@ public function getPriority()
return 0;
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- */
public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, Node $ast)
{
$this->file = $file;
@@ -193,10 +188,6 @@ protected function doLeaveNode(Node $node, Environment $env)
return $node;
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- */
public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue)
{
}
diff --git a/Translation/Extractor/File/ValidationExtractor.php b/Translation/Extractor/File/ValidationExtractor.php
index 07459845..1ca53226 100644
--- a/Translation/Extractor/File/ValidationExtractor.php
+++ b/Translation/Extractor/File/ValidationExtractor.php
@@ -1,5 +1,7 @@
*
@@ -18,15 +20,15 @@
namespace JMS\TranslationBundle\Translation\Extractor\File;
+use JMS\TranslationBundle\Model\Message;
+use JMS\TranslationBundle\Model\MessageCatalogue;
+use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
use PhpParser\Node;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\MetadataFactoryInterface as LegacyMetadataFactoryInterface;
-use JMS\TranslationBundle\Model\Message;
-use JMS\TranslationBundle\Model\MessageCatalogue;
-use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
use Twig\Node\Node as TwigNode;
/**
@@ -46,11 +48,6 @@ class ValidationExtractor implements FileVisitorInterface, NodeVisitor
*/
private $traverser;
- /**
- * @var \SplFileInfo
- */
- private $file;
-
/**
* @var MessageCatalogue
*/
@@ -61,10 +58,6 @@ class ValidationExtractor implements FileVisitorInterface, NodeVisitor
*/
private $namespace = '';
- /**
- * ValidationExtractor constructor.
- * @param $metadataFactory
- */
public function __construct($metadataFactory)
{
if (! (
@@ -72,7 +65,7 @@ public function __construct($metadataFactory)
|| $metadataFactory instanceof LegacyMetadataFactoryInterface
|| $metadataFactory instanceof ClassMetadataFactoryInterface
)) {
- throw new \InvalidArgumentException(sprintf('%s expects an instance of MetadataFactoryInterface or ClassMetadataFactoryInterface', get_class($this)));
+ throw new \InvalidArgumentException(sprintf('%s expects an instance of MetadataFactoryInterface or ClassMetadataFactoryInterface', static::class));
}
$this->metadataFactory = $metadataFactory;
@@ -82,6 +75,7 @@ public function __construct($metadataFactory)
/**
* @param Node $node
+ *
* @return void
*/
public function enterNode(Node $node)
@@ -98,13 +92,13 @@ public function enterNode(Node $node)
return;
}
- $name = '' === $this->namespace ? $node->name : $this->namespace.'\\'.$node->name;
+ $name = '' === $this->namespace ? (string) $node->name : $this->namespace . '\\' . $node->name;
if (!class_exists($name)) {
return;
}
- $metadata = ($this->metadataFactory instanceof ClassMetadataFactoryInterface)? $this->metadataFactory->getClassMetadata($name) : $this->metadataFactory->getMetadataFor($name);
+ $metadata = $this->metadataFactory instanceof ClassMetadataFactoryInterface? $this->metadataFactory->getClassMetadata($name) : $this->metadataFactory->getMetadataFor($name);
if (!$metadata->hasConstraints() && !count($metadata->getConstrainedProperties())) {
return;
}
@@ -124,7 +118,6 @@ public function enterNode(Node $node)
*/
public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, array $ast)
{
- $this->file = $file;
$this->namespace = '';
$this->catalogue = $catalogue;
$this->traverser->traverse($ast);
@@ -132,6 +125,7 @@ public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, ar
/**
* @param array $nodes
+ *
* @return void
*/
public function beforeTraverse(array $nodes)
@@ -140,6 +134,7 @@ public function beforeTraverse(array $nodes)
/**
* @param Node $node
+ *
* @return void
*/
public function leaveNode(Node $node)
@@ -148,24 +143,17 @@ public function leaveNode(Node $node)
/**
* @param array $nodes
+ *
* @return void
*/
public function afterTraverse(array $nodes)
{
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- */
public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue)
{
}
- /**
- * @param \SplFileInfo $file
- * @param MessageCatalogue $catalogue
- */
public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, TwigNode $ast)
{
}
diff --git a/Translation/Extractor/FileExtractor.php b/Translation/Extractor/FileExtractor.php
index 152cb555..34c5e2a5 100644
--- a/Translation/Extractor/FileExtractor.php
+++ b/Translation/Extractor/FileExtractor.php
@@ -1,5 +1,7 @@
*
@@ -18,17 +20,17 @@
namespace JMS\TranslationBundle\Translation\Extractor;
-use JMS\TranslationBundle\Twig\DefaultApplyingNodeVisitor;
use JMS\TranslationBundle\Exception\InvalidArgumentException;
+use JMS\TranslationBundle\Logger\LoggerAwareInterface;
+use JMS\TranslationBundle\Model\MessageCatalogue;
+use JMS\TranslationBundle\Translation\ExtractorInterface;
+use JMS\TranslationBundle\Twig\DefaultApplyingNodeVisitor;
+use JMS\TranslationBundle\Twig\RemovingNodeVisitor;
use PhpParser\Error;
use PhpParser\Lexer;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use Psr\Log\LoggerInterface;
-use JMS\TranslationBundle\Logger\LoggerAwareInterface;
-use JMS\TranslationBundle\Twig\RemovingNodeVisitor;
-use JMS\TranslationBundle\Translation\ExtractorInterface;
-use JMS\TranslationBundle\Model\MessageCatalogue;
use Symfony\Component\Finder\Finder;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
@@ -80,12 +82,12 @@ class FileExtractor implements ExtractorInterface, LoggerAwareInterface
/**
* @var array
*/
- private $excludedNames = array();
+ private $excludedNames = [];
/**
* @var array
*/
- private $excludedDirs = array();
+ private $excludedDirs = [];
/**
* @var LoggerInterface
@@ -93,7 +95,6 @@ class FileExtractor implements ExtractorInterface, LoggerAwareInterface
private $logger;
/**
- * FileExtractor constructor.
* @param Environment $twig
* @param LoggerInterface $logger
* @param array $visitors
@@ -104,7 +105,7 @@ public function __construct(Environment $twig, LoggerInterface $logger, array $v
$this->visitors = $visitors;
$this->setLogger($logger);
$lexer = new Lexer();
- if (class_exists('PhpParser\ParserFactory')) {
+ if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$this->phpParser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
} else {
@@ -123,13 +124,10 @@ public function __construct(Environment $twig, LoggerInterface $logger, array $v
public function reset()
{
- $this->excludedNames = array();
- $this->excludedDirs = array();
+ $this->excludedNames = [];
+ $this->excludedDirs = [];
}
- /**
- * @param LoggerInterface $logger
- */
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
@@ -143,9 +141,6 @@ public function setLogger(LoggerInterface $logger)
}
}
- /**
- * @param $directory
- */
public function setDirectory($directory)
{
if (!is_dir($directory)) {
@@ -181,6 +176,7 @@ public function setPattern(array $pattern)
/**
* @return MessageCatalogue
+ *
* @throws \Exception
*/
public function extract()
@@ -207,13 +203,13 @@ public function extract()
}
$curTwigLoader = $this->twig->getLoader();
- $this->twig->setLoader(new ArrayLoader(array()));
+ $this->twig->setLoader(new ArrayLoader([]));
try {
$catalogue = new MessageCatalogue();
foreach ($finder as $file) {
$visitingMethod = 'visitFile';
- $visitingArgs = array($file, $catalogue);
+ $visitingArgs = [$file, $catalogue];
$this->logger->debug(sprintf('Parsing file "%s"', $file));
@@ -236,7 +232,7 @@ public function extract()
}
foreach ($this->visitors as $visitor) {
- call_user_func_array(array($visitor, $visitingMethod), $visitingArgs);
+ call_user_func_array([$visitor, $visitingMethod], $visitingArgs);
}
}
@@ -252,7 +248,7 @@ public function extract()
}
return $catalogue;
- } catch (\Exception $ex) {
+ } catch (\Throwable $ex) {
if (null !== $curTwigLoader) {
$this->twig->setLoader($curTwigLoader);
}
diff --git a/Translation/Extractor/FileVisitorInterface.php b/Translation/Extractor/FileVisitorInterface.php
index d594c147..21e324aa 100644
--- a/Translation/Extractor/FileVisitorInterface.php
+++ b/Translation/Extractor/FileVisitorInterface.php
@@ -1,5 +1,7 @@
*
diff --git a/Translation/ExtractorInterface.php b/Translation/ExtractorInterface.php
index 390e621f..c7afa30f 100644
--- a/Translation/ExtractorInterface.php
+++ b/Translation/ExtractorInterface.php
@@ -1,5 +1,7 @@
*
diff --git a/Translation/ExtractorManager.php b/Translation/ExtractorManager.php
index e8e253cb..82af80f3 100644
--- a/Translation/ExtractorManager.php
+++ b/Translation/ExtractorManager.php
@@ -1,5 +1,7 @@
*
@@ -19,17 +21,17 @@
namespace JMS\TranslationBundle\Translation;
use JMS\TranslationBundle\Exception\InvalidArgumentException;
-use Psr\Log\LoggerInterface;
+use JMS\TranslationBundle\Logger\LoggerAwareInterface;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Extractor\FileExtractor;
-use JMS\TranslationBundle\Logger\LoggerAwareInterface;
+use Psr\Log\LoggerInterface;
class ExtractorManager implements ExtractorInterface
{
private $fileExtractor;
private $customExtractors;
- private $directories = array();
- private $enabledExtractors = array();
+ private $directories = [];
+ private $enabledExtractors = [];
private $logger;
/**
@@ -37,7 +39,7 @@ class ExtractorManager implements ExtractorInterface
* @param LoggerInterface $logger
* @param array $customExtractors
*/
- public function __construct(FileExtractor $extractor, LoggerInterface $logger, array $customExtractors = array())
+ public function __construct(FileExtractor $extractor, LoggerInterface $logger, array $customExtractors = [])
{
$this->fileExtractor = $extractor;
$this->customExtractors = $customExtractors;
@@ -46,14 +48,11 @@ public function __construct(FileExtractor $extractor, LoggerInterface $logger, a
public function reset()
{
- $this->directories = array();
- $this->enabledExtractors = array();
+ $this->directories = [];
+ $this->enabledExtractors = [];
$this->fileExtractor->reset();
}
- /**
- * @param LoggerInterface $logger
- */
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
@@ -73,16 +72,17 @@ public function setLogger(LoggerInterface $logger)
*/
public function setDirectories(array $directories)
{
- $this->directories = array();
-
+ $this->directories = [];
+
foreach ($directories as $dir) {
$this->addDirectory($dir);
}
}
/**
- * @param $directory
- * @throws \JMS\TranslationBundle\Exception\InvalidArgumentException
+ * @param string $directory
+ *
+ * @throws InvalidArgumentException
*/
public function addDirectory($directory)
{
@@ -111,7 +111,8 @@ public function setExcludedNames(array $names)
/**
* @param array $aliases
- * @throws \JMS\TranslationBundle\Exception\InvalidArgumentException
+ *
+ * @throws InvalidArgumentException
*/
public function setEnabledExtractors(array $aliases)
{
@@ -125,7 +126,7 @@ public function setEnabledExtractors(array $aliases)
}
/**
- * @return \JMS\TranslationBundle\Model\MessageCatalogue
+ * @return MessageCatalogue
*/
public function extract()
{
diff --git a/Translation/FileSourceFactory.php b/Translation/FileSourceFactory.php
index bf496228..ad7a252a 100644
--- a/Translation/FileSourceFactory.php
+++ b/Translation/FileSourceFactory.php
@@ -1,5 +1,7 @@
*
@@ -23,9 +25,9 @@
class FileSourceFactory
{
/**
- * @var string
- *
* @deprecated Will be removed in 2.0. Use $baseDir instead.
+ *
+ * @var string
*/
protected $kernelRoot;
@@ -35,11 +37,9 @@ class FileSourceFactory
protected $baseDir;
/**
- * FileSourceFactory constructor.
- *
* @param string $kernelRoot
*/
- public function __construct($kernelRoot, string $baseDir = null)
+ public function __construct($kernelRoot, ?string $baseDir = null)
{
$this->kernelRoot = $kernelRoot;
$this->baseDir = $baseDir ?? $kernelRoot;
@@ -49,8 +49,8 @@ public function __construct($kernelRoot, string $baseDir = null)
* Generate a new FileSource with a relative path.
*
* @param \SplFileInfo $file
- * @param null|int $line
- * @param null|int $column
+ * @param int|null $line
+ * @param int|null $column
*
* @return FileSource
*/
@@ -82,16 +82,16 @@ private function getRelativePath($path)
// If they are not equal
if ($pathCurrentDirectory !== $rootCurrentDirectory) {
// Prepend $relativePath with "/.."
- $relativePath = $ds.'..'.$relativePath;
+ $relativePath = $ds . '..' . $relativePath;
if ($pathCurrentDirectory) {
// Append the current directory
- $relativePath .= $pathCurrentDirectory.$ds;
+ $relativePath .= $pathCurrentDirectory . $ds;
}
}
}
// Add the rest of the $pathArray on the relative directory
- return rtrim($relativePath.implode($ds, $pathArray), '/');
+ return rtrim($relativePath . implode($ds, $pathArray), '/');
}
}
diff --git a/Translation/FileWriter.php b/Translation/FileWriter.php
index c9ef006e..690fa3e6 100644
--- a/Translation/FileWriter.php
+++ b/Translation/FileWriter.php
@@ -1,5 +1,7 @@
*
@@ -37,28 +39,30 @@ class FileWriter
/**
* @param array $dumpers
*/
- public function __construct(array $dumpers = array())
+ public function __construct(array $dumpers = [])
{
$this->dumpers = $dumpers;
}
/**
- * @param \JMS\TranslationBundle\Model\MessageCatalogue $catalogue
+ * @param MessageCatalogue $catalogue
* @param string $domain
* @param string $filePath
* @param string $format
- * @throws \JMS\TranslationBundle\Exception\InvalidArgumentException
+ *
+ * @throws InvalidArgumentException
*/
public function write(MessageCatalogue $catalogue, $domain, $filePath, $format)
{
if (!isset($this->dumpers[$format])) {
$allowedFormats = array_keys($this->dumpers);
- $allowedFormatsString = join(',', $allowedFormats);
+ $allowedFormatsString = implode(',', $allowedFormats);
+
throw new InvalidArgumentException(sprintf('The format "%s" is not supported. Allowed formats:%s', $format, $allowedFormatsString));
}
// sort messages before dumping
- $catalogue->getDomain($domain)->sort(function ($a, $b) {
+ $catalogue->getDomain($domain)->sort(static function ($a, $b) {
return strcmp($a->getId(), $b->getId());
});
diff --git a/Translation/Loader/LoaderInterface.php b/Translation/Loader/LoaderInterface.php
index c02c2f51..6446b7e6 100644
--- a/Translation/Loader/LoaderInterface.php
+++ b/Translation/Loader/LoaderInterface.php
@@ -1,5 +1,7 @@
*
@@ -37,6 +39,7 @@ interface LoaderInterface
* @param mixed $resource
* @param string $locale
* @param string $domain
+ *
* @return MessageCatalogue
*/
public function load($resource, $locale, $domain = 'messages');
diff --git a/Translation/Loader/Symfony/XliffLoader.php b/Translation/Loader/Symfony/XliffLoader.php
index 668953c1..8d4836fb 100644
--- a/Translation/Loader/Symfony/XliffLoader.php
+++ b/Translation/Loader/Symfony/XliffLoader.php
@@ -1,5 +1,7 @@
*
@@ -20,8 +22,8 @@
use JMS\TranslationBundle\Exception\RuntimeException;
use Symfony\Component\Config\Resource\FileResource;
-use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Loader\LoaderInterface;
+use Symfony\Component\Translation\MessageCatalogue;
/**
* XLIFF loader.
@@ -35,8 +37,8 @@
class XliffLoader implements LoaderInterface
{
/**
- * {@inheritdoc}
- */
+ * {@inheritdoc}
+ */
public function load($resource, $locale, $domain = 'messages')
{
$previous = libxml_use_internal_errors(true);
@@ -53,8 +55,8 @@ public function load($resource, $locale, $domain = 'messages')
$catalogue = new MessageCatalogue($locale);
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
- $id = ($resName = (string) $translation->attributes()->resname)
- ? $resName : (string) $translation->source;
+ $resName = (string) $translation->attributes()->resname;
+ $id = $resName ?: (string) $translation->source;
$catalogue->set($id, (string) $translation->target, $domain);
}
diff --git a/Translation/Loader/SymfonyLoaderAdapter.php b/Translation/Loader/SymfonyLoaderAdapter.php
index 198482cb..7832f83b 100644
--- a/Translation/Loader/SymfonyLoaderAdapter.php
+++ b/Translation/Loader/SymfonyLoaderAdapter.php
@@ -1,5 +1,7 @@
*
@@ -18,8 +20,8 @@
namespace JMS\TranslationBundle\Translation\Loader;
-use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Model\Message;
+use JMS\TranslationBundle\Model\MessageCatalogue;
use Symfony\Component\Translation\Loader\LoaderInterface as SymfonyLoader;
/**
@@ -36,10 +38,6 @@ class SymfonyLoaderAdapter implements LoaderInterface
*/
private $loader;
- /**
- * SymfonyLoaderAdapter constructor.
- * @param SymfonyLoader $loader
- */
public function __construct(SymfonyLoader $loader)
{
$this->loader = $loader;
@@ -52,6 +50,7 @@ public function __construct(SymfonyLoader $loader)
* @param mixed $resource
* @param string $locale
* @param string $domain
+ *
* @return MessageCatalogue
*/
public function load($resource, $locale, $domain = 'messages')
diff --git a/Translation/Loader/XliffLoader.php b/Translation/Loader/XliffLoader.php
index 307aceed..b6148bc9 100644
--- a/Translation/Loader/XliffLoader.php
+++ b/Translation/Loader/XliffLoader.php
@@ -1,5 +1,7 @@
*
@@ -19,9 +21,9 @@
namespace JMS\TranslationBundle\Translation\Loader;
use JMS\TranslationBundle\Exception\RuntimeException;
-use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Model\FileSource;
use JMS\TranslationBundle\Model\Message\XliffMessage as Message;
+use JMS\TranslationBundle\Model\MessageCatalogue;
class XliffLoader implements LoaderInterface
{
@@ -29,6 +31,7 @@ class XliffLoader implements LoaderInterface
* @param mixed $resource
* @param string $locale
* @param string $domain
+ *
* @return MessageCatalogue
*/
public function load($resource, $locale, $domain = 'messages')
@@ -51,25 +54,24 @@ public function load($resource, $locale, $domain = 'messages')
$catalogue = new MessageCatalogue();
$catalogue->setLocale($locale);
- /** @var \SimpleXMLElement $trans */
foreach ($doc->xpath('//xliff:trans-unit') as $trans) {
- $id = ($resName = (string) $trans->attributes()->resname)
- ? $resName : (string) $trans->source;
+ \assert($trans instanceof \SimpleXMLElement);
+ $resName = (string) $trans->attributes()->resname;
+ $id = $resName ?: (string) $trans->source;
- /** @var Message $m */
$m = Message::create($id, $domain)
->setDesc((string) $trans->source)
- ->setLocaleString((string) $trans->target)
- ;
+ ->setLocaleString((string) $trans->target);
+ \assert($m instanceof Message);
- $m->setApproved($trans['approved']=='yes');
+ $m->setApproved($trans['approved']==='yes');
if (isset($trans->target['state'])) {
$m->setState((string) $trans->target['state']);
}
// Create closure
- $addNoteToMessage = function(Message $m, $note) {
+ $addNoteToMessage = static function (Message $m, $note) {
$m->addNote((string) $note, isset($note['from']) ? ((string) $note['from']) : null);
};
@@ -93,8 +95,8 @@ public function load($resource, $locale, $domain = 'messages')
$column = (string) $file->attributes()->column;
$m->addSource(new FileSource(
(string) $file,
- $line ? (integer) $line : null,
- $column ? (integer) $column : null
+ $line ? (int) $line : null,
+ $column ? (int) $column : null
));
}
}
diff --git a/Translation/LoaderManager.php b/Translation/LoaderManager.php
index 1f357482..a8e072a9 100644
--- a/Translation/LoaderManager.php
+++ b/Translation/LoaderManager.php
@@ -1,5 +1,7 @@
*
@@ -20,6 +22,7 @@
use JMS\TranslationBundle\Exception\InvalidArgumentException;
use JMS\TranslationBundle\Model\MessageCatalogue;
+use JMS\TranslationBundle\Translation\Loader\LoaderInterface;
use JMS\TranslationBundle\Util\FileUtils;
class LoaderManager
@@ -35,10 +38,11 @@ public function __construct(array $loaders)
}
/**
- * @param $file
- * @param $format
- * @param $locale
+ * @param mixed $file
+ * @param string $format
+ * @param string $locale
* @param string $domain
+ *
* @return mixed
*/
public function loadFile($file, $format, $locale, $domain = 'messages')
@@ -47,9 +51,10 @@ public function loadFile($file, $format, $locale, $domain = 'messages')
}
/**
- * @param $dir
- * @param $targetLocale
- * @return \JMS\TranslationBundle\Model\MessageCatalogue
+ * @param string $dir
+ * @param string $targetLocale
+ *
+ * @return MessageCatalogue
*/
public function loadFromDirectory($dir, $targetLocale)
{
@@ -64,7 +69,7 @@ public function loadFromDirectory($dir, $targetLocale)
continue;
}
- list($format, $file) = $data;
+ [$format, $file] = $data;
$catalogue->merge($this->getLoader($format)->load($file, $locale, $domain));
}
@@ -74,10 +79,11 @@ public function loadFromDirectory($dir, $targetLocale)
}
/**
- * @param $format
- * @return mixed
+ * @param string $format
+ *
+ * @return LoaderInterface
+ *
* @throws \InvalidArgumentException
- * @return \JMS\TranslationBundle\Translation\Loader\LoaderInterface
*/
protected function getLoader($format)
{
diff --git a/Translation/TranslationContainerInterface.php b/Translation/TranslationContainerInterface.php
index dc8eb9bd..52ad08f6 100644
--- a/Translation/TranslationContainerInterface.php
+++ b/Translation/TranslationContainerInterface.php
@@ -1,5 +1,7 @@
*
diff --git a/Translation/Updater.php b/Translation/Updater.php
index da4b4cce..d240d002 100644
--- a/Translation/Updater.php
+++ b/Translation/Updater.php
@@ -1,5 +1,7 @@
*
@@ -18,11 +20,11 @@
namespace JMS\TranslationBundle\Translation;
-use JMS\TranslationBundle\Translation\Comparison\ChangeSet;
-use JMS\TranslationBundle\Util\FileUtils;
use JMS\TranslationBundle\Exception\RuntimeException;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Comparison\CatalogueComparator;
+use JMS\TranslationBundle\Translation\Comparison\ChangeSet;
+use JMS\TranslationBundle\Util\FileUtils;
use Psr\Log\LoggerInterface;
use Symfony\Component\Finder\Finder;
@@ -72,12 +74,6 @@ class Updater
*/
private $writer;
- /**
- * @param LoaderManager $loader
- * @param ExtractorManager $extractor
- * @param LoggerInterface $logger
- * @param FileWriter $writer
- */
public function __construct(LoaderManager $loader, ExtractorManager $extractor, LoggerInterface $logger, FileWriter $writer)
{
$this->loader = $loader;
@@ -86,9 +82,6 @@ public function __construct(LoaderManager $loader, ExtractorManager $extractor,
$this->writer = $writer;
}
- /**
- * @param LoggerInterface $logger
- */
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
@@ -97,6 +90,7 @@ public function setLogger(LoggerInterface $logger)
/**
* @param Config $config
+ *
* @return ChangeSet
*/
public function getChangeSet(Config $config)
@@ -124,8 +118,7 @@ public function updateTranslation($file, $format, $domain, $locale, $id, $trans)
$catalogue
->get($id, $domain)
->setLocaleString($trans)
- ->setNew(false)
- ;
+ ->setNew(false);
$this->writer->write($catalogue, $domain, $file, $format);
}
@@ -155,8 +148,8 @@ public function process(Config $config)
$format = $this->detectOutputFormat($name);
// delete translation files of other formats
- foreach (Finder::create()->name('/^'.$name.'\.'.$this->config->getLocale().'\.[^\.]+$/')->in($this->config->getTranslationsDir())->depth('< 1')->files() as $file) {
- if ('.'.$format === substr((string) $file, -1 * strlen('.'.$format))) {
+ foreach (Finder::create()->name('/^' . $name . '\.' . $this->config->getLocale() . '\.[^\.]+$/')->in($this->config->getTranslationsDir())->depth('< 1')->files() as $file) {
+ if ('.' . $format === substr((string) $file, -1 * strlen('.' . $format))) {
continue;
}
@@ -167,7 +160,7 @@ public function process(Config $config)
}
}
- $outputFile = $this->config->getTranslationsDir().'/'.$name.'.'.$this->config->getLocale().'.'.$format;
+ $outputFile = $this->config->getTranslationsDir() . '/' . $name . '.' . $this->config->getLocale() . '.' . $format;
$this->logger->info(sprintf('Writing translation file "%s".', $outputFile));
$this->writer->write($this->scannedCatalogue, $name, $outputFile, $format);
}
@@ -176,9 +169,11 @@ public function process(Config $config)
/**
* Detects the most suitable output format to use.
*
- * @param $currentDomain
- * @return string
* @internal param string $domain
+ *
+ * @param string $currentDomain
+ *
+ * @return string
*/
private function detectOutputFormat($currentDomain)
{
@@ -190,7 +185,7 @@ private function detectOutputFormat($currentDomain)
$otherDomainFormat = $localeFormat = $otherLocaleFormat = null;
foreach (FileUtils::findTranslationFiles($this->config->getTranslationsDir()) as $domain => $locales) {
foreach ($locales as $locale => $fileData) {
- list($format, ) = $fileData;
+ [$format ] = $fileData;
if ($currentDomain !== $domain) {
$otherDomainFormat = $format;
@@ -221,14 +216,11 @@ private function detectOutputFormat($currentDomain)
return $this->config->getDefaultOutputFormat();
}
- /**
- * @param Config $config
- */
private function setConfig(Config $config)
{
$this->config = $config;
- $this->logger->info(sprintf("Loading catalogues from \"%s\"", $config->getTranslationsDir()));
+ $this->logger->info(sprintf('Loading catalogues from "%s"', $config->getTranslationsDir()));
$this->existingCatalogue = new MessageCatalogue();
// load external resources, so current translations can be reused in the final translation
@@ -240,7 +232,8 @@ private function setConfig(Config $config)
}
$this->existingCatalogue->merge($this->loader->loadFromDirectory(
- $config->getTranslationsDir(), $config->getLocale()
+ $config->getTranslationsDir(),
+ $config->getLocale()
));
$this->extractor->reset();
@@ -249,7 +242,7 @@ private function setConfig(Config $config)
$this->extractor->setExcludedNames($config->getExcludedNames());
$this->extractor->setEnabledExtractors($config->getEnabledExtractors());
- $this->logger->info("Extracting translation keys");
+ $this->logger->info('Extracting translation keys');
$this->scannedCatalogue = $this->extractor->extract();
$this->scannedCatalogue->setLocale($config->getLocale());
diff --git a/Twig/DefaultApplyingNodeVisitor.php b/Twig/DefaultApplyingNodeVisitor.php
index 516d16e6..b4041969 100644
--- a/Twig/DefaultApplyingNodeVisitor.php
+++ b/Twig/DefaultApplyingNodeVisitor.php
@@ -1,5 +1,7 @@
*
@@ -21,13 +23,13 @@
use JMS\TranslationBundle\Exception\RuntimeException;
use JMS\TranslationBundle\Twig\Node\Transchoice;
use Twig\Environment;
-use Twig\NodeVisitor\AbstractNodeVisitor;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\Binary\EqualBinary;
use Twig\Node\Expression\ConditionalExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Node;
+use Twig\NodeVisitor\AbstractNodeVisitor;
/**
* Applies the value of the "desc" filter if the "trans" filter has no
@@ -44,9 +46,6 @@ class DefaultApplyingNodeVisitor extends AbstractNodeVisitor
*/
private $enabled = true;
- /**
- * @param $bool
- */
public function setEnabled($bool)
{
$this->enabled = (bool) $bool;
@@ -84,7 +83,7 @@ public function doEnterNode(Node $node, Environment $env)
// so that we can catch a possible exception when the default translation has not yet
// been extracted
if ('transchoice' === $transNode->getNode('filter')->getAttribute('value')) {
- $transchoiceArguments = new ArrayExpression(array(), $transNode->getTemplateLine());
+ $transchoiceArguments = new ArrayExpression([], $transNode->getTemplateLine());
$transchoiceArguments->addElement($wrappingNode->getNode('node'));
$transchoiceArguments->addElement($defaultNode);
foreach ($wrappingNode->getNode('arguments') as $arg) {
diff --git a/Twig/Node/Transchoice.php b/Twig/Node/Transchoice.php
index e07405f6..b83b5cf0 100644
--- a/Twig/Node/Transchoice.php
+++ b/Twig/Node/Transchoice.php
@@ -1,5 +1,7 @@
*
@@ -18,6 +20,7 @@
namespace JMS\TranslationBundle\Twig\Node;
+use JMS\TranslationBundle\Twig\TranslationExtension;
use Twig\Compiler;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\ArrayExpression;
@@ -26,7 +29,7 @@ class Transchoice extends AbstractExpression
{
public function __construct(ArrayExpression $arguments, $lineno)
{
- parent::__construct(array('arguments' => $arguments), array(), $lineno);
+ parent::__construct(['arguments' => $arguments], [], $lineno);
}
public function compile(Compiler $compiler)
@@ -34,7 +37,7 @@ public function compile(Compiler $compiler)
$compiler->raw(
sprintf(
'$this->env->getExtension(\'%s\')->%s(',
- 'JMS\TranslationBundle\Twig\TranslationExtension',
+ TranslationExtension::class,
'transchoiceWithDefault'
)
);
diff --git a/Twig/NormalizingNodeVisitor.php b/Twig/NormalizingNodeVisitor.php
index a7a467da..4ef0e610 100644
--- a/Twig/NormalizingNodeVisitor.php
+++ b/Twig/NormalizingNodeVisitor.php
@@ -1,5 +1,7 @@
*
@@ -19,10 +21,10 @@
namespace JMS\TranslationBundle\Twig;
use Twig\Environment;
-use Twig\NodeVisitor\AbstractNodeVisitor;
use Twig\Node\Expression\Binary\ConcatBinary;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Node;
+use Twig\NodeVisitor\AbstractNodeVisitor;
/**
* Performs equivalence transformations on the AST to ensure that
@@ -50,7 +52,7 @@ protected function doLeaveNode(Node $node, Environment $env)
if ($node instanceof ConcatBinary
&& ($left = $node->getNode('left')) instanceof ConstantExpression
&& ($right = $node->getNode('right')) instanceof ConstantExpression) {
- return new ConstantExpression($left->getAttribute('value').$right->getAttribute('value'), $left->getTemplateLine());
+ return new ConstantExpression($left->getAttribute('value') . $right->getAttribute('value'), $left->getTemplateLine());
}
return $node;
diff --git a/Twig/RemovingNodeVisitor.php b/Twig/RemovingNodeVisitor.php
index 12bd8096..c5a8d4e2 100644
--- a/Twig/RemovingNodeVisitor.php
+++ b/Twig/RemovingNodeVisitor.php
@@ -1,5 +1,7 @@
*
@@ -19,9 +21,9 @@
namespace JMS\TranslationBundle\Twig;
use Twig\Environment;
-use Twig\NodeVisitor\AbstractNodeVisitor;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Node;
+use Twig\NodeVisitor\AbstractNodeVisitor;
/**
* Removes translation metadata filters from the AST.
@@ -35,9 +37,6 @@ class RemovingNodeVisitor extends AbstractNodeVisitor
*/
private $enabled = true;
- /**
- * @param $bool
- */
public function setEnabled($bool)
{
$this->enabled = (bool) $bool;
diff --git a/Twig/TranslationExtension.php b/Twig/TranslationExtension.php
index 931d78fe..20ac34d1 100644
--- a/Twig/TranslationExtension.php
+++ b/Twig/TranslationExtension.php
@@ -1,5 +1,7 @@
*
@@ -41,7 +43,6 @@ class TranslationExtension extends AbstractExtension
private $debug;
/**
- * TranslationExtension constructor.
* @param TranslatorInterface|LegacyTranslatorInterface $translator
* @param bool $debug
*/
@@ -49,8 +50,7 @@ public function __construct($translator, $debug = false)
{
if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
throw new \InvalidArgumentException(sprintf(
- 'Argument 1 must be an instance of %s or %s, instance of %s given'
- ,
+ 'Argument 1 must be an instance of %s or %s, instance of %s given',
TranslatorInterface::class,
LegacyTranslatorInterface::class,
get_class($translator)
@@ -66,10 +66,10 @@ public function __construct($translator, $debug = false)
*/
public function getNodeVisitors()
{
- $visitors = array(
+ $visitors = [
new NormalizingNodeVisitor(),
new RemovingNodeVisitor(),
- );
+ ];
if ($this->debug) {
$visitors[] = new DefaultApplyingNodeVisitor();
@@ -83,10 +83,10 @@ public function getNodeVisitors()
*/
public function getFilters()
{
- return array(
- new TwigFilter('desc', array($this, 'desc')),
- new TwigFilter('meaning', array($this, 'meaning')),
- );
+ return [
+ new TwigFilter('desc', [$this, 'desc']),
+ new TwigFilter('meaning', [$this, 'meaning']),
+ ];
}
/**
@@ -94,34 +94,36 @@ public function getFilters()
* @param string $defaultMessage
* @param int $count
* @param array $arguments
- * @param null|string $domain
- * @param null|string $locale
+ * @param string|null $domain
+ * @param string|null $locale
+ *
* @return string
*/
- public function transchoiceWithDefault($message, $defaultMessage, $count, array $arguments = array(), $domain = null, $locale = null)
+ public function transchoiceWithDefault($message, $defaultMessage, $count, array $arguments = [], $domain = null, $locale = null)
{
if (null === $domain) {
$domain = 'messages';
}
- if (false == $this->translator->getCatalogue($locale)->defines($message, $domain)) {
- return $this->doTransChoice($defaultMessage, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
+ if (false === $this->translator->getCatalogue($locale)->defines($message, $domain)) {
+ return $this->doTransChoice($defaultMessage, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale);
}
- return $this->doTransChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
+ return $this->doTransChoice($message, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale);
}
private function doTransChoice($message, $count, array $arguments, $domain, $locale)
{
if ($this->translator instanceof LegacyTranslatorInterface) {
- return $this->translator->transChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
+ return $this->translator->transChoice($message, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale);
}
- return $this->translator->trans($message, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
+ return $this->translator->trans($message, array_merge(['%count%' => $count], $arguments), $domain, $locale);
}
/**
- * @param $v
+ * @param mixed $v
+ *
* @return mixed
*/
public function desc($v)
@@ -130,7 +132,8 @@ public function desc($v)
}
/**
- * @param $v
+ * @param mixed $v
+ *
* @return mixed
*/
public function meaning($v)
diff --git a/Util/FileUtils.php b/Util/FileUtils.php
index 62100f80..99d2321e 100644
--- a/Util/FileUtils.php
+++ b/Util/FileUtils.php
@@ -1,5 +1,7 @@
*
@@ -35,22 +37,22 @@ abstract class FileUtils
* )
* )
*
- * @throws \RuntimeException
- *
* @return array
+ *
+ * @throws \RuntimeException
*/
public static function findTranslationFiles($directory)
{
- $files = array();
+ $files = [];
foreach (Finder::create()->in($directory)->depth('< 1')->files() as $file) {
if (!preg_match('/^([^\.]+)\.([^\.]+)\.([^\.]+)$/', basename((string) $file), $match)) {
continue;
}
- $files[$match[1]][$match[2]] = array(
+ $files[$match[1]][$match[2]] = [
$match[3],
- $file
- );
+ $file,
+ ];
}
uksort($files, 'strcasecmp');
diff --git a/Util/Writer.php b/Util/Writer.php
index 173a2334..cb6f0cfe 100644
--- a/Util/Writer.php
+++ b/Util/Writer.php
@@ -1,5 +1,7 @@
*
@@ -52,7 +54,7 @@ class Writer
/**
* @var array
*/
- private $changes = array();
+ private $changes = [];
/**
* @return $this
@@ -79,12 +81,13 @@ public function outdent()
}
/**
- * @param $content
+ * @param string $content
+ *
* @return $this
*/
public function writeln($content)
{
- $this->write($content."\n");
+ $this->write($content . "\n");
return $this;
}
@@ -92,12 +95,13 @@ public function writeln($content)
public function revert()
{
$change = array_pop($this->changes);
- $this->changeCount -=1 ;
+ $this->changeCount -=1;
$this->content = substr($this->content, 0, -1 * strlen($change));
}
/**
- * @param $content
+ * @param string $content
+ *
* @return $this
*/
public function write($content)
@@ -129,6 +133,7 @@ public function write($content)
/**
* @param bool $preserveNewLines
+ *
* @return $this
*/
public function rtrim($preserveNewLines = true)
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 36ca4a7d..4f50e4d9 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -10,7 +10,17 @@
- Tests
+ Annotation/
+ Command/
+ Controller/
+ DependencyInjection/
+ Exception/
+ Logger/
+ Model/
+ Tests/
+ Translation/
+ Twig/
+ Util/
vendor/*
messages\.en\.php
.+\.html\.php$
@@ -18,13 +28,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -67,17 +91,32 @@
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+