1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NicolasBeauvais\Transcribe\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Support\Arr; |
7
|
|
|
use NicolasBeauvais\Transcribe\Manager; |
8
|
|
|
|
9
|
|
|
class UnusedCommand extends Command |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The name and signature of the console command. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $signature = 'langman:unused'; |
17
|
|
|
/** |
18
|
|
|
* The description of the console command. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $description = 'Look for translations in views and update missing key in language files.'; |
23
|
|
|
/** |
24
|
|
|
* The Languages manager instance. |
25
|
|
|
* |
26
|
|
|
* @var \Themsaid\LangMan\Manager |
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
private $manager; |
29
|
|
|
/** |
30
|
|
|
* Command constructor. |
31
|
|
|
* |
32
|
|
|
* @param \Themsaid\LangMan\Manager $manager |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function __construct(Manager $manager) |
36
|
|
|
{ |
37
|
|
|
parent::__construct(); |
38
|
|
|
$this->manager = $manager; |
|
|
|
|
39
|
|
|
} |
40
|
|
|
/** |
41
|
|
|
* Execute the console command. |
42
|
|
|
* |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
|
|
public function handle() |
46
|
|
|
{ |
47
|
|
|
$translationFiles = $this->manager->files(); |
48
|
|
|
$this->reportUnused($translationFiles); |
49
|
|
|
$this->info('Done!'); |
50
|
|
|
} |
51
|
|
|
/** |
52
|
|
|
* Report unused keys in translation files |
53
|
|
|
* |
54
|
|
|
* @param $translationFiles |
55
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
private function reportUnused($translationFiles) |
59
|
|
|
{ |
60
|
|
|
$this->info('Finding unused keys...'); |
61
|
|
|
// An array of all translation keys as found in project files. |
62
|
|
|
$allKeysInFiles = $this->manager->collectFromFiles(); |
63
|
|
|
foreach ($translationFiles as $fileName => $languages) { |
64
|
|
|
foreach ($languages as $languageKey => $path) { |
65
|
|
|
$fileContent = $this->manager->getFileContent($path); |
66
|
|
|
if (isset($allKeysInFiles[$fileName])) { |
67
|
|
|
$missingKeys = array_diff(array_keys(array_dot($fileContent)), $allKeysInFiles[$fileName]); |
68
|
|
|
foreach ($missingKeys as $i => $missingKey) { |
69
|
|
|
$this->output->writeln("\"<fg=red>{$languageKey}.{$fileName}.{$missingKey}</>\" never used."); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths