2016-12-30 21:53:35 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Storage;
|
|
|
|
|
2019-07-05 22:24:00 +02:00
|
|
|
use function array_map;
|
|
|
|
use function implode;
|
2016-12-30 21:53:35 +01:00
|
|
|
use Psalm\CodeLocation;
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
|
2019-07-05 22:24:00 +02:00
|
|
|
use Psalm\Type;
|
2016-12-30 21:53:35 +01:00
|
|
|
|
|
|
|
class FunctionLikeStorage
|
|
|
|
{
|
2019-02-24 22:21:28 +01:00
|
|
|
use CustomMetadataTrait;
|
|
|
|
|
2016-12-30 21:53:35 +01:00
|
|
|
/**
|
2017-02-08 06:28:26 +01:00
|
|
|
* @var CodeLocation|null
|
2016-12-30 21:53:35 +01:00
|
|
|
*/
|
2017-02-08 06:28:26 +01:00
|
|
|
public $location;
|
2016-12-30 21:53:35 +01:00
|
|
|
|
2019-04-17 17:12:18 +02:00
|
|
|
/**
|
|
|
|
* @var CodeLocation|null
|
|
|
|
*/
|
|
|
|
public $stmt_location;
|
|
|
|
|
2016-12-30 21:53:35 +01:00
|
|
|
/**
|
|
|
|
* @var array<int, FunctionLikeParameter>
|
|
|
|
*/
|
|
|
|
public $params = [];
|
|
|
|
|
2017-01-06 07:07:11 +01:00
|
|
|
/**
|
2017-09-02 17:18:56 +02:00
|
|
|
* @var array<string, Type\Union|null>
|
2017-01-06 07:07:11 +01:00
|
|
|
*/
|
|
|
|
public $param_types = [];
|
|
|
|
|
2019-01-19 19:32:43 +01:00
|
|
|
/**
|
|
|
|
* @var array<int, Type\Union|null>
|
|
|
|
*/
|
|
|
|
public $param_out_types = [];
|
|
|
|
|
2016-12-30 21:53:35 +01:00
|
|
|
/**
|
|
|
|
* @var Type\Union|null
|
|
|
|
*/
|
|
|
|
public $return_type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CodeLocation|null
|
|
|
|
*/
|
|
|
|
public $return_type_location;
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
/**
|
|
|
|
* @var Type\Union|null
|
|
|
|
*/
|
|
|
|
public $signature_return_type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CodeLocation|null
|
|
|
|
*/
|
|
|
|
public $signature_return_type_location;
|
|
|
|
|
2016-12-30 21:53:35 +01:00
|
|
|
/**
|
2019-11-25 21:20:31 +01:00
|
|
|
* @var ?string
|
2016-12-30 21:53:35 +01:00
|
|
|
*/
|
|
|
|
public $cased_name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<int, string>
|
|
|
|
*/
|
|
|
|
public $suppressed_issues = [];
|
|
|
|
|
|
|
|
/**
|
2019-11-25 21:20:31 +01:00
|
|
|
* @var ?bool
|
2016-12-30 21:53:35 +01:00
|
|
|
*/
|
|
|
|
public $deprecated;
|
|
|
|
|
2018-12-02 00:37:49 +01:00
|
|
|
/**
|
2019-11-25 21:20:31 +01:00
|
|
|
* @var ?bool
|
2018-12-02 00:37:49 +01:00
|
|
|
*/
|
|
|
|
public $internal;
|
|
|
|
|
2019-05-11 16:15:50 +02:00
|
|
|
/**
|
|
|
|
* @var null|string
|
|
|
|
*/
|
2019-05-11 21:39:53 +02:00
|
|
|
public $psalm_internal;
|
2019-05-11 16:15:50 +02:00
|
|
|
|
2016-12-30 21:53:35 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2019-11-25 21:20:31 +01:00
|
|
|
public $variadic = false;
|
2017-01-13 18:03:22 +01:00
|
|
|
|
2018-01-13 07:15:00 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $returns_by_ref = false;
|
|
|
|
|
2017-01-13 18:03:22 +01:00
|
|
|
/**
|
2019-11-25 21:20:31 +01:00
|
|
|
* @var ?int
|
2017-01-13 18:03:22 +01:00
|
|
|
*/
|
|
|
|
public $required_param_count;
|
2017-01-15 22:43:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<string, Type\Union>
|
|
|
|
*/
|
|
|
|
public $defined_constants = [];
|
2017-01-30 05:44:05 +01:00
|
|
|
|
2018-05-31 04:09:46 +02:00
|
|
|
/**
|
|
|
|
* @var array<string, bool>
|
|
|
|
*/
|
|
|
|
public $global_variables = [];
|
|
|
|
|
2018-06-08 15:31:21 +02:00
|
|
|
/**
|
|
|
|
* @var array<string, Type\Union>
|
|
|
|
*/
|
|
|
|
public $global_types = [];
|
|
|
|
|
2017-02-10 02:35:17 +01:00
|
|
|
/**
|
2019-03-22 20:59:10 +01:00
|
|
|
* @var array<string, array<string, array{Type\Union}>>|null
|
2017-02-10 02:35:17 +01:00
|
|
|
*/
|
|
|
|
public $template_types;
|
|
|
|
|
2019-05-06 22:38:08 +02:00
|
|
|
/**
|
|
|
|
* @var array<int, bool>|null
|
|
|
|
*/
|
|
|
|
public $template_covariants;
|
|
|
|
|
2018-05-28 21:07:42 +02:00
|
|
|
/**
|
|
|
|
* @var array<int, Assertion>
|
|
|
|
*/
|
2017-09-21 21:36:26 +02:00
|
|
|
public $assertions = [];
|
2018-05-28 21:07:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<int, Assertion>
|
|
|
|
*/
|
|
|
|
public $if_true_assertions = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<int, Assertion>
|
|
|
|
*/
|
|
|
|
public $if_false_assertions = [];
|
2018-05-29 16:13:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $has_visitor_issues = false;
|
2018-06-22 07:13:49 +02:00
|
|
|
|
2018-11-01 22:03:08 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $has_docblock_issues = false;
|
|
|
|
|
2018-06-22 07:13:49 +02:00
|
|
|
/**
|
|
|
|
* @var array<string, bool>
|
|
|
|
*/
|
|
|
|
public $throws = [];
|
2018-07-15 23:47:58 +02:00
|
|
|
|
2019-08-13 21:44:18 +02:00
|
|
|
/**
|
|
|
|
* @var array<string, CodeLocation>
|
|
|
|
*/
|
|
|
|
public $throw_locations = [];
|
|
|
|
|
2018-07-15 23:47:58 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $has_yield = false;
|
2018-09-14 05:39:24 +02:00
|
|
|
|
2019-08-30 18:36:35 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $mutation_free = false;
|
|
|
|
|
2018-09-14 05:39:24 +02:00
|
|
|
/**
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
public $return_type_description;
|
2018-10-17 21:52:26 +02:00
|
|
|
|
2019-02-27 22:00:44 +01:00
|
|
|
/**
|
|
|
|
* @var array<string, CodeLocation>|null
|
|
|
|
*/
|
|
|
|
public $unused_docblock_params;
|
|
|
|
|
2019-07-18 07:31:48 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $pure = false;
|
|
|
|
|
2019-10-15 22:25:27 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $remove_taint = false;
|
|
|
|
|
2018-10-17 21:52:26 +02:00
|
|
|
public function __toString()
|
|
|
|
{
|
2019-06-22 21:59:16 +02:00
|
|
|
return $this->getSignature(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSignature(bool $allow_newlines = false): string
|
|
|
|
{
|
|
|
|
$newlines = $allow_newlines && !empty($this->params);
|
|
|
|
|
2019-07-03 22:58:27 +02:00
|
|
|
$symbol_text = 'function ' . $this->cased_name . '(' . ($newlines ? "\n" : '') . implode(
|
|
|
|
',' . ($newlines ? "\n" : ' '),
|
2018-10-17 21:52:26 +02:00
|
|
|
array_map(
|
2019-06-22 21:59:16 +02:00
|
|
|
function (FunctionLikeParameter $param) use ($newlines) : string {
|
|
|
|
return ($newlines ? ' ' : '') . ($param->type ?: 'mixed') . ' $' . $param->name;
|
2018-10-17 21:52:26 +02:00
|
|
|
},
|
|
|
|
$this->params
|
|
|
|
)
|
2019-07-03 22:58:27 +02:00
|
|
|
) . ($newlines ? "\n" : '') . ') : ' . ($this->return_type ?: 'mixed');
|
2018-10-17 21:52:26 +02:00
|
|
|
|
|
|
|
if (!$this instanceof MethodStorage) {
|
|
|
|
return $symbol_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($this->visibility) {
|
2018-11-06 03:57:36 +01:00
|
|
|
case ClassLikeAnalyzer::VISIBILITY_PRIVATE:
|
2018-10-17 21:52:26 +02:00
|
|
|
$visibility_text = 'private';
|
|
|
|
break;
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
case ClassLikeAnalyzer::VISIBILITY_PROTECTED:
|
2018-10-17 21:52:26 +02:00
|
|
|
$visibility_text = 'protected';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$visibility_text = 'public';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $visibility_text . ' ' . $symbol_text;
|
|
|
|
}
|
2016-12-30 21:53:35 +01:00
|
|
|
}
|