1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHP Translation package. |
5
|
|
|
* |
6
|
|
|
* (c) PHP Translation team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Translation\Bundle\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Command\Command; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
20
|
|
|
use Translation\Bundle\Catalogue\CatalogueCounter; |
21
|
|
|
use Translation\Bundle\Catalogue\CatalogueFetcher; |
22
|
|
|
use Translation\Bundle\Service\ConfigurationManager; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Tobias Nyholm <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class StatusCommand extends Command |
28
|
|
|
{ |
29
|
|
|
use BundleTrait; |
30
|
|
|
|
31
|
|
|
protected static $defaultName = 'translation:status'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var CatalogueCounter |
35
|
|
|
*/ |
36
|
|
|
private $catalogueCounter; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var ConfigurationManager |
40
|
|
|
*/ |
41
|
|
|
private $configurationManager; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var CatalogueFetcher |
45
|
|
|
*/ |
46
|
|
|
private $catalogueFetcher; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param CatalogueCounter $catalogueCounter |
50
|
|
|
* @param ConfigurationManager $configurationManager |
51
|
|
|
* @param CatalogueFetcher $catalogueFetcher |
52
|
|
|
*/ |
53
|
1 |
|
public function __construct( |
54
|
|
|
CatalogueCounter $catalogueCounter, |
55
|
|
|
ConfigurationManager $configurationManager, |
56
|
|
|
CatalogueFetcher $catalogueFetcher |
57
|
|
|
) { |
58
|
1 |
|
$this->catalogueCounter = $catalogueCounter; |
59
|
1 |
|
$this->configurationManager = $configurationManager; |
60
|
1 |
|
$this->catalogueFetcher = $catalogueFetcher; |
61
|
|
|
|
62
|
1 |
|
parent::__construct(); |
63
|
1 |
|
} |
64
|
|
|
|
65
|
1 |
View Code Duplication |
protected function configure() |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$this |
68
|
1 |
|
->setName(self::$defaultName) |
69
|
1 |
|
->setDescription('Show status about your translations.') |
70
|
1 |
|
->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') |
71
|
1 |
|
->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false) |
72
|
1 |
|
->addOption('json', null, InputOption::VALUE_NONE, 'If we should output in Json format') |
73
|
1 |
|
->addOption('bundle', 'b', InputOption::VALUE_REQUIRED, 'The translations for bundle you want to check.') |
74
|
|
|
; |
75
|
1 |
|
} |
76
|
|
|
|
77
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
78
|
|
|
{ |
79
|
1 |
|
$config = $this->configurationManager->getConfiguration($input->getArgument('configuration')); |
80
|
1 |
|
$this->configureBundleDirs($input, $config); |
|
|
|
|
81
|
|
|
|
82
|
1 |
|
$locales = []; |
83
|
1 |
|
if ($inputLocale = $input->getArgument('locale')) { |
84
|
1 |
|
$locales = [$inputLocale]; |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
$catalogues = $this->catalogueFetcher->getCatalogues($config, $locales); |
|
|
|
|
88
|
|
|
|
89
|
1 |
|
$stats = []; |
90
|
1 |
|
foreach ($catalogues as $catalogue) { |
91
|
1 |
|
$stats[$catalogue->getLocale()] = $this->catalogueCounter->getCatalogueStatistics($catalogue); |
92
|
|
|
} |
93
|
|
|
|
94
|
1 |
|
if ($input->getOption('json')) { |
95
|
1 |
|
$output->writeln(json_encode($stats)); |
96
|
|
|
|
97
|
1 |
|
return; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$io = new SymfonyStyle($input, $output); |
101
|
|
|
foreach ($stats as $locale => $stat) { |
102
|
|
|
$rows = []; |
103
|
|
|
foreach ($stat as $domain => $data) { |
104
|
|
|
$rows[] = [$domain, $data['defined'], $data['new'], $data['obsolete']]; |
105
|
|
|
} |
106
|
|
|
$io->title('Locale: '.$locale); |
107
|
|
|
$io->table(['Domain', 'Defined', 'New', 'Obsolete'], $rows); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.