Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Apply cs #532

Merged
merged 2 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Annotation/Desc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
*
Expand Down
2 changes: 2 additions & 0 deletions Annotation/Ignore.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
*
Expand Down
5 changes: 2 additions & 3 deletions Annotation/Meaning.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
*
Expand Down Expand Up @@ -30,9 +32,6 @@ final class Meaning
/** @var string @Required */
public $text;

/**
* Meaning constructor.
*/
public function __construct()
{
if (0 === func_num_args()) {
Expand Down
31 changes: 12 additions & 19 deletions Command/ExtractTranslationCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
*
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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') ?
Expand All @@ -116,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln(sprintf('Directories: <info>%s</info>', implode(', ', $config->getScanDirs())));
$output->writeln(sprintf('Excluded Directories: <info>%s</info>', $config->getExcludedDirs() ? implode(', ', $config->getExcludedDirs()) : '# none #'));
$output->writeln(sprintf('Excluded Names: <info>%s</info>', $config->getExcludedNames() ? implode(', ', $config->getExcludedNames()) : '# none #'));
$output->writeln(sprintf('Output-Format: <info>%s</info>', $config->getOutputFormat() ? $config->getOutputFormat() : '# whatever is present, if nothing then '.$config->getDefaultOutputFormat().' #'));
$output->writeln(sprintf('Output-Format: <info>%s</info>', $config->getOutputFormat() ? $config->getOutputFormat() : '# whatever is present, if nothing then ' . $config->getDefaultOutputFormat() . ' #'));
$output->writeln(sprintf('Custom Extractors: <info>%s</info>', $config->getEnabledExtractors() ? implode(', ', array_keys($config->getEnabledExtractors())) : '# none #'));
$output->writeln('============================================================');

Expand All @@ -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());
}
}
}
Expand All @@ -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')) {
Expand All @@ -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')) {
Expand Down
24 changes: 11 additions & 13 deletions Command/ResourcesListCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
*
Expand All @@ -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 <fabien@symfony.com>
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
31 changes: 16 additions & 15 deletions Controller/ApiController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
*
Expand All @@ -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 <schmittjoh@gmail.com>
*
* @Route("/api")
*/
class ApiController
{
Expand All @@ -43,30 +45,25 @@ class ApiController
*/
private $updater;

/**
* ApiController constructor.
*
* @param ConfigFactory $configFactory
* @param Updater $updater
*/
public function __construct(ConfigFactory $configFactory, Updater $updater)
{
$this->configFactory = $configFactory;
$this->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)
{
Expand All @@ -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')
);

Expand Down
24 changes: 11 additions & 13 deletions Controller/TranslateController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
*
Expand Down Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -138,7 +136,7 @@ public function indexAction(Request $request)
$existingMessages[$id] = $message;
}

return array(
return [
'selectedConfig' => $config,
'configs' => $configs,
'selectedDomain' => $domain,
Expand All @@ -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,
);
];
}
}
4 changes: 3 additions & 1 deletion DependencyInjection/Compiler/IntegrationPass.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
*
Expand All @@ -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
{
Expand Down
Loading