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;
|
2016-12-30 21:53:35 +01:00
|
|
|
|
|
|
|
class FunctionLikeStorage
|
|
|
|
{
|
|
|
|
/**
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 = [];
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
/**
|
2018-06-19 19:19:34 +02:00
|
|
|
* @var array<string, Type\Union>|null
|
2017-02-10 02:35:17 +01:00
|
|
|
*/
|
|
|
|
public $template_types;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $has_template_return_type;
|
2017-02-27 05:09:18 +01:00
|
|
|
|
|
|
|
/**
|
2017-02-28 00:24:20 +01:00
|
|
|
* @var array<string, array<int, CodeLocation>>|null
|
2017-02-27 05:09:18 +01:00
|
|
|
*/
|
|
|
|
public $referencing_locations;
|
2017-09-21 21:36:26 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
$symbol_text = 'function ' . $this->cased_name . '(' . implode(
|
|
|
|
', ',
|
|
|
|
array_map(
|
|
|
|
function (FunctionLikeParameter $param) : string {
|
|
|
|
return ($param->type ?: 'mixed') . ' $' . $param->name;
|
|
|
|
},
|
|
|
|
$this->params
|
|
|
|
)
|
|
|
|
) . ') : ' . ($this->return_type ?: 'mixed');
|
|
|
|
|
|
|
|
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
|
|
|
}
|