Skip to content

Commit 945d556

Browse files
authored
Merge pull request #31 from wundii/dev
version output via the composer install json
2 parents 3e27930 + 1005c8e commit 945d556

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/Console/Commands/LintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5858
$startExecuteTime = microtime(true);
5959

6060
$output = new LintSymfonyStyle($lintConfig, $input, $output);
61-
$output->startApplication(LintApplication::VERSION);
61+
$output->startApplication(LintApplication::vendorVersion());
6262

6363
$lintFinder = $this->lintFinder->getFilesFromLintConfig($lintConfig);
6464

src/Console/LintApplication.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ final class LintApplication extends BaseApplication
2727
/**
2828
* @var string
2929
*/
30-
public const VERSION = '0.3.1';
30+
public const VERSION = '0.3';
3131

3232
public function __construct(
3333
LintCommand $lintCommand,
3434
LintInitCommand $lintInitCommand,
3535
) {
36-
parent::__construct(self::NAME, self::VERSION);
36+
parent::__construct(self::NAME, self::vendorVersion());
3737

3838
$this->add($lintCommand);
3939
$this->add($lintInitCommand);
@@ -53,7 +53,7 @@ public static function runExceptionally(Throwable $throwable, ?OutputInterface $
5353
$symfonyStyle = new SymfonyStyle($argvInput, $output);
5454

5555
$symfonyStyle->writeln('> ' . implode(' ', $argv));
56-
$symfonyStyle->writeln('<fg=blue;options=bold>PHP</><fg=yellow;options=bold>Lint</> ' . self::VERSION);
56+
$symfonyStyle->writeln('<fg=blue;options=bold>PHP</><fg=yellow;options=bold>Lint</> ' . self::vendorVersion());
5757
$symfonyStyle->newLine();
5858

5959
$symfonyStyle->error($throwable->getMessage());
@@ -62,6 +62,33 @@ public static function runExceptionally(Throwable $throwable, ?OutputInterface $
6262
return Command::FAILURE;
6363
}
6464

65+
public static function vendorVersion(): string
66+
{
67+
$version = self::VERSION;
68+
$vendorInstallJson = getcwd() . DIRECTORY_SEPARATOR . 'vendor/composer/installed.json';
69+
70+
$fileContent = file_get_contents($vendorInstallJson);
71+
if ($fileContent === false) {
72+
return $version;
73+
}
74+
75+
$composerJson = json_decode($fileContent, true);
76+
if (! is_array($composerJson)) {
77+
return $version;
78+
}
79+
80+
$packages = $composerJson['packages'] ?? [];
81+
82+
foreach ($packages as $package) {
83+
if ($package['name'] === 'wundii/phplint') {
84+
$version = $package['version'];
85+
break;
86+
}
87+
}
88+
89+
return $version;
90+
}
91+
6592
private function getInputDefinition(): InputDefinition
6693
{
6794
return new InputDefinition([

0 commit comments

Comments
 (0)