Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom command line options for custom renderer #543

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dnolbon
Copy link

@dnolbon dnolbon commented Jan 11, 2018

adds the ability to transmit custom command line options for custom renderer

For example:
phpmd --custom-pretty-json 1 path-to-source JsonRenderer codesize,unusedcode,naming

Then in custom renderer we can get these options in costructor and then use them in renderReport function, for example:

class JsonRenderer extends AbstractRenderer
{
    /**
     * Custom command line options
     *
     * @var array
     */
    protected $options = [];

    public function __construct($options)
    {
        $this->options = $options;
    }

    /**
     * This method will be called when the engine has finished the source analysis
     * phase.
     *
     * @param \PHPMD\Report $report
     * @return void
     */
    public function renderReport(Report $report)
    {
        ...
        $options = 0;
        if (isset($this->options['pretty-json']) && (int)$this->options['pretty-json'] === 1) {
            $options = JSON_PRETTY_PRINT;
        }
        ...
    }
}

Full example can see here

@ravage84 ravage84 added this to the 2.7.0 milestone Jun 25, 2019
Copy link
Member

@ravage84 ravage84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnolbon looks good. Could you please add documentation? This way this new feature actually gets discovered by other's.

Plus, I'm not sure "custom" is a good choice. If these options are for renderers, why not use something like --render-XYZ?

@ravage84
Copy link
Member

ravage84 commented May 6, 2020

I still think since these optons are for renderers only, the CLI parameter should be named --render-options or something that line...

@dnolbon are you still interested in pursuing this?

@tvbeek tvbeek modified the milestones: 2.9.0, 2.10.0 Sep 2, 2020
@kylekatarnls kylekatarnls modified the milestones: 2.10.0, 2.11.0 Apr 11, 2021
@kylekatarnls kylekatarnls modified the milestones: 2.11.0, 2.12.0 Nov 27, 2021
@kylekatarnls kylekatarnls modified the milestones: 2.12.0, 2.13.0 Jun 19, 2022
@kylekatarnls kylekatarnls modified the milestones: 2.13.0, 2.14.0 Sep 10, 2022
@kylekatarnls kylekatarnls modified the milestones: 2.14.0, 2.15.0 Sep 27, 2023
@kylekatarnls kylekatarnls modified the milestones: 2.15.0, 2.16.0 Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants