2016-10-09 23:54:58 +02:00
|
|
|
<?php
|
2018-05-12 00:35:02 +02:00
|
|
|
namespace Psalm\Storage;
|
|
|
|
|
|
|
|
use Psalm\CodeLocation;
|
|
|
|
use Psalm\Type;
|
2016-10-09 23:54:58 +02:00
|
|
|
|
|
|
|
class FunctionLikeParameter
|
|
|
|
{
|
2019-02-24 22:21:28 +01:00
|
|
|
use CustomMetadataTrait;
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-10-09 23:54:58 +02:00
|
|
|
public $name;
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2016-10-09 23:54:58 +02:00
|
|
|
public $by_ref;
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
2017-09-02 17:18:56 +02:00
|
|
|
* @var Type\Union|null
|
2016-11-02 07:29:00 +01:00
|
|
|
*/
|
2016-10-09 23:54:58 +02:00
|
|
|
public $type;
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
2017-09-02 17:18:56 +02:00
|
|
|
* @var Type\Union|null
|
2016-11-02 07:29:00 +01:00
|
|
|
*/
|
2016-10-16 00:01:04 +02:00
|
|
|
public $signature_type;
|
|
|
|
|
2019-01-19 18:42:46 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $has_docblock_type = false;
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2016-10-09 23:54:58 +02:00
|
|
|
public $is_optional;
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2016-10-09 23:54:58 +02:00
|
|
|
public $is_nullable;
|
|
|
|
|
2018-06-07 18:23:10 +02:00
|
|
|
/**
|
|
|
|
* @var Type\Union|null
|
|
|
|
*/
|
|
|
|
public $default_type;
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
2016-12-04 01:11:30 +01:00
|
|
|
* @var CodeLocation|null
|
2016-11-02 07:29:00 +01:00
|
|
|
*/
|
2017-03-02 00:36:04 +01:00
|
|
|
public $location;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CodeLocation|null
|
|
|
|
*/
|
2017-12-30 03:28:21 +01:00
|
|
|
public $type_location;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CodeLocation|null
|
|
|
|
*/
|
|
|
|
public $signature_type_location;
|
2016-10-15 06:12:57 +02:00
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2016-10-23 07:57:11 +02:00
|
|
|
public $is_variadic;
|
|
|
|
|
2016-10-15 06:12:57 +02:00
|
|
|
/**
|
|
|
|
* @param string $name
|
2017-05-27 02:16:18 +02:00
|
|
|
* @param bool $by_ref
|
2017-09-02 17:18:56 +02:00
|
|
|
* @param Type\Union|null $type
|
|
|
|
* @param CodeLocation|null $location
|
2017-05-27 02:16:18 +02:00
|
|
|
* @param bool $is_optional
|
|
|
|
* @param bool $is_nullable
|
|
|
|
* @param bool $is_variadic
|
2018-06-07 18:23:10 +02:00
|
|
|
* @param Type\Union|null $default_type
|
2016-10-15 06:12:57 +02:00
|
|
|
*/
|
2016-11-02 07:29:00 +01:00
|
|
|
public function __construct(
|
|
|
|
$name,
|
2019-03-01 14:57:10 +01:00
|
|
|
bool $by_ref,
|
2017-09-02 17:18:56 +02:00
|
|
|
Type\Union $type = null,
|
2017-03-02 00:36:04 +01:00
|
|
|
CodeLocation $location = null,
|
2017-12-30 03:28:21 +01:00
|
|
|
CodeLocation $type_location = null,
|
2016-11-02 07:29:00 +01:00
|
|
|
$is_optional = true,
|
|
|
|
$is_nullable = false,
|
2018-06-07 18:23:10 +02:00
|
|
|
$is_variadic = false,
|
|
|
|
$default_type = null
|
2016-11-02 07:29:00 +01:00
|
|
|
) {
|
2016-10-09 23:54:58 +02:00
|
|
|
$this->name = $name;
|
|
|
|
$this->by_ref = $by_ref;
|
|
|
|
$this->type = $type;
|
2016-10-16 00:01:04 +02:00
|
|
|
$this->signature_type = $type;
|
2016-10-09 23:54:58 +02:00
|
|
|
$this->is_optional = $is_optional;
|
|
|
|
$this->is_nullable = $is_nullable;
|
2016-10-19 06:31:32 +02:00
|
|
|
$this->is_variadic = $is_variadic;
|
2017-03-02 00:36:04 +01:00
|
|
|
$this->location = $location;
|
2017-12-30 03:28:21 +01:00
|
|
|
$this->type_location = $type_location;
|
|
|
|
$this->signature_type_location = $type_location;
|
2018-06-07 18:23:10 +02:00
|
|
|
$this->default_type = $default_type;
|
2016-10-09 23:54:58 +02:00
|
|
|
}
|
2018-03-27 04:13:10 +02:00
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
2018-04-09 22:45:54 +02:00
|
|
|
return ($this->type ?: 'mixed')
|
|
|
|
. ($this->is_variadic ? '...' : '')
|
|
|
|
. ($this->is_optional ? '=' : '');
|
2018-03-27 04:13:10 +02:00
|
|
|
}
|
2018-06-09 16:14:18 +02:00
|
|
|
|
2019-03-01 15:06:37 +01:00
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return ($this->type ? $this->type->getId() : 'mixed')
|
|
|
|
. ($this->is_variadic ? '...' : '')
|
|
|
|
. ($this->is_optional ? '=' : '');
|
|
|
|
}
|
|
|
|
|
2018-06-09 16:14:18 +02:00
|
|
|
public function __clone()
|
|
|
|
{
|
|
|
|
if ($this->type) {
|
|
|
|
$this->type = clone $this->type;
|
|
|
|
}
|
|
|
|
}
|
2016-10-09 23:54:58 +02:00
|
|
|
}
|