-
-
Notifications
You must be signed in to change notification settings - Fork 166
/
Application.php
94 lines (73 loc) · 2.11 KB
/
Application.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php declare(strict_types=1);
/*
* This file is part of PHPLOC.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\PHPLOC;
use const PHP_EOL;
use function dirname;
use function printf;
use SebastianBergmann\FileIterator\Facade;
use SebastianBergmann\Version;
final class Application
{
private const VERSION = '8.0';
/**
* @psalm-param list<non-empty-string> $argv
*/
public function run(array $argv): int
{
$this->printVersion();
try {
$arguments = (new ArgumentsBuilder)->build($argv);
} catch (Exception $e) {
print PHP_EOL . $e->getMessage() . PHP_EOL;
return 1;
}
if ($arguments->version()) {
return 0;
}
print PHP_EOL;
if ($arguments->help()) {
$this->help();
return 0;
}
$files = (new Facade)->getFilesAsArray(
$arguments->directories(),
$arguments->suffixes(),
'',
$arguments->exclude(),
);
if (empty($files)) {
print 'No files found to scan' . PHP_EOL;
return 1;
}
$result = (new Analyser)->analyse($files, $arguments->debug());
print (new TextResultFormatter)->format($result);
return 0;
}
private function printVersion(): void
{
printf(
'phploc %s by Sebastian Bergmann.' . PHP_EOL,
(new Version(self::VERSION, dirname(__DIR__)))->asString(),
);
}
private function help(): void
{
print <<<'EOT'
Usage:
phploc [options] <directory>
Options for selecting files:
--suffix <suffix> Include files with names ending in <suffix> in the analysis
(default: .php; can be given multiple times)
--exclude <path> Exclude files with <path> in their path from the analysis
(can be given multiple times)
--debug Print debugging information
EOT;
}
}