1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NamespaceProtector\Command; |
4
|
|
|
|
5
|
|
|
use NamespaceProtector\Config\Config; |
6
|
|
|
use NamespaceProtector\Common\FileSystemPath; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use NamespaceProtector\NamespaceProtectorProcessorFactory; |
11
|
|
|
|
12
|
|
|
abstract class AbstractValidateNamespaceCommand extends Command |
13
|
|
|
{ |
14
|
|
|
public function __construct(string $name = null) |
15
|
|
|
{ |
16
|
|
|
parent::__construct($name); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function configure(): void |
20
|
|
|
{ |
21
|
|
|
parent::configure(); |
22
|
|
|
$this->setName('validate-namespace') |
23
|
|
|
->setDescription('Validate namespace') |
24
|
|
|
->setHelp('Validate if some namespace access to one private namespace'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
28
|
|
|
{ |
29
|
|
|
$output->writeln("Boot validate analysis...."); |
30
|
|
|
$config = Config::loadFromFile(new FileSystemPath(\getcwd().'/namespace-protector-config.json')); |
31
|
|
|
$factory = new NamespaceProtectorProcessorFactory(); |
32
|
|
|
$namespaceProtectorProcessor = $factory->create($config); |
33
|
|
|
|
34
|
|
|
$namespaceProtectorProcessor->load(); |
35
|
|
|
|
36
|
|
|
$output->writeln($config->print()); |
37
|
|
|
|
38
|
|
|
$output->writeln("Load data...."); |
39
|
|
|
$output->writeln('Loaded ' . $namespaceProtectorProcessor->getFilesLoaded() . ' files to validate'); |
40
|
|
|
$output->writeln('Loaded ' . $namespaceProtectorProcessor->totalSymbolsLoaded() . ' built in symbols'); |
41
|
|
|
|
42
|
|
|
$output->writeln('Start analysis...'); |
43
|
|
|
$namespaceProtectorProcessor->process(); |
44
|
|
|
|
45
|
|
|
$output->writeln('<fg=red>Total errors: ' . $namespaceProtectorProcessor->getCountErrors().'</>'); |
46
|
|
|
|
47
|
|
|
if ($namespaceProtectorProcessor->getCountErrors()>0) { |
48
|
|
|
return self::FAILURE; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return self::SUCCESS; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|