-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorConfigCommand.php
More file actions
59 lines (45 loc) · 1.55 KB
/
Copy pathEditorConfigCommand.php
File metadata and controls
59 lines (45 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace DragonCode\Codestyler\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function file_exists;
use function is_dir;
use function realpath;
class EditorConfigCommand extends Command
{
protected function configure(): void
{
$this
->setName('editorconfig')
->setDescription('Publishes the .editorconfig file')
->addOption('path', 'p', InputOption::VALUE_OPTIONAL, 'Path to publish files', realpath('.'));
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$path = $input->getOption('path');
$source = $this->sourcePath();
$target = $this->targetPath($path);
if (! $this->validateDirectory($path)) {
$output->writeln("<error>Directory \"$path\" not found.</error>");
return static::FAILURE;
}
copy($source, $target);
$output->writeln("<info>The .editorconfig file published successfully to \"$target\".</info>");
return static::SUCCESS;
}
protected function validateDirectory(string $path): bool
{
return file_exists($path) && is_dir($path);
}
protected function sourcePath(): string
{
return __DIR__ . '/../../.editorconfig';
}
protected function targetPath(string $path): string
{
return $path . '/.editorconfig';
}
}