Skip to content

rectangle object

A rectangle object specifies a rectangular area within an image. When a SARIF viewer displays an image, it MAY indicate the presence of these areas, for example, by highlighting them or surrounding them with a border.

rectangle object

Tip

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

docs/assets/sarif/rectangle.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 screen shot provided"
                    },
                    "attachments": [
                        {
                            "artifactLocation": {
                                "uri": "file:///C:/ScanOutput/image001.png"
                            },
                            "description": {
                                "text": "Screen shot"
                            },
                            "rectangles": [
                                {
                                    "top": 80,
                                    "left": 10,
                                    "bottom": 5,
                                    "right": 90
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}
examples/rectangle.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\Attachment;
use Bartlett\Sarif\Definition\Message;
use Bartlett\Sarif\Definition\Rectangle;
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);

$desc = new Message();
$desc->setText('Screen shot');

$attachment = new Attachment();
$attachment->setDescription($desc);
$artifactLocation = new ArtifactLocation();
$artifactLocation->setUri('file:///C:/ScanOutput/image001.png');
$attachment->setArtifactLocation($artifactLocation);
$rectangle = new Rectangle();
$rectangle->setTop(80);
$rectangle->setLeft(10);
$rectangle->setBottom(5);
$rectangle->setRight(90);
$attachment->addRectangles([$rectangle]);

$message = new Message();
$message->setText('Have a look on screen shot provided');

$result = new Result();
$result->setMessage($message);
$result->addAttachments([$attachment]);

$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/rectangle.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/rectangle.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 screen shot provided')
                    )
                    ->addAttachment(
                        $factory->attachment()
                            ->artifactLocation(
                                $factory->artifactLocation()
                                    ->uri('file:///C:/ScanOutput/image001.png')
                            )
                            ->description('Screen shot')
                            ->addRectangle(
                                $factory->rectangle()
                                    ->top(80)
                                    ->left(10)
                                    ->bottom(5)
                                    ->right(90)
                            )
                    )
            )
    )
;