From f444d53c8b0a439e98ad397b9895c4584e713a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 29 Dec 2020 12:24:53 +0100 Subject: [PATCH] Fix: Show version of plugin instead of version of application --- CHANGELOG.md | 15 +++++++-- phar/composer-normalize.php | 3 +- src/Command/NormalizeCommand.php | 3 +- src/{Application.php => Version.php} | 31 +++++-------------- .../{ApplicationTest.php => VersionTest.php} | 12 +++---- 5 files changed, 30 insertions(+), 34 deletions(-) rename src/{Application.php => Version.php} (60%) rename test/Unit/{ApplicationTest.php => VersionTest.php} (60%) diff --git a/CHANGELOG.md b/CHANGELOG.md index de4cd41e..bffd8f1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased -For a full diff see [`2.12.0...main`][2.12.0...main]. +For a full diff see [`2.12.1...main`][2.12.1...main]. + +## [`2.12.1`][2.12.1] + +For a full diff see [`2.12.0...2.12.1`][2.12.0...2.12.1]. + +### Fixed + +* Show version of plugin instead of version of `Composer\Console\Application` when running as development dependency ([#643]), by [@localheinz] ## [`2.12.0`][2.12.0] @@ -510,6 +518,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0]. [2.10.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.10.0 [2.11.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.11.0 [2.12.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.12.0 +[2.12.1]: https://github.com/ergebnis/composer-normalize/releases/tag/2.12.1 [81bc3a8...0.1.0]: https://github.com/ergebnis/composer-normalize/compare/81bc3a8...0.1.0 [0.1.0...0.2.0]: https://github.com/ergebnis/composer-normalize/compare/0.1.0...0.2.0 @@ -558,7 +567,8 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0]. [2.9.1...2.10.0]: https://github.com/ergebnis/composer-normalize/compare/2.9.1...2.10.0 [2.10.0...2.11.0]: https://github.com/ergebnis/composer-normalize/compare/2.10.0...2.11.0 [2.11.0...2.12.0]: https://github.com/ergebnis/composer-normalize/compare/2.11.0...2.12.0 -[2.12.0...main]: https://github.com/ergebnis/composer-normalize/compare/2.12.0...main +[2.12.0...2.12.1]: https://github.com/ergebnis/composer-normalize/compare/2.12.0...2.12.1 +[2.12.1...main]: https://github.com/ergebnis/composer-normalize/compare/2.12.1...main [#1]: https://github.com/ergebnis/composer-normalize/pull/1 [#2]: https://github.com/ergebnis/composer-normalize/pull/2 @@ -631,6 +641,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0]. [#634]: https://github.com/ergebnis/composer-normalize/pull/634 [#640]: https://github.com/ergebnis/composer-normalize/pull/640 [#641]: https://github.com/ergebnis/composer-normalize/pull/641 +[#643]: https://github.com/ergebnis/composer-normalize/pull/643 [@core23]: https://github.com/core23 [@dependabot]: https://github.com/dependabot diff --git a/phar/composer-normalize.php b/phar/composer-normalize.php index 78e4326f..9b33ef96 100644 --- a/phar/composer-normalize.php +++ b/phar/composer-normalize.php @@ -11,6 +11,7 @@ * @see https://github.com/ergebnis/composer-normalize */ +use Composer\Console\Application; use Composer\Factory; use Ergebnis\Composer\Normalize; use Ergebnis\Json\Normalizer; @@ -30,7 +31,7 @@ ])) ); -$application = new Normalize\Application(); +$application = new Application(); $application->add($command); diff --git a/src/Command/NormalizeCommand.php b/src/Command/NormalizeCommand.php index 3c08a606..037b7860 100644 --- a/src/Command/NormalizeCommand.php +++ b/src/Command/NormalizeCommand.php @@ -18,6 +18,7 @@ use Composer\Factory; use Composer\IO; use Ergebnis\Composer\Normalize\Exception; +use Ergebnis\Composer\Normalize\Version; use Ergebnis\Json\Normalizer; use Localheinz\Diff; use Symfony\Component\Console; @@ -107,7 +108,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $io->write([ \sprintf( 'Running %s.', - $this->getApplication()->getLongVersion() + Version::long() ), '', ]); diff --git a/src/Application.php b/src/Version.php similarity index 60% rename from src/Application.php rename to src/Version.php index 853a88cd..e54b811a 100644 --- a/src/Application.php +++ b/src/Version.php @@ -13,53 +13,38 @@ namespace Ergebnis\Composer\Normalize; -use Composer\Console; - /** * @internal */ -final class Application extends Console\Application +final class Version { /** * @see https://github.com/box-project/box/blob/master/doc/configuration.md#pretty-git-tag-placeholder-git * * @var string */ - private $version = '@git@'; + private static $version = '@git@'; - public function getLongVersion(): string + public static function long(): string { + $name = 'ergebnis/composer-normalize'; $attribution = 'by Andreas Möller and contributors'; - $version = $this->getVersion(); + $version = self::$version; - if ('' === $version) { + if ('@' . 'git@' === $version) { return \sprintf( '%s %s', - $this->getName(), + $name, $attribution ); } return \sprintf( '%s %s %s', - $this->getName(), + $name, $version, $attribution ); } - - public function getName(): string - { - return 'ergebnis/composer-normalize'; - } - - public function getVersion(): string - { - if ('@' . 'git@' === $this->version) { - return ''; - } - - return $this->version; - } } diff --git a/test/Unit/ApplicationTest.php b/test/Unit/VersionTest.php similarity index 60% rename from test/Unit/ApplicationTest.php rename to test/Unit/VersionTest.php index c3abcb35..724a542d 100644 --- a/test/Unit/ApplicationTest.php +++ b/test/Unit/VersionTest.php @@ -13,22 +13,20 @@ namespace Ergebnis\Composer\Normalize\Test\Unit; -use Ergebnis\Composer\Normalize\Application; +use Ergebnis\Composer\Normalize\Version; use PHPUnit\Framework; /** * @internal * - * @covers \Ergebnis\Composer\Normalize\Application + * @covers \Ergebnis\Composer\Normalize\Version */ -final class ApplicationTest extends Framework\TestCase +final class VersionTest extends Framework\TestCase { - public function testGetLongVersionReturnsVersion(): void + public function testLongReturnsVersion(): void { - $application = new Application(); - $expected = 'ergebnis/composer-normalize by Andreas Möller and contributors'; - self::assertSame($expected, $application->getLongVersion()); + self::assertSame($expected, Version::long()); } }