locationRelationship object
A locationRelationship
object specifies one or more directed relationships from one location object,
which we refer to as theSource, to another one, which we refer to as theTarget.
Tip
Generated with following command : php ./resources/serialize.php locationRelationship docs/assets/sarif 192
docs/assets/sarif/locationRelationship.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"
}
},
"results": [
{
"message": {
"text": "A result object with locationRelationship object"
},
"locations": [
{
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "f.h"
},
"region": {
"startLine": 42
}
},
"relationships": [
{
"target": 1,
"kinds": [
"isIncludedBy"
]
}
]
}
],
"relatedLocations": [
{
"id": 1,
"physicalLocation": {
"artifactLocation": {
"uri": "g.h"
},
"region": {
"startLine": 17
}
},
"relationships": [
{
"target": 0,
"kinds": [
"includes"
]
},
{
"target": 2,
"kinds": [
"isIncludedBy"
]
}
]
},
{
"id": 2,
"physicalLocation": {
"artifactLocation": {
"uri": "g.c"
},
"region": {
"startLine": 8
}
},
"relationships": [
{
"target": 1,
"kinds": [
"includes"
]
}
]
}
]
}
]
}
]
}
examples/locationRelationship.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\Location;
use Bartlett\Sarif\Definition\LocationRelationship;
use Bartlett\Sarif\Definition\Message;
use Bartlett\Sarif\Definition\PhysicalLocation;
use Bartlett\Sarif\Definition\Region;
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');
$tool = new Tool();
$tool->setDriver($driver);
$location = [];
$physicalLocation = [];
$artifactLocation = [];
$region = [];
$relationships = [];
$location[0] = new Location();
$location[0]->setId(0);
$artifactLocation[0] = new ArtifactLocation();
$artifactLocation[0]->setUri('f.h');
$physicalLocation[0] = new PhysicalLocation();
$physicalLocation[0]->setArtifactLocation($artifactLocation[0]);
$region[0] = new Region();
$region[0]->setStartLine(42);
$physicalLocation[0]->setRegion($region[0]);
$location[0]->setPhysicalLocation($physicalLocation[0]);
$relationships[0] = new LocationRelationship();
$relationships[0]->setTarget(1);
$relationships[0]->addKinds(['isIncludedBy']);
$location[0]->addRelationships([$relationships[0]]);
$location[1] = new Location();
$location[1]->setId(1);
$artifactLocation[1] = new ArtifactLocation();
$artifactLocation[1]->setUri('g.h');
$physicalLocation[1] = new PhysicalLocation();
$physicalLocation[1]->setArtifactLocation($artifactLocation[1]);
$region[1] = new Region();
$region[1]->setStartLine(17);
$physicalLocation[1]->setRegion($region[1]);
$location[1]->setPhysicalLocation($physicalLocation[1]);
$relationships[1] = new LocationRelationship();
$relationships[1]->setTarget(0);
$relationships[1]->addKinds(['includes']);
$relationships[2] = new LocationRelationship();
$relationships[2]->setTarget(2);
$relationships[2]->addKinds(['isIncludedBy']);
$location[1]->addRelationships([$relationships[1], $relationships[2]]);
$location[2] = new Location();
$location[2]->setId(2);
$artifactLocation[2] = new ArtifactLocation();
$artifactLocation[2]->setUri('g.c');
$physicalLocation[2] = new PhysicalLocation();
$physicalLocation[2]->setArtifactLocation($artifactLocation[2]);
$region[2] = new Region();
$region[2]->setStartLine(8);
$physicalLocation[2]->setRegion($region[2]);
$location[2]->setPhysicalLocation($physicalLocation[2]);
$relationships[2] = new LocationRelationship();
$relationships[2]->setTarget(1);
$relationships[2]->addKinds(['includes']);
$location[2]->addRelationships([$relationships[2]]);
$message = new Message();
$message->setText('A result object with locationRelationship object');
$result = new Result();
$result->setMessage($message);
$result->addLocations([$location[0]]);
$result->addRelatedLocations([$location[1], $location[2]]);
$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/locationRelationship.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/locationRelationship.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')
)
)
->addResult(
$factory->result()
->message(
$factory->message()
->text('A result object with locationRelationship object')
)
->addLocation(
$factory->location()
->id(0)
->physicalLocation(
$factory->physicalLocation()
->artifactLocation(
$factory->artifactLocation()
->uri('f.h')
)
->region(
$factory->region()
->startLine(42)
)
)
->addRelationship(
$factory->locationRelationship()
->target(1)
->addKind('isIncludedBy')
)
)
->addRelatedLocation(
$factory->location()
->id(1)
->physicalLocation(
$factory->physicalLocation()
->artifactLocation(
$factory->artifactLocation()
->uri('g.h')
)
->region(
$factory->region()
->startLine(17)
)
)
->addRelationship(
$factory->locationRelationship()
->target(0)
->addKind('includes')
)
->addRelationship(
$factory->locationRelationship()
->target(2)
->addKind('isIncludedBy')
)
)
->addRelatedLocation(
$factory->location()
->id(2)
->physicalLocation(
$factory->physicalLocation()
->artifactLocation(
$factory->artifactLocation()
->uri('g.c')
)
->region(
$factory->region()
->startLine(8)
)
)
->addRelationship(
$factory->locationRelationship()
->target(1)
->addKind('includes')
)
)
)
)
;