To provide your own parser, you have to create a new PHP Class implementing
CodeMonitoring\Framework\Parse\ParserInterface. That’s all you have to do.
The interface defines the following methods:
rface ParserInterface extends CanHandleFileInterface, PriorityInterface /** * This method will be called once the parser will be used. * Due this method the file to parse will be provided. * * Most likely you will "persist" the file in a property for later usage in * getData method. * * @param Resource $file * * @return void */ public function setFileToParse(Resource $file); /** * Will provide the parsed information to the world. * * This method should return whatever the parser has parsed. Most likely * this method will be called by the importer. * * @return mixed */ public function getData();
Use Eel expression for
In addition you can use the trait
canHandle method. The trait will implement this method and provide the property
$eelExpression which can be configured through
An example can be found in CodeMonitoring.Parser.Checkstyle. Add the following to your parser class:
And the following to your
CodeMonitoring\Parser\Checkstyle\Parser\CheckstyleParser: properties: eelExpression: value: 'file.fileExtension == "xml" && String.substr(lines, 1, 10) == "checkstyle" && String.substr(lines, 21, 3) == "2.5"'
Adjust the first line to match your fully qualified class name.
The expression will be parsed through the trait and result in
false depending on
expression and file.
The above expression will check that the extension of file is equal to
xml and that the second
checkstyle in version
Currently the following context is provided to parse the expression:
For more information about Eel check out the official documentation about Eel.