Skip to content

conversion object

A conversion object describes how a converter transformed the output of an analysis tool from the analysis tool’s native output format into the SARIF format.

conversion object

Tip

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

docs/assets/sarif/conversion.json
{
    "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
    "version": "2.1.0",
    "runs": [
        {
            "tool": {
                "driver": {
                    "name": "AndroidStudio",
                    "semanticVersion": "1.0.0-beta.1",
                    "informationUri": "https://android-studion.dev"
                }
            },
            "conversion": {
                "tool": {
                    "driver": {
                        "name": "SARIF SDK Multitool"
                    }
                },
                "invocation": {
                    "executionSuccessful": true,
                    "commandLine": "Sarif.Multitool.exe convert -t AndroidStudio northwind.log"
                },
                "analysisToolLogFiles": [
                    {
                        "uri": "northwind.log",
                        "uriBaseId": "$LOG_DIR$"
                    }
                ]
            },
            "results": []
        }
    ]
}
examples/conversion.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\ArtifactLocation;
use Bartlett\Sarif\Definition\Conversion;
use Bartlett\Sarif\Definition\Invocation;
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('AndroidStudio');
$driver->setInformationUri('https://android-studion.dev');
$driver->setSemanticVersion('1.0.0-beta.1');

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

$converter = new Tool();
$sdk = new ToolComponent();
$sdk->setName('SARIF SDK Multitool');
$converter->setDriver($sdk);

$artifactLocation = new ArtifactLocation();
$artifactLocation->setUri('northwind.log');
$artifactLocation->setUriBaseId('$LOG_DIR$');

$invocation = new Invocation();
$invocation->setExecutionSuccessful(true);
$invocation->setCommandLine('Sarif.Multitool.exe convert -t AndroidStudio northwind.log');

$conversion = new Conversion();
$conversion->setTool($converter);
$conversion->addAnalysisToolLogFiles([$artifactLocation]);
$conversion->setInvocation($invocation);

$run = new Run();
$run->setTool($tool);
$run->setConversion($conversion);

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

Note

This alternative API is available since release 1.5.0

examples/builder/conversion.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/conversion.md
$spec = $factory->specification('2.1.0')
    ->addRun(
        $factory->run()
            ->tool(
                $factory->tool()
                    ->driver(
                        $factory->driver()
                            ->name('AndroidStudio')
                            ->semanticVersion('1.0.0-beta.1')
                            ->informationUri('https://android-studion.dev')
                    )
            )
            ->conversion(
                $factory->conversion()
                    ->tool(
                        $factory->tool()
                            ->driver(
                                $factory->driver()
                                    ->name('SARIF SDK Multitool')
                            )
                    )
                    ->invocation(
                        $factory->invocation()
                            ->executionSuccessful(true)
                            ->commandLine('Sarif.Multitool.exe convert -t AndroidStudio northwind.log')
                    )
                    ->addAnalysisToolLogFile(
                        $factory->artifactLocation()
                            ->uri('northwind.log')
                            ->uriBaseId('$LOG_DIR$')
                    )
            )
    )
;