Skip to content

resultProvenance object

A resultProvenance object contains information about the how and when theResult was detected.

resultProvenance object

Tip

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

docs/assets/sarif/resultProvenance.json
{
    "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
    "version": "2.1.0",
    "runs": [
        {
            "tool": {
                "driver": {
                    "name": "SarifSamples",
                    "version": "1.0",
                    "informationUri": "https://github.com/microsoft/sarif-tutorials/"
                }
            },
            "results": [
                {
                    "message": {
                        "text": "Assertions are unreliable."
                    },
                    "ruleId": "Assertions",
                    "provenance": {
                        "conversionSources": [
                            {
                                "artifactLocation": {
                                    "uri": "CodeScanner.log",
                                    "uriBaseId": "LOGSROOT"
                                },
                                "region": {
                                    "startLine": 3,
                                    "startColumn": 3,
                                    "endLine": 12,
                                    "endColumn": 13,
                                    "snippet": {
                                        "text": "<problem>...</problem>"
                                    }
                                }
                            }
                        ]
                    }
                }
            ]
        }
    ]
}
examples/resultProvenance.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\ArtifactContent;
use Bartlett\Sarif\Definition\ArtifactLocation;
use Bartlett\Sarif\Definition\Message;
use Bartlett\Sarif\Definition\PhysicalLocation;
use Bartlett\Sarif\Definition\Region;
use Bartlett\Sarif\Definition\Result;
use Bartlett\Sarif\Definition\ResultProvenance;
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('SarifSamples');
$driver->setInformationUri('https://github.com/microsoft/sarif-tutorials/');
$driver->setVersion('1.0');

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

$provenance = new ResultProvenance();
$fromSources = [];
$artifactLocation = new ArtifactLocation();
$artifactLocation->setUri('CodeScanner.log');
$artifactLocation->setUriBaseId('LOGSROOT');
$fromSources[0] = new PhysicalLocation();
$fromSources[0]->setArtifactLocation($artifactLocation);
$region = new Region();
$region->setStartLine(3);
$region->setEndLine(12);
$region->setStartColumn(3);
$region->setEndColumn(13);
$snippet = new ArtifactContent();
$snippet->setText('<problem>...</problem>');
$region->setSnippet($snippet);
$fromSources[0]->setRegion($region);

$provenance->addConversionSources($fromSources);

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

$result = new Result();
$result->setMessage($message);
$result->setRuleId('Assertions');
$result->setProvenance($provenance);

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

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

Note

This alternative API is available since release 1.5.0

examples/builder/resultProvenance.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/resultProvenance.md
$spec = $factory->specification('2.1.0')
    ->addRun(
        $factory->run()
            ->tool(
                $factory->tool()
                    ->driver(
                        $factory->driver()
                            ->name('SarifSamples')
                            ->version('1.0')
                            ->informationUri('https://github.com/microsoft/sarif-tutorials/')
                    )
            )
            ->addResult(
                $factory->result()
                    ->message(
                        $factory->message()
                            ->text('Assertions are unreliable.')
                    )
                    ->ruleId('Assertions')
                    ->provenance(
                        $factory->resultProvenance()
                            ->addConversionSource(
                                $factory->physicalLocation()
                                    ->artifactLocation(
                                        $factory->artifactLocation()
                                            ->uri('CodeScanner.log')
                                            ->uriBaseId('LOGSROOT')
                                    )
                                    ->region(
                                        $factory->region()
                                            ->startLine(3)
                                            ->startColumn(3)
                                            ->endLine(12)
                                            ->endColumn(13)
                                            ->snippet(
                                                $factory->artifactContent()
                                                    ->text('<problem>...</problem>')
                                            )
                                    )
                            )
                    )
            )
    )
;