<commit_before>import ILogger from "./logger/ILogger";
import NullLogger from "./logger/NullLogger";
import { WorkspaceFolder } from "vscode-languageserver";

/**
 * PHP mess detector command builder
 *
 * Builder for the php mess detector command
 *
 * @module vscode-phpmd/service
 * @author <NAME> (<EMAIL>)
 */
class PhpmdCommandBuilder {
    /**
     * Logger
     *
     * @property {ILogger}
     */
    private logger: ILogger;

    /**
     * Service constructor
     *
     * Takes the command string and variable for substitution 
     *
     * @param {string} command
     * @param {WorkspaceFolder[]} workspaceFolders
     * @param {string} homeDir
     */
    constructor(private readonly command: string, private workspaceFolders: WorkspaceFolder[], private homeDir: string) { }

    public usingGlobalPhp(): boolean {
        return this.command.toLowerCase().substr(0, 4) === "php ";
    }

    /**
     * Build the PHP mess detector version command.
     *
     * @returns {string}
     */
    public buildPhpmdVersionCommand(): string {
        const command = `${this.command} --version`;
        this.getLogger().info(`Building phpmd version command: ${command}`, true);

        return command;
    }

    /**
     * Build the PHP mess detector command.
     *
     * @param  {string} options A string with PHP mess detector command line options
     * @returns {string}
     */
    public buildPhpmdCommand(options: string): string {
        const command = `${this.command} ${options}`;
        this.getLogger().info(`Building phpmd command: ${command}`, true);

        return command;
    }

    /**
     * Logger setter
     *
     * @param {ILogger} logger
     * @returns {void}
     */
    public setLogger(logger: ILogger): void {
        this.logger = logger;
    }

    /**
     * Logger getter
     *
     * Returns null object logger if the setter was not called before
     *
     * @returns {ILogger}
     */
    protected getLogger(): ILogger {
        if (!this.logger) {
            this.logger = new NullLogger();
        }

        return this.logger;
    }
}

export default PhpmdCommandBuilder;<commit_msg>Add home dir replacement<commit_after>import ILogger from "./logger/ILogger";
import NullLogger from "./logger/NullLogger";
import { WorkspaceFolder } from "vscode-languageserver";

/**
 * PHP mess detector command builder
 *
 * Builder for the php mess detector command
 *
 * @module vscode-phpmd/service
 * @author <NAME> (<EMAIL>)
 */
class PhpmdCommandBuilder {
    /**
     * Logger
     *
     * @property {ILogger}
     */
    private logger: ILogger;

    /**
     * Service constructor
     *
     * Takes the command string and variable for substitution 
     *
     * @param {string} command
     * @param {WorkspaceFolder[]} workspaceFolders
     * @param {string} homeDir
     */
    constructor(private readonly command: string, private workspaceFolders: WorkspaceFolder[], private homeDir: string) { }

    public usingGlobalPhp(): boolean {
        return this.command.toLowerCase().substr(0, 4) === "php ";
    }

    /**
     * Build the PHP mess detector version command.
     *
     * @returns {string}
     */
    public buildPhpmdVersionCommand(): string {
        const command = `${this.command} --version`;
        this.getLogger().info(`Building phpmd version command: ${command}`, true);

        return command;
    }

    /**
     * Build the PHP mess detector command.
     *
     * @param  {string} options A string with PHP mess detector command line options
     * @returns {string}
     */
    public buildPhpmdCommand(options: string): string {
        // Replace homedir in options
        if (options.indexOf("\"~/") > -1)
            options = options.replace(`"~/`, `"${this.homeDir}/`);

        if (options.indexOf("\"~\\") > -1)
            options = options.replace(`"~\\`, `"${this.homeDir}\\`);

        const command = `${this.command} ${options}`;
        this.getLogger().info(`Building phpmd command: ${command}`, true);

        return command;
    }

    /**
     * Logger setter
     *
     * @param {ILogger} logger
     * @returns {void}
     */
    public setLogger(logger: ILogger): void {
        this.logger = logger;
    }

    /**
     * Logger getter
     *
     * Returns null object logger if the setter was not called before
     *
     * @returns {ILogger}
     */
    protected getLogger(): ILogger {
        if (!this.logger) {
            this.logger = new NullLogger();
        }

        return this.logger;
    }
}

export default PhpmdCommandBuilder;
{'fraction_non_alphanumeric': 0.12707786526684164, 'fraction_numerical': 0.0013123359580052493, 'mean_word_length': 2.352639296187683, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7042962', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1305, 'n_words': 364}