Skip to content

invocation object

An invocation object describes the invocation of the analysis tool that was run.

invocation object

Tip

Generated with following command : php ./resources/serialize.php reportingDescriptorReference docs/assets/sarif 192

docs/assets/sarif/reportingDescriptorReference.json
{
    "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
    "version": "2.1.0",
    "runs": [
        {
            "tool": {
                "driver": {
                    "name": "CodeScanner",
                    "semanticVersion": "1.1.2-beta.12",
                    "informationUri": "https://codeScanner.dev",
                    "rules": [
                        {
                            "id": "CTN9999",
                            "shortDescription": {
                                "text": "First version of rule."
                            }
                        },
                        {
                            "id": "CTN9999",
                            "shortDescription": {
                                "text": "Second version of rule."
                            }
                        }
                    ]
                }
            },
            "invocations": [
                {
                    "executionSuccessful": true,
                    "toolExecutionNotifications": [
                        {
                            "message": {
                                "text": "Exception evaluating rule 'C2001'. Rule configuration is missing."
                            },
                            "level": "error",
                            "descriptor": {
                                "index": 1,
                                "id": "CTN9999"
                            }
                        }
                    ]
                }
            ],
            "results": [
                {
                    "message": {
                        "text": "..."
                    },
                    "ruleId": "CTN9999"
                }
            ]
        }
    ]
}
examples/reportingDescriptorReference.php
<?php declare(strict_types=1);
/**
 * This file is part of the Sarif-PHP-SDK package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author Laurent Laville
 */

use Bartlett\Sarif\Definition\Invocation;
use Bartlett\Sarif\Definition\Message;
use Bartlett\Sarif\Definition\MultiformatMessageString;
use Bartlett\Sarif\Definition\Notification;
use Bartlett\Sarif\Definition\ReportingDescriptor;
use Bartlett\Sarif\Definition\ReportingDescriptorReference;
use Bartlett\Sarif\Definition\Result;
use Bartlett\Sarif\Definition\Run;
use Bartlett\Sarif\Definition\Tool;
use Bartlett\Sarif\Definition\ToolComponent;
use Bartlett\Sarif\SarifLog;

require_once dirname(__DIR__) . '/vendor/autoload.php';

$driver = new ToolComponent();
$driver->setName('CodeScanner');
$driver->setInformationUri('https://codeScanner.dev');
$driver->setSemanticVersion('1.1.2-beta.12');

$ruleV1 = new ReportingDescriptor();
$ruleV1->setId('CTN9999');
$desc = new MultiformatMessageString();
$desc->setText('First version of rule.');
$ruleV1->setShortDescription($desc);

$ruleV2 = new ReportingDescriptor();
$ruleV2->setId('CTN9999');
$desc = new MultiformatMessageString();
$desc->setText('Second version of rule.');
$ruleV2->setShortDescription($desc);

$driver->addRules([$ruleV1, $ruleV2]);

$tool = new Tool();
$tool->setDriver($driver);

$message = new Message();
$message->setText("Exception evaluating rule 'C2001'. Rule configuration is missing.");

$notification = new Notification();
$notification->setMessage($message);
$associatedRule = new ReportingDescriptorReference();
$associatedRule->setIndex(0);
$associatedRule->setId('C2001');
$notification->setAssociatedRule($associatedRule);
$descriptor = new ReportingDescriptorReference();
$descriptor->setIndex(1);
$descriptor->setId('CTN9999');
$notification->setDescriptor($descriptor);
$notification->setLevel('error');
$invocation = new Invocation();
$invocation->setExecutionSuccessful(true);
$invocation->addToolExecutionNotifications([$notification]);

$message = new Message();
$message->setText('...');

$result = new Result();
$result->setMessage($message);
$result->setRuleId('CTN9999');

$run = new Run();
$run->setTool($tool);
$run->addResults([$result]);
$run->addInvocations([$invocation]);

$log = new SarifLog([$run]);

Note

This alternative API is available since release 1.5.0

examples/builder/reportingDescriptorReference.php
<?php declare(strict_types=1);
/**
 * This file is part of the Sarif-PHP-SDK package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author Laurent Laville
 */

require_once dirname(__DIR__, 2) . '/vendor/autoload.php';

use Bartlett\Sarif\Factory\BuilderFactory;

$factory = new BuilderFactory();

// @link https://github.com/llaville/sarif-php-sdk/blob/1.1/docs/reference/reportingDescriptorReference.md
$spec = $factory->specification('2.1.0')
    ->addRun(
        $factory->run()
            ->tool(
                $factory->tool()
                    ->driver(
                        $factory->driver()
                            ->name('CodeScanner')
                            ->semanticVersion('1.1.2-beta.12')
                            ->informationUri('https://codeScanner.dev')
                            ->addRule(
                                $factory->rule()
                                    ->id('CTN9999')
                                    ->shortDescription('First version of rule.')
                            )
                            ->addRule(
                                $factory->rule()
                                    ->id('CTN9999')
                                    ->shortDescription('Second version of rule.')
                            )
                    )
            )
            ->addInvocation(
                $factory->invocation()
                    ->executionSuccessful(true)
                    ->addToolExecutionNotification(
                        $factory->notification()
                            ->message("Exception evaluating rule 'C2001'. Rule configuration is missing.")
                            ->level('error')
                            ->descriptor(
                                $factory->descriptor()
                                    ->index(1)
                                    ->id('CTN9999')
                            )
                    )
            )
            ->addResult(
                $factory->result()
                    ->message(
                        $factory->message()
                            ->text('...')
                    )
                    ->ruleId('CTN9999')
            )
    )
;