edge object
A edge
object represents a directed edge in the graph represented by theGraph.
Tip
Generated with following command : php ./resources/serialize.php graph docs/assets/sarif 192
docs/assets/sarif/graph.json
{
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "CodeScanner",
"fullName": "CodeScanner 1.1, Developer Preview (en-US)",
"version": "1.1.2b12",
"semanticVersion": "1.1.2-beta.12",
"informationUri": "https://codeScanner.dev"
}
},
"results": [
{
"message": {
"text": "Have a look on this graph"
},
"graphs": [
{
"nodes": [
{
"id": "n2"
},
{
"id": "n3"
},
{
"id": "n4"
},
{
"id": "n1",
"children": [
{
"id": "n3"
}
]
}
],
"edges": [
{
"id": "e1",
"sourceNodeId": "n3",
"targetNodeId": "n4"
}
]
}
]
}
]
}
]
}
examples/graph.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\Edge;
use Bartlett\Sarif\Definition\Graph;
use Bartlett\Sarif\Definition\Message;
use Bartlett\Sarif\Definition\Node;
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->setFullName('CodeScanner 1.1, Developer Preview (en-US)');
$driver->setSemanticVersion('1.1.2-beta.12');
$driver->setVersion('1.1.2b12');
$tool = new Tool();
$tool->setDriver($driver);
$nodes = [];
foreach ([2 => 'n2', 3 => 'n3', 4 => 'n4', 1 => 'n1'] as $idx => $nodeId) {
$node = new Node();
$node->setId($nodeId);
$nodes[$idx] = $node;
}
$nodes[1]->addChildren([$nodes[3]]);
$edges = [];
$edges[1] = new Edge();
$edges[1]->setId('e1');
$edges[1]->setSourceNodeId('n3');
$edges[1]->setTargetNodeId('n4');
$graph = new Graph();
$graph->addNodes($nodes);
$graph->addEdges($edges);
$message = new Message();
$message->setText('Have a look on this graph');
$result = new Result();
$result->setMessage($message);
$result->addGraphs([$graph]);
$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/graph.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/graph.md
$spec = $factory->specification('2.1.0')
->addRun(
$factory->run()
->tool(
$factory->tool()
->driver(
$factory->driver()
->name('CodeScanner')
->fullName('CodeScanner 1.1, Developer Preview (en-US)')
->version('1.1.2b12')
->semanticVersion('1.1.2-beta.12')
->informationUri('https://codeScanner.dev')
)
)
->addResult(
$factory->result()
->message(
$factory->message()
->text('Have a look on this graph')
)
->addGraph(
$factory->graph()
->addNode(
$factory->node()
->id('n2')
)
->addNode(
$factory->node()
->id('n3')
)
->addNode(
$factory->node()
->id('n4')
)
->addNode(
$factory->node()
->id('n1')
->addChildren(
$factory->node()
->id('n3')
)
)
->addEdge(
$factory->edge()
->id('e1')
->sourceNodeId('n3')
->targetNodeId('n4')
)
)
)
)
;