2018-02-23 21:39:33 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Storage;
|
|
|
|
|
|
|
|
class Assertion
|
|
|
|
{
|
|
|
|
/**
|
2018-05-13 01:38:43 +02:00
|
|
|
* @var array<int, array<int, string>> the rule being asserted
|
2018-02-23 21:39:33 +01:00
|
|
|
*/
|
|
|
|
public $rule;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int|string the id of the property/variable, or
|
|
|
|
* the parameter offset of the affected arg
|
|
|
|
*/
|
|
|
|
public $var_id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|int $var_id
|
2018-05-13 01:38:43 +02:00
|
|
|
* @param array<int, array<int, string>> $rule
|
2018-02-23 21:39:33 +01:00
|
|
|
*/
|
|
|
|
public function __construct($var_id, $rule)
|
|
|
|
{
|
|
|
|
$this->rule = $rule;
|
|
|
|
$this->var_id = $var_id;
|
|
|
|
}
|
2019-01-23 05:42:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<string, array{0:\Psalm\Type\Union, 1:null|string}> $template_type_map
|
|
|
|
*/
|
|
|
|
public function getUntemplatedCopy(array $template_type_map) : self
|
|
|
|
{
|
|
|
|
return new Assertion(
|
|
|
|
$this->var_id,
|
|
|
|
array_map(
|
|
|
|
/**
|
|
|
|
* @param array<int, string> $rules
|
|
|
|
*/
|
|
|
|
function (array $rules) use ($template_type_map) : array {
|
|
|
|
$first_rule = $rules[0];
|
|
|
|
|
|
|
|
$rule_tokens = \Psalm\Type::tokenize($first_rule);
|
|
|
|
|
|
|
|
if ($template_type_map) {
|
|
|
|
foreach ($rule_tokens as &$rule_token) {
|
|
|
|
if (isset($template_type_map[$rule_token])) {
|
|
|
|
$rule_token = $template_type_map[$rule_token][0]->getId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [implode('', $rule_tokens)];
|
|
|
|
},
|
|
|
|
$this->rule
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2018-02-23 21:39:33 +01:00
|
|
|
}
|