<commit_before><?php
/**
 * This file is part of the Jacobine package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Jacobine\Consumer\Analysis;

use Jacobine\Consumer\ConsumerAbstract;
use Jacobine\Component\Process\ProcessFactory;
use Jacobine\Component\Database\Database;
use Symfony\Component\Process\ProcessUtils;

/**
 * Class PHPLoc
 *
 * A consumer to execute PHPLOC (https://github.com/sebastianbergmann/phploc).
 * PHPLOC measured a PHP project very fast with some more general metrics like lines of code or num of classes.
 * This metrics will be saved in the database in the phploc table.
 *
 * Message format (json encoded):
 *  [
 *      directory: Absolute path to folder which will be analyzed. E.g. /var/www/my/sourcecode
 *      versionId: Version ID to get the regarding version record from version database table
 *      project: Project to be analyzed. Id of jacobine_project table
 *  ]
 *
 * Usage:
 *  php console jacobine:consumer Analysis\\PHPLoc
 *
 * @package Jacobine\Consumer\Analysis
 * @author <NAME> <<EMAIL>>
 */
class PHPLoc extends ConsumerAbstract
{

    /**
     * @var \Jacobine\Component\Process\ProcessFactory
     */
    protected $processFactory;

    /**
     * Constructor to set dependencies
     *
     * @param Database $database
     * @param ProcessFactory $processFactory
     */
    public function __construct(Database $database, ProcessFactory $processFactory)
    {
        $this->setDatabase($database);
        $this->processFactory = $processFactory;
    }

    /**
     * Gets a description of the consumer
     *
     * @return string
     */
    public function getDescription()
    {
        return 'Executes the PHPLoc analysis on a given folder and stores the results in phploc database table.';
    }

    /**
     * Initialize the consumer.
     * Sets the queue and routing key
     *
     * @return void
     */
    public function initialize()
    {
        parent::initialize();

        $this->setQueueOption('name', 'analysis.phploc');
        $this->enableDeadLettering();

        $this->setRouting('analysis.phploc');
    }

    /**
     * The logic of the consumer
     *
     * TODO: Add project into phploc table
     *
     * @param \stdClass $message
     * @throws \Exception
     * @return void
     */
    protected function process($message)
    {
        // If there is already a phploc record in database, exit here
        if ($this->getPhpLocDataFromDatabase($message->versionId) !== false) {
            $this->getLogger()->info('Record already analyzed with PHPLoc', ['versionId' => $message->versionId]);
            return;
        }
<commit_msg>[TASK] Remove TODO comment<commit_after><?php
/**
 * This file is part of the Jacobine package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Jacobine\Consumer\Analysis;

use Jacobine\Consumer\ConsumerAbstract;
use Jacobine\Component\Process\ProcessFactory;
use Jacobine\Component\Database\Database;
use Symfony\Component\Process\ProcessUtils;

/**
 * Class PHPLoc
 *
 * A consumer to execute PHPLOC (https://github.com/sebastianbergmann/phploc).
 * PHPLOC measured a PHP project very fast with some more general metrics like lines of code or num of classes.
 * This metrics will be saved in the database in the phploc table.
 *
 * Message format (json encoded):
 *  [
 *      directory: Absolute path to folder which will be analyzed. E.g. /var/www/my/sourcecode
 *      versionId: Version ID to get the regarding version record from version database table
 *      project: Project to be analyzed. Id of jacobine_project table
 *  ]
 *
 * Usage:
 *  php console jacobine:consumer Analysis\\PHPLoc
 *
 * @package Jacobine\Consumer\Analysis
 * @author <NAME> <<EMAIL>>
 */
class PHPLoc extends ConsumerAbstract
{

    /**
     * @var \Jacobine\Component\Process\ProcessFactory
     */
    protected $processFactory;

    /**
     * Constructor to set dependencies
     *
     * @param Database $database
     * @param ProcessFactory $processFactory
     */
    public function __construct(Database $database, ProcessFactory $processFactory)
    {
        $this->setDatabase($database);
        $this->processFactory = $processFactory;
    }

    /**
     * Gets a description of the consumer
     *
     * @return string
     */
    public function getDescription()
    {
        return 'Executes the PHPLoc analysis on a given folder and stores the results in phploc database table.';
    }

    /**
     * Initialize the consumer.
     * Sets the queue and routing key
     *
     * @return void
     */
    public function initialize()
    {
        parent::initialize();

        $this->setQueueOption('name', 'analysis.phploc');
        $this->enableDeadLettering();

        $this->setRouting('analysis.phploc');
    }

    /**
     * The logic of the consumer
     *
     * @param \stdClass $message
     * @throws \Exception
     * @return void
     */
    protected function process($message)
    {
        // If there is already a phploc record in database, exit here
        if ($this->getPhpLocDataFromDatabase($message->versionId) !== false) {
            $this->getLogger()->info('Record already analyzed with PHPLoc', ['versionId' => $message->versionId]);
            return;
        }

{'fraction_non_alphanumeric': 0.10325987980331451, 'fraction_numerical': 0.0, 'mean_word_length': 2.771978021978022, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 37, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '811818', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1488, 'n_words': 487}