2016-12-30 21:53:35 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Storage;
|
|
|
|
|
|
|
|
use Psalm\CodeLocation;
|
2017-05-19 06:48:26 +02:00
|
|
|
use Psalm\Type;
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
|
2019-06-26 22:52:29 +02:00
|
|
|
use const PHP_EOL;
|
|
|
|
use function implode;
|
|
|
|
use function array_map;
|
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
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $cased_name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<int, string>
|
|
|
|
*/
|
|
|
|
public $suppressed_issues = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $deprecated;
|
|
|
|
|
2018-12-02 00:37:49 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public $variadic;
|
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
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $has_yield = 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;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
$symbol_text = 'function ' . $this->cased_name . '(' . ($newlines ? PHP_EOL : '') . implode(
|
|
|
|
',' . ($newlines ? PHP_EOL : ' '),
|
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-06-22 21:59:16 +02:00
|
|
|
) . ($newlines ? PHP_EOL : '') . ') : ' . ($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
|
|
|
}
|