Skip to content

Commit

Permalink
Fix detected issues
Browse files Browse the repository at this point in the history
  • Loading branch information
discordier committed Mar 14, 2022
1 parent ba0068b commit 904be22
Show file tree
Hide file tree
Showing 19 changed files with 246 additions and 579 deletions.
15 changes: 15 additions & 0 deletions .composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
{
"symbol-whitelist" : [
"null", "true", "false",
"self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"Contao\\ManagerPlugin\\Bundle\\BundlePluginInterface",
"Contao\\ManagerPlugin\\Bundle\\Config\\BundleConfig",
"Contao\\ManagerPlugin\\Bundle\\Parser\\ParserInterface",
"Contao\\ManagerPlugin\\Config\\ConfigPluginInterface",
"Contao\\ManagerPlugin\\Routing\\RoutingPluginInterface",
"CyberSpectrum\\I18N\\MetaModels\\MetaModelDictionaryDefinitionBuilder",
"CyberSpectrum\\I18N\\MetaModels\\MetaModelDictionaryProvider",
"MadeYourDay\\RockSolidCustomElements\\RockSolidCustomElementsBundle",
"MetaModels\\CoreBundle\\MetaModelsCoreBundle",
"Terminal42\\ChangeLanguage\\Terminal42ChangeLanguageBundle"
]
}
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
},
"require": {
"php": "^7.1.3",
"ext-json": "*",
"contao/core-bundle": "^4.4.0",
"cyberspectrum/i18n": "dev-fix/phpcq-2 as 1.0.0@dev",
"cyberspectrum/i18n-bundle": "dev-fix/phpcq-2 as 1.0.0@dev",
"cyberspectrum/i18n-contao": "dev-fix/phpcq-2 as 1.0.0@dev",
"cyberspectrum/i18n-xliff": "dev-fix/phpcq-2 as 1.0.0@dev",
"psr/log": "^1.1.4 || ^2.0 || ^3.0",
"symfony/config": "^3.4 || ^4.1 || ^5.0",
"symfony/console": "^3.4 || ^4.1 || ^5.0",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0",
"symfony/error-handler": "^4.4 || ^5.4 || ^6.0",
"symfony/form": "^4.4 || ^5.4 || ^6.0",
"symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0",
"symfony/http-foundation": "^4.4 || ^5.4 || ^6.0",
Expand All @@ -42,7 +46,6 @@
"contao-community-alliance/dc-general": "^2.1",
"contao/manager-plugin": "^2.6.0",
"cyberspectrum/i18n-metamodels": "dev-fix/phpcq-2 as 1.0.0@dev",
"metamodels/core": "^2.1",
"phpcq/runner-bootstrap": "^1.0@dev"
},
"suggest": {
Expand Down
48 changes: 13 additions & 35 deletions src/Command/DebugMapCommand.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
<?php

/**
* This file is part of cyberspectrum/i18n-contao-bundle.
*
* (c) 2019 CyberSpectrum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package cyberspectrum/i18n-contao-bundle
* @author Christian Schiffler <[email protected]>
* @copyright 2019 CyberSpectrum.
* @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT
* @filesource
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace CyberSpectrum\I18N\ContaoBundle\Command;

Expand All @@ -33,12 +16,8 @@
*/
class DebugMapCommand extends Command
{
/**
* The map builder.
*
* @var MapBuilderInterface
*/
private $mapBuilder;
/** The map builder. */
private MapBuilderInterface $mapBuilder;

/**
* Create a new instance.
Expand All @@ -51,28 +30,25 @@ public function __construct(MapBuilderInterface $mapBuilder)
$this->mapBuilder = $mapBuilder;
}

/**
* {@inheritDoc}
*/
protected function configure(): void
{
parent::configure();

$this->setName('debug:i18n-map');
$this->setDescription('Dump the mapping');
$this->addArgument('table', InputArgument::OPTIONAL, 'The table name');
$this->addArgument('source-language', InputArgument::OPTIONAL, 'The source language');
$this->addArgument('target-language', InputArgument::OPTIONAL, 'The target language');
$this->addArgument('table', InputArgument::REQUIRED, 'The table name');
$this->addArgument('source-language', InputArgument::REQUIRED, 'The source language');
$this->addArgument('target-language', InputArgument::REQUIRED, 'The target language');
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$tableName = $input->getArgument('table');
$tableName = $input->getArgument('table');
assert(is_string($tableName));
$sourceLanguage = $input->getArgument('source-language');
assert(is_string($sourceLanguage));
$targetLanguage = $input->getArgument('target-language');
assert(is_string($targetLanguage));

$tableMap = $this->mapBuilder->getMappingFor($tableName, $sourceLanguage, $targetLanguage);
$keys = $tableMap->sourceIds();
Expand All @@ -83,5 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$table->render();

return 0;
}
}
42 changes: 17 additions & 25 deletions src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
<?php

/**
* This file is part of cyberspectrum/i18n-contao-bundle.
*
* (c) 2018 CyberSpectrum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package cyberspectrum/i18n-contao-bundle
* @author Christian Schiffler <[email protected]>
* @copyright 2018 CyberSpectrum.
* @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT
* @filesource
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace CyberSpectrum\I18N\ContaoBundle\ContaoManager;

Expand All @@ -27,13 +10,14 @@
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Config\ConfigPluginInterface;
use Contao\ManagerPlugin\Routing\RoutingPluginInterface;
use CyberSpectrum\I18N\ContaoBundle\CyberSpectrumI18NContaoBundle;
use CyberSpectrum\I18NBundle\CyberSpectrumI18NBundle;
use CyberSpectrum\I18N\ContaoBundle\CyberSpectrumI18NContaoBundle;
use MetaModels\CoreBundle\MetaModelsCoreBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\RouteCollection;

/**
* Plugin for the Contao Manager.
Expand All @@ -43,7 +27,7 @@ class Plugin implements BundlePluginInterface, ConfigPluginInterface, RoutingPlu
/**
* {@inheritdoc}
*/
public function getBundles(ParserInterface $parser)
public function getBundles(ParserInterface $parser): array
{
return [
BundleConfig::create(CyberSpectrumI18NContaoBundle::class)
Expand All @@ -62,18 +46,26 @@ public function getBundles(ParserInterface $parser)
/**
* {@inheritDoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader, array $managerConfig)
public function registerContainerConfiguration(LoaderInterface $loader, array $managerConfig): void
{
$loader->load('@CyberSpectrumI18NContaoBundle/Resources/contao-manager/framework.yml');
}

/**
* {@inheritDoc}
*
* @psalm-suppress MixedInferredReturnType
* @psalm-suppress MixedReturnStatement
*/
public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel)
public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel): ?RouteCollection
{
return $resolver
->resolve(__DIR__.'/../Resources/config/contao/routing.yml')
->load(__DIR__.'/../Resources/config/contao/routing.yml');
$loader = $resolver->resolve(__DIR__ . '/../Resources/config/contao/routing.yml');

if (!$loader instanceof LoaderInterface) {
throw new \RuntimeException('Failed to load routes');
}

return $loader
->load(__DIR__ . '/../Resources/config/contao/routing.yml');
}
}
85 changes: 29 additions & 56 deletions src/Controller/ContaoInspectProblemsController.php
Original file line number Diff line number Diff line change
@@ -1,68 +1,39 @@
<?php

/**
* This file is part of cyberspectrum/i18n-contao-bundle.
*
* (c) 2018 CyberSpectrum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package cyberspectrum/i18n-contao-bundle
* @author Christian Schiffler <[email protected]>
* @copyright 2018 CyberSpectrum.
* @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT
* @filesource
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace CyberSpectrum\I18N\ContaoBundle\Controller;

use CyberSpectrum\I18N\Contao\Mapping\MapBuilderInterface;
use CyberSpectrum\I18N\Contao\Mapping\Terminal42ChangeLanguage\ArticleMap;
use CyberSpectrum\I18N\ContaoBundle\FormType\InspectMappingFormType;
use Psr\Log\LoggerAwareInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Debug\BufferingLogger;
use Symfony\Component\ErrorHandler\BufferingLogger;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Csrf\CsrfTokenManager;
use Symfony\Component\Templating\EngineInterface;

use function in_array;
use function strtr;

/**
* This allows to inspect dictionary problems in the Contao backend.
*/
class ContaoInspectProblemsController extends AbstractController
{
/**
* The twig engine.
*
* @var EngineInterface
*/
private $templating;
/** The twig engine. */
private EngineInterface $templating;

/**
* The Contao map builder.
*
* @var MapBuilderInterface
*/
private $mapBuilder;
/** The Contao map builder. */
private MapBuilderInterface $mapBuilder;

/**
* The CSRF token manager.
*
* @var CsrfTokenManager
*/
private $csrfTokenManager;
/** The CSRF token manager. */
private CsrfTokenManager $csrfTokenManager;

/**
* The CSRF token name.
*
* @var string
*/
private $csrfTokenName;
/** The CSRF token name. */
private string $csrfTokenName;

/**
* Create a new instance.
Expand Down Expand Up @@ -93,7 +64,7 @@ public function __construct(
*/
public function __invoke(Request $request): Response
{
switch ($request->get('act')) {
switch ($request->query->get('act')) {
case 'inspect-map':
return $this->inspectMap($request);
default:
Expand All @@ -106,25 +77,29 @@ public function __invoke(Request $request): Response
* Inspect Terminal42 mappings.
*
* @param Request $request The request.
*
* @return Response
*/
private function inspectMap(Request $request): Response
{
if (empty($map = $request->get('map'))) {
if (empty($map = $request->query->get('map'))) {
$map = 'tl_page';
}
assert(is_string($map));

$form = $this->createForm(InspectMappingFormType::class);
$form->handleRequest($request);

$logger = new BufferingLogger();
/** @var array{source: string, target: string} $data */
$data = $form->getData();
$logger = new BufferingLogger();
$errors = [];
if ($form->isSubmitted() && $form->isValid()) {
$this->mapBuilder->setLogger($logger);
if ($this->mapBuilder instanceof LoggerAwareInterface) {
$this->mapBuilder->setLogger($logger);
}
$this->mapBuilder->getMappingFor($map, $data['source'], $data['target']);
foreach ($logger->cleanLogs() as $message) {
/** @var list<array{0: string, 1: string, 2: array<string, string>}> $logs */
$logs = $logger->cleanLogs();
foreach ($logs as $message) {
if ([] !== ($converted = $this->convertMessage($message))) {
$errors[] = $converted;
}
Expand All @@ -143,7 +118,7 @@ private function inspectMap(Request $request): Response
/**
* Convert an error message to the correct error array.
*
* @param array $message The error message to convert.
* @param array{0: string, 1: string, 2: array<string, string>} $message The error message to convert.
*
* @return array
*
Expand All @@ -153,7 +128,7 @@ private function inspectMap(Request $request): Response
private function convertMessage(array $message): array
{
[$level, $text, $context] = $message;
if (!\in_array($level, ['warning', 'error'])) {
if (!in_array($level, ['warning', 'error'])) {
return [];
}

Expand Down Expand Up @@ -281,10 +256,8 @@ private function link(array $params): array
/**
* Transform the message by replacing the context parameters.
*
* @param string $message The message template.
* @param array $context The context parameters.
*
* @return string
* @param string $message The message template.
* @param array<string, string> $context The context parameters.
*/
private function transformMessage(string $message, array $context): string
{
Expand Down
Loading

0 comments on commit 904be22

Please sign in to comment.