2019-08-04 16:37:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Psalm\Internal\Taint;
|
|
|
|
|
|
|
|
use Psalm\CodeLocation;
|
|
|
|
|
2019-08-14 06:47:57 +02:00
|
|
|
abstract class Taintable
|
2019-08-04 16:37:36 +02:00
|
|
|
{
|
|
|
|
/** @var string */
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
/** @var ?CodeLocation */
|
|
|
|
public $code_location;
|
|
|
|
|
2019-08-13 05:16:05 +02:00
|
|
|
/** @var int */
|
|
|
|
public $taint;
|
|
|
|
|
|
|
|
public function __construct(string $id, ?CodeLocation $code_location, int $taint = 0)
|
2019-08-04 16:37:36 +02:00
|
|
|
{
|
|
|
|
$this->id = $id;
|
|
|
|
$this->code_location = $code_location;
|
2019-08-13 05:16:05 +02:00
|
|
|
$this->taint = $taint;
|
2019-08-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
2019-08-14 06:47:57 +02:00
|
|
|
/**
|
|
|
|
* @return static
|
|
|
|
*/
|
2019-08-04 16:37:36 +02:00
|
|
|
public static function getForMethodArgument(
|
|
|
|
string $method_id,
|
|
|
|
int $argument_offset,
|
2019-08-06 00:33:33 +02:00
|
|
|
?CodeLocation $code_location,
|
|
|
|
?CodeLocation $function_location = null
|
2019-08-14 06:47:57 +02:00
|
|
|
) {
|
2019-08-06 00:33:33 +02:00
|
|
|
$function_id = $method_id . '#' . ($argument_offset + 1);
|
|
|
|
|
|
|
|
if ($function_location) {
|
2019-08-06 23:29:44 +02:00
|
|
|
$function_id .= '-' . $function_location->file_name . ':' . $function_location->raw_file_start;
|
2019-08-06 00:33:33 +02:00
|
|
|
}
|
|
|
|
|
2019-08-14 06:47:57 +02:00
|
|
|
return new static(\strtolower($function_id), $code_location);
|
2019-08-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
}
|