<commit_before><?php
namespace App\SystemInfo;

/**
 * Composer class
 *
 * This is a helper class that assists with
 * fetching a variety of composer information
 * from the system.
 */
class Composer
{
    /**
     * Get a list of installed composer packages
     *
     * @return array
     */
    public static function getInstalledPackages()
    {
        //
        // Installed composer libraries (from composer.lock file)
        //
        $composerLock = ROOT . DS . 'composer.lock';
        $composer = null;
        if (is_readable($composerLock)) {
            $composer = json_decode(file_get_contents($composerLock), true);
        }
        $result = !empty($composer['packages']) ? $composer['packages'] : [];

        return $result;
    }

    /**
     * Get a list of match counts
     *
     * This method looks in the list of provided composer
     * packages for the list of provided match words, and
     * returns the list of counts for each match word.
     *
     * @param array $packages Installed composer packages
     * @param array $matchWords List of words to match
     * @return array
     */
    public static function getMatchCounts(array $packages, array $matchWords)
    {
        $result = [];
        foreach ($packages as $package) {
            // Concatenate all fields that we'll be matching against
            $matchString = $package['name'];
            if (!empty($package['description'])) {
                $matchString .= $package['description'];
            }
            foreach ($matchWords as $word) {
                if (empty($result[$word])) {
                    $result[$word] = 0;
                }
                if (preg_match('/' . $word . '/', $matchString)) {
                    $result[$word]++;
                }
            }
        }

        return $result;
    }
}
<commit_msg>Minor refactoring (task #5473)<commit_after><?php
namespace App\SystemInfo;

/**
 * Composer class
 *
 * This is a helper class that assists with
 * fetching a variety of composer information
 * from the system.
 */
class Composer
{
    /**
     * Get a list of installed composer packages
     *
     * @return array
     */
    public static function getInstalledPackages()
    {
        //
        // Installed composer libraries (from composer.lock file)
        //
        $composerLock = ROOT . DS . 'composer.lock';
        $composer = null;
        if (is_readable($composerLock)) {
            $composer = json_decode(file_get_contents($composerLock), true);
        }
        $result = !empty($composer['packages']) ? $composer['packages'] : [];

        return $result;
    }

    /**
     * Get a list of match counts
     *
     * This method looks in the list of provided composer
     * packages for the list of provided match words, and
     * returns the list of counts for each match word.
     *
     * @param array $packages Installed composer packages
     * @param array $matchWords List of words to match
     * @return array
     */
    public static function getMatchCounts(array $packages, array $matchWords)
    {
        $result = [];
        foreach ($packages as $package) {
            // Concatenate all fields that we'll be matching against
            $matchString = self::getMatchString($package);
            foreach ($matchWords as $word) {
                if (empty($result[$word])) {
                    $result[$word] = 0;
                }
                if (preg_match('/' . $word . '/', $matchString)) {
                    $result[$word]++;
                }
            }
        }

        return $result;
    }

    /**
     * Concatenate matching package fields into a single string
     *
     * @param array $package Package data
     * @return string
     */
    protected static function getMatchString(array $package)
    {
        $result = '';

        $keys = ['name', 'description'];
        foreach ($keys as $key) {
            if (!empty($package[$key])) {
                $result .= ' ' . $package[$key];
            }
        }

        return $result;
    }
}

{'fraction_non_alphanumeric': 0.11383709519136408, 'fraction_numerical': 0.0014720314033366045, 'mean_word_length': 1.8097863542384562, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1047847', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1066, 'n_words': 331}