|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\UnusedRelationsRemover; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
|
|
10
|
|
|
class RemoveUnusedRelationsCommand extends AbstractCommand |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var UnusedRelationsRemover |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $remover; |
|
16
|
|
|
|
|
17
|
1 |
|
public function __construct(UnusedRelationsRemover $remover, ?string $name = null) |
|
18
|
|
|
{ |
|
19
|
1 |
|
parent::__construct($name); |
|
20
|
1 |
|
$this->remover = $remover; |
|
21
|
1 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @throws DoctrineStaticMetaException |
|
25
|
|
|
*/ |
|
26
|
1 |
|
public function configure(): void |
|
27
|
|
|
{ |
|
28
|
|
|
try { |
|
29
|
1 |
|
$this->setName(AbstractCommand::COMMAND_PREFIX . 'remove:unusedRelations') |
|
30
|
1 |
|
->setDefinition( |
|
31
|
|
|
[ |
|
32
|
1 |
|
$this->getProjectRootPathOption(), |
|
33
|
1 |
|
$this->getProjectRootNamespaceOption(), |
|
34
|
|
|
] |
|
35
|
1 |
|
)->setDescription( |
|
36
|
1 |
|
'Find and remove unused relations traits and interfaces' |
|
37
|
|
|
); |
|
38
|
|
|
} catch (\Exception $e) { |
|
39
|
|
|
throw new DoctrineStaticMetaException( |
|
40
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
|
41
|
|
|
$e->getCode(), |
|
42
|
|
|
$e |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param InputInterface $input |
|
49
|
|
|
* @param OutputInterface $output |
|
50
|
|
|
* |
|
51
|
|
|
* @return int|null|void |
|
52
|
|
|
* @throws DoctrineStaticMetaException |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function execute(InputInterface $input, OutputInterface $output) |
|
55
|
|
|
{ |
|
56
|
|
|
try { |
|
57
|
1 |
|
$output->writeln( |
|
58
|
1 |
|
'<comment>Finding and Removing Unused Generated Code</comment>' |
|
59
|
|
|
); |
|
60
|
1 |
|
$this->checkOptions($input); |
|
61
|
1 |
|
$removedFiles = $this->remover->run( |
|
62
|
1 |
|
$input->getOption(self::OPT_PROJECT_ROOT_PATH), |
|
63
|
1 |
|
$input->getOption(self::OPT_PROJECT_ROOT_NAMESPACE) |
|
64
|
|
|
); |
|
65
|
1 |
|
$output->writeln('<comment>Removed ' . count($removedFiles) . ' Files:</comment>'); |
|
66
|
1 |
|
$output->writeln(print_r($removedFiles, true)); |
|
67
|
1 |
|
$output->writeln('<info>completed</info>'); |
|
68
|
|
|
} catch (\Exception $e) { |
|
69
|
|
|
throw new DoctrineStaticMetaException( |
|
70
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
|
71
|
|
|
$e->getCode(), |
|
72
|
|
|
$e |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
1 |
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|