|
@@ -21,79 +21,74 @@ use PhpCsFixer\Console\Application;
|
|
*
|
|
*
|
|
* @internal
|
|
* @internal
|
|
*/
|
|
*/
|
|
-final class ToolInfo
|
|
|
|
|
|
+final class ToolInfo implements ToolInfoInterface
|
|
{
|
|
{
|
|
const COMPOSER_PACKAGE_NAME = 'friendsofphp/php-cs-fixer';
|
|
const COMPOSER_PACKAGE_NAME = 'friendsofphp/php-cs-fixer';
|
|
|
|
|
|
const COMPOSER_LEGACY_PACKAGE_NAME = 'fabpot/php-cs-fixer';
|
|
const COMPOSER_LEGACY_PACKAGE_NAME = 'fabpot/php-cs-fixer';
|
|
|
|
|
|
- public static function getComposerInstallationDetails()
|
|
|
|
- {
|
|
|
|
- static $result;
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @var null|array
|
|
|
|
+ */
|
|
|
|
+ private $composerInstallationDetails;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @var null|bool
|
|
|
|
+ */
|
|
|
|
+ private $isInstalledByComposer;
|
|
|
|
|
|
- if (!self::isInstalledByComposer()) {
|
|
|
|
|
|
+ public function getComposerInstallationDetails()
|
|
|
|
+ {
|
|
|
|
+ if (!$this->isInstalledByComposer()) {
|
|
throw new \LogicException('Cannot get composer version for tool not installed by composer.');
|
|
throw new \LogicException('Cannot get composer version for tool not installed by composer.');
|
|
}
|
|
}
|
|
|
|
|
|
- if (null === $result) {
|
|
|
|
- $composerInstalled = json_decode(file_get_contents(self::getComposerInstalledFile()), true);
|
|
|
|
|
|
+ if (null === $this->composerInstallationDetails) {
|
|
|
|
+ $composerInstalled = json_decode(file_get_contents($this->getComposerInstalledFile()), true);
|
|
|
|
|
|
foreach ($composerInstalled as $package) {
|
|
foreach ($composerInstalled as $package) {
|
|
if (in_array($package['name'], [self::COMPOSER_PACKAGE_NAME, self::COMPOSER_LEGACY_PACKAGE_NAME], true)) {
|
|
if (in_array($package['name'], [self::COMPOSER_PACKAGE_NAME, self::COMPOSER_LEGACY_PACKAGE_NAME], true)) {
|
|
- $result = $package;
|
|
|
|
|
|
+ $this->composerInstallationDetails = $package;
|
|
|
|
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return $result;
|
|
|
|
|
|
+ return $this->composerInstallationDetails;
|
|
}
|
|
}
|
|
|
|
|
|
- public static function getComposerVersion()
|
|
|
|
|
|
+ public function getComposerVersion()
|
|
{
|
|
{
|
|
- static $result;
|
|
|
|
-
|
|
|
|
- if (null === $result) {
|
|
|
|
- $package = self::getComposerInstallationDetails();
|
|
|
|
- $result = $package['version'].'#'.$package['dist']['reference'];
|
|
|
|
- }
|
|
|
|
|
|
+ $package = $this->getComposerInstallationDetails();
|
|
|
|
|
|
- return $result;
|
|
|
|
|
|
+ return $package['version'].'#'.$package['dist']['reference'];
|
|
}
|
|
}
|
|
|
|
|
|
- public static function getVersion()
|
|
|
|
|
|
+ public function getVersion()
|
|
{
|
|
{
|
|
- if (self::isInstalledByComposer()) {
|
|
|
|
- return Application::VERSION.':'.self::getComposerVersion();
|
|
|
|
|
|
+ if ($this->isInstalledByComposer()) {
|
|
|
|
+ return Application::VERSION.':'.$this->getComposerVersion();
|
|
}
|
|
}
|
|
|
|
|
|
return Application::VERSION;
|
|
return Application::VERSION;
|
|
}
|
|
}
|
|
|
|
|
|
- public static function isInstalledAsPhar()
|
|
|
|
|
|
+ public function isInstalledAsPhar()
|
|
{
|
|
{
|
|
- static $result;
|
|
|
|
-
|
|
|
|
- if (null === $result) {
|
|
|
|
- $result = 'phar://' === substr(__DIR__, 0, 7);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return $result;
|
|
|
|
|
|
+ return 'phar://' === substr(__DIR__, 0, 7);
|
|
}
|
|
}
|
|
|
|
|
|
- public static function isInstalledByComposer()
|
|
|
|
|
|
+ public function isInstalledByComposer()
|
|
{
|
|
{
|
|
- static $result;
|
|
|
|
-
|
|
|
|
- if (null === $result) {
|
|
|
|
- $result = !self::isInstalledAsPhar() && file_exists(self::getComposerInstalledFile());
|
|
|
|
|
|
+ if (null === $this->isInstalledByComposer) {
|
|
|
|
+ $this->isInstalledByComposer = !$this->isInstalledAsPhar() && file_exists($this->getComposerInstalledFile());
|
|
}
|
|
}
|
|
|
|
|
|
- return $result;
|
|
|
|
|
|
+ return $this->isInstalledByComposer;
|
|
}
|
|
}
|
|
|
|
|
|
- private static function getComposerInstalledFile()
|
|
|
|
|
|
+ private function getComposerInstalledFile()
|
|
{
|
|
{
|
|
return __DIR__.'/../../../composer/installed.json';
|
|
return __DIR__.'/../../../composer/installed.json';
|
|
}
|
|
}
|