These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Victoire\Bundle\I18nBundle\Command; |
||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
||
6 | use Symfony\Component\Console\Input\InputInterface; |
||
7 | use Symfony\Component\Console\Input\InputOption; |
||
8 | use Symfony\Component\Console\Output\OutputInterface; |
||
9 | use Victoire\Bundle\I18nBundle\Entity\ViewTranslationLegacy; |
||
10 | |||
11 | class LegacyViewTranslationMigrationCommand extends ContainerAwareCommand |
||
12 | { |
||
13 | /** |
||
14 | * {@inheritdoc} |
||
15 | */ |
||
16 | public function configure() |
||
17 | { |
||
18 | parent::configure(); |
||
19 | |||
20 | $this |
||
21 | ->setName('victoire:legacy:view_translation') |
||
22 | ->setDescription('migrate gedmo view translations into knp translations') |
||
23 | ->addOption('mode', null, InputOption::VALUE_OPTIONAL, 'could be "all" to migrate all, "views" to migrate only views or "articles" to migrate only articles', 'all'); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Transform Gedmo translations into Knp translations. |
||
28 | * |
||
29 | * @param InputInterface $input |
||
30 | * @param OutputInterface $output |
||
31 | * |
||
32 | * @return void |
||
33 | */ |
||
34 | protected function execute(InputInterface $input, OutputInterface $output) |
||
35 | { |
||
36 | $mode = $input->getOption('mode'); |
||
37 | $progress = $this->getHelperSet()->get('progress'); |
||
38 | $progress->setProgressCharacter('V'); |
||
39 | $progress->setEmptyBarCharacter('-'); |
||
40 | |||
41 | $entityManager = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
42 | |||
43 | $legacyTranslations = $legacyArticles = []; |
||
44 | if ('all' === $mode || 'views' === $mode) { |
||
45 | $repo = $entityManager->getRepository('Victoire\Bundle\I18nBundle\Entity\ViewTranslationLegacy'); |
||
46 | $legacyTranslations = $repo->findAll(); |
||
47 | } |
||
48 | if ('all' === $mode || 'articles' === $mode) { |
||
49 | $repoArticle = $entityManager->getRepository('Victoire\Bundle\BlogBundle\Entity\Article'); |
||
50 | $legacyArticles = $repoArticle->findAll(); |
||
51 | } |
||
52 | $total = count($legacyTranslations) + count($legacyArticles); |
||
53 | $progress->start($output, $total); |
||
54 | /** @var ViewTranslationLegacy $legacyTranslation */ |
||
55 | foreach ($legacyTranslations as $legacyTranslation) { |
||
56 | $view = $legacyTranslation->getObject(); |
||
57 | $trans = $view->translate($legacyTranslation->getLocale(), false)->{'set'.$legacyTranslation->getField()}($legacyTranslation->getContent()); |
||
0 ignored issues
–
show
|
|||
58 | $entityManager->persist($view); |
||
59 | $view->mergeNewTranslations(); |
||
60 | |||
61 | $progress->advance(); |
||
62 | } |
||
63 | |||
64 | foreach ($legacyArticles as $legacyArticle) { |
||
65 | $legacyArticleTranslation = $legacyArticle->translate('fr', false); |
||
66 | $legacyArticleTranslation->setName($legacyArticle->getName()); |
||
67 | $legacyArticleTranslation->setSlug($legacyArticle->getSlug()); |
||
68 | $legacyArticleTranslation->setDescription($legacyArticle->getDescription()); |
||
69 | $entityManager->persist($legacyArticleTranslation); |
||
70 | $legacyArticle->mergeNewTranslations(); |
||
71 | |||
72 | $progress->advance(); |
||
73 | } |
||
74 | |||
75 | $entityManager->flush(); |
||
76 | $progress->finish(); |
||
77 | |||
78 | $output->writeln(sprintf('<comment>Ok, %s translations migrated !</comment>', count($total))); |
||
79 | } |
||
80 | } |
||
81 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.