<commit_before><?php

namespace Oro\Bundle\PlatformBundle\Composer;

use Composer\Package\PackageInterface;

use Oro\Bundle\PlatformBundle\OroPlatformBundle;

class VersionHelper
{
    const UNDEFINED_VERSION = 'N/A';

    /**
     * @var LocalRepositoryFactory
     */
    protected $factory;

    /**
     * @var array
     */
    protected $packages = [];

    /**
     * @param LocalRepositoryFactory $factory
     */
    public function __construct(LocalRepositoryFactory $factory)
    {
        $this->factory = $factory;
    }

    /**
     * @param string $packageName
     * @return string
     */
    public function getVersion($packageName = OroPlatformBundle::PACKAGE_NAME)
    {
        if (isset($this->packages[$packageName])) {
            return $this->packages[$packageName];
        }

        $packages = $this->factory->getLocalRepository()->findPackages($packageName);

        if ($package = current($packages)) {
            /** @var PackageInterface $package */
            $version = $package->getPrettyVersion();

            $this->packages[$packageName] = $version;

            return $version;
        }

        return self::UNDEFINED_VERSION;
    }
}<commit_msg>OEE-24: Application version for Enterprise - add cache<commit_after><?php

namespace Oro\Bundle\PlatformBundle\Composer;

use Composer\Package\PackageInterface;

use Oro\Bundle\PlatformBundle\OroPlatformBundle;

class VersionHelper
{
    const UNDEFINED_VERSION = 'N/A';

    /**
     * @var LocalRepositoryFactory
     */
    protected $factory;

    /**
     * @var array
     */
    protected $packageVersions = [];

    /**
     * @param LocalRepositoryFactory $factory
     */
    public function __construct(LocalRepositoryFactory $factory)
    {
        $this->factory = $factory;
    }

    /**
     * @param string $packageName
     * @return string
     */
    public function getVersion($packageName = OroPlatformBundle::PACKAGE_NAME)
    {
        if (isset($this->packageVersions[$packageName])) {
            return $this->packageVersions[$packageName];
        }

        $packages = $this->factory->getLocalRepository()->findPackages($packageName);

        if ($package = current($packages)) {
            /** @var PackageInterface $package */
            $version = $package->getPrettyVersion();

            $this->packageVersions[$packageName] = $version;

            return $version;
        }

        $this->packageVersions[$packageName] = self::UNDEFINED_VERSION;

        return self::UNDEFINED_VERSION;
    }
}
{'fraction_non_alphanumeric': 0.1259873617693523, 'fraction_numerical': 0.0007898894154818325, 'mean_word_length': 2.5625879043600563, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7555260', 'n_tokens_mistral': 708, 'n_tokens_neox': 681, 'n_words': 124}