repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 39
1.84M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
twilio/twilio-php | Twilio/Rest/Api/V2010/Account/Sip/IpAccessControlList/IpAddressList.php | IpAddressList.create | public function create($friendlyName, $ipAddress, $options = array()) {
$options = new Values($options);
$data = Values::of(array(
'FriendlyName' => $friendlyName,
'IpAddress' => $ipAddress,
'CidrPrefixLength' => $options['cidrPrefixLength'],
));
$payload = $this->version->create(
'POST',
$this->uri,
array(),
$data
);
return new IpAddressInstance(
$this->version,
$payload,
$this->solution['accountSid'],
$this->solution['ipAccessControlListSid']
);
} | php | public function create($friendlyName, $ipAddress, $options = array()) {
$options = new Values($options);
$data = Values::of(array(
'FriendlyName' => $friendlyName,
'IpAddress' => $ipAddress,
'CidrPrefixLength' => $options['cidrPrefixLength'],
));
$payload = $this->version->create(
'POST',
$this->uri,
array(),
$data
);
return new IpAddressInstance(
$this->version,
$payload,
$this->solution['accountSid'],
$this->solution['ipAccessControlListSid']
);
} | [
"public",
"function",
"create",
"(",
"$",
"friendlyName",
",",
"$",
"ipAddress",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"new",
"Values",
"(",
"$",
"options",
")",
";",
"$",
"data",
"=",
"Values",
"::",
"of",
"(",
"array",
"(",
"'FriendlyName'",
"=>",
"$",
"friendlyName",
",",
"'IpAddress'",
"=>",
"$",
"ipAddress",
",",
"'CidrPrefixLength'",
"=>",
"$",
"options",
"[",
"'cidrPrefixLength'",
"]",
",",
")",
")",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"version",
"->",
"create",
"(",
"'POST'",
",",
"$",
"this",
"->",
"uri",
",",
"array",
"(",
")",
",",
"$",
"data",
")",
";",
"return",
"new",
"IpAddressInstance",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"payload",
",",
"$",
"this",
"->",
"solution",
"[",
"'accountSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'ipAccessControlListSid'",
"]",
")",
";",
"}"
] | Create a new IpAddressInstance
@param string $friendlyName A human readable descriptive text for this
resource, up to 64 characters long.
@param string $ipAddress An IP address in dotted decimal notation from which
you want to accept traffic. Any SIP requests from
this IP address will be allowed by Twilio. IPv4
only supported today.
@param array|Options $options Optional Arguments
@return IpAddressInstance Newly created IpAddressInstance
@throws TwilioException When an HTTP error occurs. | [
"Create",
"a",
"new",
"IpAddressInstance"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Api/V2010/Account/Sip/IpAccessControlList/IpAddressList.php#L140-L162 |
twilio/twilio-php | Twilio/Rest/Api/V2010/Account/Sip/IpAccessControlList/IpAddressList.php | IpAddressList.getContext | public function getContext($sid) {
return new IpAddressContext(
$this->version,
$this->solution['accountSid'],
$this->solution['ipAccessControlListSid'],
$sid
);
} | php | public function getContext($sid) {
return new IpAddressContext(
$this->version,
$this->solution['accountSid'],
$this->solution['ipAccessControlListSid'],
$sid
);
} | [
"public",
"function",
"getContext",
"(",
"$",
"sid",
")",
"{",
"return",
"new",
"IpAddressContext",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'accountSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'ipAccessControlListSid'",
"]",
",",
"$",
"sid",
")",
";",
"}"
] | Constructs a IpAddressContext
@param string $sid A string that identifies the IpAddress resource to fetch
@return \Twilio\Rest\Api\V2010\Account\Sip\IpAccessControlList\IpAddressContext | [
"Constructs",
"a",
"IpAddressContext"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Api/V2010/Account/Sip/IpAccessControlList/IpAddressList.php#L170-L177 |
twilio/twilio-php | Twilio/Rest/Serverless/V1/Service/FunctionInstance.php | FunctionInstance.proxy | protected function proxy() {
if (!$this->context) {
$this->context = new FunctionContext(
$this->version,
$this->solution['serviceSid'],
$this->solution['sid']
);
}
return $this->context;
} | php | protected function proxy() {
if (!$this->context) {
$this->context = new FunctionContext(
$this->version,
$this->solution['serviceSid'],
$this->solution['sid']
);
}
return $this->context;
} | [
"protected",
"function",
"proxy",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"context",
")",
"{",
"$",
"this",
"->",
"context",
"=",
"new",
"FunctionContext",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'serviceSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'sid'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"context",
";",
"}"
] | Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
@return \Twilio\Rest\Serverless\V1\Service\FunctionContext Context for this
FunctionInstance | [
"Generate",
"an",
"instance",
"context",
"for",
"the",
"instance",
"the",
"context",
"is",
"capable",
"of",
"performing",
"various",
"actions",
".",
"All",
"instance",
"actions",
"are",
"proxied",
"to",
"the",
"context"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Serverless/V1/Service/FunctionInstance.php#L67-L77 |
twilio/twilio-php | Twilio/Rest/Serverless/V1/Service/AssetInstance.php | AssetInstance.proxy | protected function proxy() {
if (!$this->context) {
$this->context = new AssetContext(
$this->version,
$this->solution['serviceSid'],
$this->solution['sid']
);
}
return $this->context;
} | php | protected function proxy() {
if (!$this->context) {
$this->context = new AssetContext(
$this->version,
$this->solution['serviceSid'],
$this->solution['sid']
);
}
return $this->context;
} | [
"protected",
"function",
"proxy",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"context",
")",
"{",
"$",
"this",
"->",
"context",
"=",
"new",
"AssetContext",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'serviceSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'sid'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"context",
";",
"}"
] | Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
@return \Twilio\Rest\Serverless\V1\Service\AssetContext Context for this
AssetInstance | [
"Generate",
"an",
"instance",
"context",
"for",
"the",
"instance",
"the",
"context",
"is",
"capable",
"of",
"performing",
"various",
"actions",
".",
"All",
"instance",
"actions",
"are",
"proxied",
"to",
"the",
"context"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Serverless/V1/Service/AssetInstance.php#L67-L77 |
twilio/twilio-php | Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsInstance.php | WorkerStatisticsInstance.proxy | protected function proxy() {
if (!$this->context) {
$this->context = new WorkerStatisticsContext(
$this->version,
$this->solution['workspaceSid'],
$this->solution['workerSid']
);
}
return $this->context;
} | php | protected function proxy() {
if (!$this->context) {
$this->context = new WorkerStatisticsContext(
$this->version,
$this->solution['workspaceSid'],
$this->solution['workerSid']
);
}
return $this->context;
} | [
"protected",
"function",
"proxy",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"context",
")",
"{",
"$",
"this",
"->",
"context",
"=",
"new",
"WorkerStatisticsContext",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'workspaceSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'workerSid'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"context",
";",
"}"
] | Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
@return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkerStatisticsContext Context for this WorkerStatisticsInstance | [
"Generate",
"an",
"instance",
"context",
"for",
"the",
"instance",
"the",
"context",
"is",
"capable",
"of",
"performing",
"various",
"actions",
".",
"All",
"instance",
"actions",
"are",
"proxied",
"to",
"the",
"context"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsInstance.php#L56-L66 |
twilio/twilio-php | Twilio/Rest/Chat/V1/CredentialList.php | CredentialList.create | public function create($type, $options = array()) {
$options = new Values($options);
$data = Values::of(array(
'Type' => $type,
'FriendlyName' => $options['friendlyName'],
'Certificate' => $options['certificate'],
'PrivateKey' => $options['privateKey'],
'Sandbox' => Serialize::booleanToString($options['sandbox']),
'ApiKey' => $options['apiKey'],
'Secret' => $options['secret'],
));
$payload = $this->version->create(
'POST',
$this->uri,
array(),
$data
);
return new CredentialInstance($this->version, $payload);
} | php | public function create($type, $options = array()) {
$options = new Values($options);
$data = Values::of(array(
'Type' => $type,
'FriendlyName' => $options['friendlyName'],
'Certificate' => $options['certificate'],
'PrivateKey' => $options['privateKey'],
'Sandbox' => Serialize::booleanToString($options['sandbox']),
'ApiKey' => $options['apiKey'],
'Secret' => $options['secret'],
));
$payload = $this->version->create(
'POST',
$this->uri,
array(),
$data
);
return new CredentialInstance($this->version, $payload);
} | [
"public",
"function",
"create",
"(",
"$",
"type",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"new",
"Values",
"(",
"$",
"options",
")",
";",
"$",
"data",
"=",
"Values",
"::",
"of",
"(",
"array",
"(",
"'Type'",
"=>",
"$",
"type",
",",
"'FriendlyName'",
"=>",
"$",
"options",
"[",
"'friendlyName'",
"]",
",",
"'Certificate'",
"=>",
"$",
"options",
"[",
"'certificate'",
"]",
",",
"'PrivateKey'",
"=>",
"$",
"options",
"[",
"'privateKey'",
"]",
",",
"'Sandbox'",
"=>",
"Serialize",
"::",
"booleanToString",
"(",
"$",
"options",
"[",
"'sandbox'",
"]",
")",
",",
"'ApiKey'",
"=>",
"$",
"options",
"[",
"'apiKey'",
"]",
",",
"'Secret'",
"=>",
"$",
"options",
"[",
"'secret'",
"]",
",",
")",
")",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"version",
"->",
"create",
"(",
"'POST'",
",",
"$",
"this",
"->",
"uri",
",",
"array",
"(",
")",
",",
"$",
"data",
")",
";",
"return",
"new",
"CredentialInstance",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"payload",
")",
";",
"}"
] | Create a new CredentialInstance
@param string $type Credential type, one of "gcm" or "apn"
@param array|Options $options Optional Arguments
@return CredentialInstance Newly created CredentialInstance
@throws TwilioException When an HTTP error occurs. | [
"Create",
"a",
"new",
"CredentialInstance"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Chat/V1/CredentialList.php#L128-L149 |
twilio/twilio-php | Twilio/Rest/Chat/V2/Service/User/UserChannelList.php | UserChannelList.getContext | public function getContext($channelSid) {
return new UserChannelContext(
$this->version,
$this->solution['serviceSid'],
$this->solution['userSid'],
$channelSid
);
} | php | public function getContext($channelSid) {
return new UserChannelContext(
$this->version,
$this->solution['serviceSid'],
$this->solution['userSid'],
$channelSid
);
} | [
"public",
"function",
"getContext",
"(",
"$",
"channelSid",
")",
"{",
"return",
"new",
"UserChannelContext",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'serviceSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'userSid'",
"]",
",",
"$",
"channelSid",
")",
";",
"}"
] | Constructs a UserChannelContext
@param string $channelSid The SID of the Channel that has the User Channel
to fetch
@return \Twilio\Rest\Chat\V2\Service\User\UserChannelContext | [
"Constructs",
"a",
"UserChannelContext"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Chat/V2/Service/User/UserChannelList.php#L128-L135 |
twilio/twilio-php | Twilio/Rest/Authy/V1/Service/Entity/Factor/ChallengeInstance.php | ChallengeInstance.proxy | protected function proxy() {
if (!$this->context) {
$this->context = new ChallengeContext(
$this->version,
$this->solution['serviceSid'],
$this->solution['identity'],
$this->solution['factorSid'],
$this->solution['sid']
);
}
return $this->context;
} | php | protected function proxy() {
if (!$this->context) {
$this->context = new ChallengeContext(
$this->version,
$this->solution['serviceSid'],
$this->solution['identity'],
$this->solution['factorSid'],
$this->solution['sid']
);
}
return $this->context;
} | [
"protected",
"function",
"proxy",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"context",
")",
"{",
"$",
"this",
"->",
"context",
"=",
"new",
"ChallengeContext",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'serviceSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'identity'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'factorSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'sid'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"context",
";",
"}"
] | Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
@return \Twilio\Rest\Authy\V1\Service\Entity\Factor\ChallengeContext Context
for
this
ChallengeInstance | [
"Generate",
"an",
"instance",
"context",
"for",
"the",
"instance",
"the",
"context",
"is",
"capable",
"of",
"performing",
"various",
"actions",
".",
"All",
"instance",
"actions",
"are",
"proxied",
"to",
"the",
"context"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Authy/V1/Service/Entity/Factor/ChallengeInstance.php#L94-L106 |
twilio/twilio-php | Twilio/Rest/Api/V2010/Account/Sip/CredentialListContext.php | CredentialListContext.getCredentials | protected function getCredentials() {
if (!$this->_credentials) {
$this->_credentials = new CredentialList(
$this->version,
$this->solution['accountSid'],
$this->solution['sid']
);
}
return $this->_credentials;
} | php | protected function getCredentials() {
if (!$this->_credentials) {
$this->_credentials = new CredentialList(
$this->version,
$this->solution['accountSid'],
$this->solution['sid']
);
}
return $this->_credentials;
} | [
"protected",
"function",
"getCredentials",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_credentials",
")",
"{",
"$",
"this",
"->",
"_credentials",
"=",
"new",
"CredentialList",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'accountSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'sid'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_credentials",
";",
"}"
] | Access the credentials
@return \Twilio\Rest\Api\V2010\Account\Sip\CredentialList\CredentialList | [
"Access",
"the",
"credentials"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Api/V2010/Account/Sip/CredentialListContext.php#L106-L116 |
twilio/twilio-php | Twilio/Rest/Trunking/V1/Trunk/PhoneNumberInstance.php | PhoneNumberInstance.proxy | protected function proxy() {
if (!$this->context) {
$this->context = new PhoneNumberContext(
$this->version,
$this->solution['trunkSid'],
$this->solution['sid']
);
}
return $this->context;
} | php | protected function proxy() {
if (!$this->context) {
$this->context = new PhoneNumberContext(
$this->version,
$this->solution['trunkSid'],
$this->solution['sid']
);
}
return $this->context;
} | [
"protected",
"function",
"proxy",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"context",
")",
"{",
"$",
"this",
"->",
"context",
"=",
"new",
"PhoneNumberContext",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'trunkSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'sid'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"context",
";",
"}"
] | Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
@return \Twilio\Rest\Trunking\V1\Trunk\PhoneNumberContext Context for this
PhoneNumberInstance | [
"Generate",
"an",
"instance",
"context",
"for",
"the",
"instance",
"the",
"context",
"is",
"capable",
"of",
"performing",
"various",
"actions",
".",
"All",
"instance",
"actions",
"are",
"proxied",
"to",
"the",
"context"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberInstance.php#L100-L110 |
twilio/twilio-php | Twilio/Rest/Autopilot/V1/AssistantInstance.php | AssistantInstance.proxy | protected function proxy() {
if (!$this->context) {
$this->context = new AssistantContext($this->version, $this->solution['sid']);
}
return $this->context;
} | php | protected function proxy() {
if (!$this->context) {
$this->context = new AssistantContext($this->version, $this->solution['sid']);
}
return $this->context;
} | [
"protected",
"function",
"proxy",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"context",
")",
"{",
"$",
"this",
"->",
"context",
"=",
"new",
"AssistantContext",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'sid'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"context",
";",
"}"
] | Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
@return \Twilio\Rest\Autopilot\V1\AssistantContext Context for this
AssistantInstance | [
"Generate",
"an",
"instance",
"context",
"for",
"the",
"instance",
"the",
"context",
"is",
"capable",
"of",
"performing",
"various",
"actions",
".",
"All",
"instance",
"actions",
"are",
"proxied",
"to",
"the",
"context"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Autopilot/V1/AssistantInstance.php#L81-L87 |
twilio/twilio-php | Twilio/Rest/Chat/V2/Service/UserContext.php | UserContext.getUserBindings | protected function getUserBindings() {
if (!$this->_userBindings) {
$this->_userBindings = new UserBindingList(
$this->version,
$this->solution['serviceSid'],
$this->solution['sid']
);
}
return $this->_userBindings;
} | php | protected function getUserBindings() {
if (!$this->_userBindings) {
$this->_userBindings = new UserBindingList(
$this->version,
$this->solution['serviceSid'],
$this->solution['sid']
);
}
return $this->_userBindings;
} | [
"protected",
"function",
"getUserBindings",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_userBindings",
")",
"{",
"$",
"this",
"->",
"_userBindings",
"=",
"new",
"UserBindingList",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'serviceSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'sid'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_userBindings",
";",
"}"
] | Access the userBindings
@return \Twilio\Rest\Chat\V2\Service\User\UserBindingList | [
"Access",
"the",
"userBindings"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Chat/V2/Service/UserContext.php#L133-L143 |
twilio/twilio-php | Twilio/Rest/Preview/DeployedDevices/Fleet/DeviceInstance.php | DeviceInstance.proxy | protected function proxy() {
if (!$this->context) {
$this->context = new DeviceContext(
$this->version,
$this->solution['fleetSid'],
$this->solution['sid']
);
}
return $this->context;
} | php | protected function proxy() {
if (!$this->context) {
$this->context = new DeviceContext(
$this->version,
$this->solution['fleetSid'],
$this->solution['sid']
);
}
return $this->context;
} | [
"protected",
"function",
"proxy",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"context",
")",
"{",
"$",
"this",
"->",
"context",
"=",
"new",
"DeviceContext",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'fleetSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'sid'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"context",
";",
"}"
] | Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
@return \Twilio\Rest\Preview\DeployedDevices\Fleet\DeviceContext Context for
this
DeviceInstance | [
"Generate",
"an",
"instance",
"context",
"for",
"the",
"instance",
"the",
"context",
"is",
"capable",
"of",
"performing",
"various",
"actions",
".",
"All",
"instance",
"actions",
"are",
"proxied",
"to",
"the",
"context"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Preview/DeployedDevices/Fleet/DeviceInstance.php#L75-L85 |
twilio/twilio-php | Twilio/Rest/Api/V2010/Account/Call/NotificationList.php | NotificationList.getContext | public function getContext($sid) {
return new NotificationContext(
$this->version,
$this->solution['accountSid'],
$this->solution['callSid'],
$sid
);
} | php | public function getContext($sid) {
return new NotificationContext(
$this->version,
$this->solution['accountSid'],
$this->solution['callSid'],
$sid
);
} | [
"public",
"function",
"getContext",
"(",
"$",
"sid",
")",
"{",
"return",
"new",
"NotificationContext",
"(",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"solution",
"[",
"'accountSid'",
"]",
",",
"$",
"this",
"->",
"solution",
"[",
"'callSid'",
"]",
",",
"$",
"sid",
")",
";",
"}"
] | Constructs a NotificationContext
@param string $sid The unique string that identifies the resource
@return \Twilio\Rest\Api\V2010\Account\Call\NotificationContext | [
"Constructs",
"a",
"NotificationContext"
] | train | https://github.com/twilio/twilio-php/blob/58a8322c5a8ce2ff7d68cd16ff56dc8ab44c168f/Twilio/Rest/Api/V2010/Account/Call/NotificationList.php#L136-L143 |
cybercog/laravel-love | src/Reactant/Listeners/IncrementAggregates.php | IncrementAggregates.handle | public function handle(ReactionHasBeenAdded $event): void
{
$reaction = $event->getReaction();
$reactant = $reaction->getReactant();
(new ReactionCounterService($reactant))
->addReaction($reaction);
(new ReactionTotalService($reactant))
->addReaction($reaction);
} | php | public function handle(ReactionHasBeenAdded $event): void
{
$reaction = $event->getReaction();
$reactant = $reaction->getReactant();
(new ReactionCounterService($reactant))
->addReaction($reaction);
(new ReactionTotalService($reactant))
->addReaction($reaction);
} | [
"public",
"function",
"handle",
"(",
"ReactionHasBeenAdded",
"$",
"event",
")",
":",
"void",
"{",
"$",
"reaction",
"=",
"$",
"event",
"->",
"getReaction",
"(",
")",
";",
"$",
"reactant",
"=",
"$",
"reaction",
"->",
"getReactant",
"(",
")",
";",
"(",
"new",
"ReactionCounterService",
"(",
"$",
"reactant",
")",
")",
"->",
"addReaction",
"(",
"$",
"reaction",
")",
";",
"(",
"new",
"ReactionTotalService",
"(",
"$",
"reactant",
")",
")",
"->",
"addReaction",
"(",
"$",
"reaction",
")",
";",
"}"
] | Handle the event.
@param \Cog\Laravel\Love\Reaction\Events\ReactionHasBeenAdded $event
@return void | [
"Handle",
"the",
"event",
"."
] | train | https://github.com/cybercog/laravel-love/blob/115cf188f9ee308569fd779ca61c365f421c01ad/src/Reactant/Listeners/IncrementAggregates.php#L29-L39 |
cybercog/laravel-love | src/Reactant/Listeners/DecrementAggregates.php | DecrementAggregates.handle | public function handle(ReactionHasBeenRemoved $event): void
{
$reaction = $event->getReaction();
$reactant = $reaction->getReactant();
(new ReactionCounterService($reactant))
->removeReaction($reaction);
(new ReactionTotalService($reactant))
->removeReaction($reaction);
} | php | public function handle(ReactionHasBeenRemoved $event): void
{
$reaction = $event->getReaction();
$reactant = $reaction->getReactant();
(new ReactionCounterService($reactant))
->removeReaction($reaction);
(new ReactionTotalService($reactant))
->removeReaction($reaction);
} | [
"public",
"function",
"handle",
"(",
"ReactionHasBeenRemoved",
"$",
"event",
")",
":",
"void",
"{",
"$",
"reaction",
"=",
"$",
"event",
"->",
"getReaction",
"(",
")",
";",
"$",
"reactant",
"=",
"$",
"reaction",
"->",
"getReactant",
"(",
")",
";",
"(",
"new",
"ReactionCounterService",
"(",
"$",
"reactant",
")",
")",
"->",
"removeReaction",
"(",
"$",
"reaction",
")",
";",
"(",
"new",
"ReactionTotalService",
"(",
"$",
"reactant",
")",
")",
"->",
"removeReaction",
"(",
"$",
"reaction",
")",
";",
"}"
] | Handle the event.
@param \Cog\Laravel\Love\Reaction\Events\ReactionHasBeenRemoved $event
@return void | [
"Handle",
"the",
"event",
"."
] | train | https://github.com/cybercog/laravel-love/blob/115cf188f9ee308569fd779ca61c365f421c01ad/src/Reactant/Listeners/DecrementAggregates.php#L29-L39 |
cybercog/laravel-love | src/Console/Commands/UpgradeV5ToV6.php | UpgradeV5ToV6.handle | public function handle(): void
{
$this->dbMigrate();
$this->populateReactionTypes();
$this->populateReacters();
$this->populateReactants();
$this->populateReactions();
$this->dbCleanup();
$this->filesystemCleanup();
} | php | public function handle(): void
{
$this->dbMigrate();
$this->populateReactionTypes();
$this->populateReacters();
$this->populateReactants();
$this->populateReactions();
$this->dbCleanup();
$this->filesystemCleanup();
} | [
"public",
"function",
"handle",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"dbMigrate",
"(",
")",
";",
"$",
"this",
"->",
"populateReactionTypes",
"(",
")",
";",
"$",
"this",
"->",
"populateReacters",
"(",
")",
";",
"$",
"this",
"->",
"populateReactants",
"(",
")",
";",
"$",
"this",
"->",
"populateReactions",
"(",
")",
";",
"$",
"this",
"->",
"dbCleanup",
"(",
")",
";",
"$",
"this",
"->",
"filesystemCleanup",
"(",
")",
";",
"}"
] | Execute the console command.
@return void | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/cybercog/laravel-love/blob/115cf188f9ee308569fd779ca61c365f421c01ad/src/Console/Commands/UpgradeV5ToV6.php#L46-L55 |
cybercog/laravel-love | src/Console/Commands/Recount.php | Recount.handle | public function handle(
Dispatcher $events
): void {
if ($reactableType = $this->argument('reactableType')) {
$reactableType = $this->normalizeReactableModelType($reactableType);
}
if ($reactionType = $this->argument('type')) {
$reactionType = ReactionType::fromName($reactionType);
}
$reactantsQuery = Reactant::query();
if ($reactableType) {
$reactantsQuery->where('type', $reactableType);
}
$reactants = $reactantsQuery->get();
foreach ($reactants as $reactant) {
/** @var \Illuminate\Database\Eloquent\Builder $query */
$query = $reactant->reactions();
if ($reactionType) {
$query->where('reaction_type_id', $reactionType->getId());
}
$counters = $reactant->getReactionCounters();
/** @var \Cog\Laravel\Love\Reactant\ReactionCounter\Models\ReactionCounter $counter */
foreach ($counters as $counter) {
if ($reactionType && !$counter->isReactionOfType($reactionType)) {
continue;
}
$counter->update([
'count' => 0,
'weight' => 0,
]);
}
$reactions = $query->get();
$this->recountCounters($reactant, $reactions);
$this->recountTotal($reactant);
}
} | php | public function handle(
Dispatcher $events
): void {
if ($reactableType = $this->argument('reactableType')) {
$reactableType = $this->normalizeReactableModelType($reactableType);
}
if ($reactionType = $this->argument('type')) {
$reactionType = ReactionType::fromName($reactionType);
}
$reactantsQuery = Reactant::query();
if ($reactableType) {
$reactantsQuery->where('type', $reactableType);
}
$reactants = $reactantsQuery->get();
foreach ($reactants as $reactant) {
$query = $reactant->reactions();
if ($reactionType) {
$query->where('reaction_type_id', $reactionType->getId());
}
$counters = $reactant->getReactionCounters();
foreach ($counters as $counter) {
if ($reactionType && !$counter->isReactionOfType($reactionType)) {
continue;
}
$counter->update([
'count' => 0,
'weight' => 0,
]);
}
$reactions = $query->get();
$this->recountCounters($reactant, $reactions);
$this->recountTotal($reactant);
}
} | [
"public",
"function",
"handle",
"(",
"Dispatcher",
"$",
"events",
")",
":",
"void",
"{",
"if",
"(",
"$",
"reactableType",
"=",
"$",
"this",
"->",
"argument",
"(",
"'reactableType'",
")",
")",
"{",
"$",
"reactableType",
"=",
"$",
"this",
"->",
"normalizeReactableModelType",
"(",
"$",
"reactableType",
")",
";",
"}",
"if",
"(",
"$",
"reactionType",
"=",
"$",
"this",
"->",
"argument",
"(",
"'type'",
")",
")",
"{",
"$",
"reactionType",
"=",
"ReactionType",
"::",
"fromName",
"(",
"$",
"reactionType",
")",
";",
"}",
"$",
"reactantsQuery",
"=",
"Reactant",
"::",
"query",
"(",
")",
";",
"if",
"(",
"$",
"reactableType",
")",
"{",
"$",
"reactantsQuery",
"->",
"where",
"(",
"'type'",
",",
"$",
"reactableType",
")",
";",
"}",
"$",
"reactants",
"=",
"$",
"reactantsQuery",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"reactants",
"as",
"$",
"reactant",
")",
"{",
"/** @var \\Illuminate\\Database\\Eloquent\\Builder $query */",
"$",
"query",
"=",
"$",
"reactant",
"->",
"reactions",
"(",
")",
";",
"if",
"(",
"$",
"reactionType",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'reaction_type_id'",
",",
"$",
"reactionType",
"->",
"getId",
"(",
")",
")",
";",
"}",
"$",
"counters",
"=",
"$",
"reactant",
"->",
"getReactionCounters",
"(",
")",
";",
"/** @var \\Cog\\Laravel\\Love\\Reactant\\ReactionCounter\\Models\\ReactionCounter $counter */",
"foreach",
"(",
"$",
"counters",
"as",
"$",
"counter",
")",
"{",
"if",
"(",
"$",
"reactionType",
"&&",
"!",
"$",
"counter",
"->",
"isReactionOfType",
"(",
"$",
"reactionType",
")",
")",
"{",
"continue",
";",
"}",
"$",
"counter",
"->",
"update",
"(",
"[",
"'count'",
"=>",
"0",
",",
"'weight'",
"=>",
"0",
",",
"]",
")",
";",
"}",
"$",
"reactions",
"=",
"$",
"query",
"->",
"get",
"(",
")",
";",
"$",
"this",
"->",
"recountCounters",
"(",
"$",
"reactant",
",",
"$",
"reactions",
")",
";",
"$",
"this",
"->",
"recountTotal",
"(",
"$",
"reactant",
")",
";",
"}",
"}"
] | Execute the console command.
@param \Illuminate\Contracts\Events\Dispatcher $events
@return void
@throws \Cog\Contracts\Love\Reactable\Exceptions\ReactableInvalid | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/cybercog/laravel-love/blob/115cf188f9ee308569fd779ca61c365f421c01ad/src/Console/Commands/Recount.php#L50-L94 |
cybercog/laravel-love | src/Console/Commands/Recount.php | Recount.reactableModelFromType | private function reactableModelFromType(
string $modelType
): ReactableContract {
if (!class_exists($modelType)) {
$modelType = $this->findModelTypeInMorphMap($modelType);
}
$model = new $modelType;
if (!$model instanceof ReactableContract) {
throw ReactableInvalid::notImplementInterface($modelType);
}
return $model;
} | php | private function reactableModelFromType(
string $modelType
): ReactableContract {
if (!class_exists($modelType)) {
$modelType = $this->findModelTypeInMorphMap($modelType);
}
$model = new $modelType;
if (!$model instanceof ReactableContract) {
throw ReactableInvalid::notImplementInterface($modelType);
}
return $model;
} | [
"private",
"function",
"reactableModelFromType",
"(",
"string",
"$",
"modelType",
")",
":",
"ReactableContract",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"modelType",
")",
")",
"{",
"$",
"modelType",
"=",
"$",
"this",
"->",
"findModelTypeInMorphMap",
"(",
"$",
"modelType",
")",
";",
"}",
"$",
"model",
"=",
"new",
"$",
"modelType",
";",
"if",
"(",
"!",
"$",
"model",
"instanceof",
"ReactableContract",
")",
"{",
"throw",
"ReactableInvalid",
"::",
"notImplementInterface",
"(",
"$",
"modelType",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] | Instantiate model from type or morph map value.
@param string $modelType
@return \Cog\Contracts\Love\Reactable\Models\Reactable|\Illuminate\Database\Eloquent\Model
@throws \Cog\Contracts\Love\Reactable\Exceptions\ReactableInvalid | [
"Instantiate",
"model",
"from",
"type",
"or",
"morph",
"map",
"value",
"."
] | train | https://github.com/cybercog/laravel-love/blob/115cf188f9ee308569fd779ca61c365f421c01ad/src/Console/Commands/Recount.php#L120-L134 |
cybercog/laravel-love | src/Console/Commands/Recount.php | Recount.findModelTypeInMorphMap | private function findModelTypeInMorphMap(
string $modelType
): string {
$morphMap = Relation::morphMap();
if (!isset($morphMap[$modelType])) {
throw ReactableInvalid::classNotExists($modelType);
}
return $morphMap[$modelType];
} | php | private function findModelTypeInMorphMap(
string $modelType
): string {
$morphMap = Relation::morphMap();
if (!isset($morphMap[$modelType])) {
throw ReactableInvalid::classNotExists($modelType);
}
return $morphMap[$modelType];
} | [
"private",
"function",
"findModelTypeInMorphMap",
"(",
"string",
"$",
"modelType",
")",
":",
"string",
"{",
"$",
"morphMap",
"=",
"Relation",
"::",
"morphMap",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"morphMap",
"[",
"$",
"modelType",
"]",
")",
")",
"{",
"throw",
"ReactableInvalid",
"::",
"classNotExists",
"(",
"$",
"modelType",
")",
";",
"}",
"return",
"$",
"morphMap",
"[",
"$",
"modelType",
"]",
";",
"}"
] | Find model type in morph mappings registry.
@param string $modelType
@return string
@throws \Cog\Contracts\Love\Reactable\Exceptions\ReactableInvalid | [
"Find",
"model",
"type",
"in",
"morph",
"mappings",
"registry",
"."
] | train | https://github.com/cybercog/laravel-love/blob/115cf188f9ee308569fd779ca61c365f421c01ad/src/Console/Commands/Recount.php#L144-L154 |
cybercog/laravel-love | src/LoveServiceProvider.php | LoveServiceProvider.boot | public function boot(): void
{
$this->registerConsoleCommands();
$this->registerObservers();
$this->registerPublishes();
$this->registerMigrations();
$this->registerListeners();
} | php | public function boot(): void
{
$this->registerConsoleCommands();
$this->registerObservers();
$this->registerPublishes();
$this->registerMigrations();
$this->registerListeners();
} | [
"public",
"function",
"boot",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"registerConsoleCommands",
"(",
")",
";",
"$",
"this",
"->",
"registerObservers",
"(",
")",
";",
"$",
"this",
"->",
"registerPublishes",
"(",
")",
";",
"$",
"this",
"->",
"registerMigrations",
"(",
")",
";",
"$",
"this",
"->",
"registerListeners",
"(",
")",
";",
"}"
] | Bootstrap the application events.
@return void | [
"Bootstrap",
"the",
"application",
"events",
"."
] | train | https://github.com/cybercog/laravel-love/blob/115cf188f9ee308569fd779ca61c365f421c01ad/src/LoveServiceProvider.php#L43-L50 |
cybercog/laravel-love | src/LoveServiceProvider.php | LoveServiceProvider.registerListeners | private function registerListeners(): void
{
Event::listen(ReactionHasBeenAdded::class, IncrementAggregates::class);
Event::listen(ReactionHasBeenRemoved::class, DecrementAggregates::class);
} | php | private function registerListeners(): void
{
Event::listen(ReactionHasBeenAdded::class, IncrementAggregates::class);
Event::listen(ReactionHasBeenRemoved::class, DecrementAggregates::class);
} | [
"private",
"function",
"registerListeners",
"(",
")",
":",
"void",
"{",
"Event",
"::",
"listen",
"(",
"ReactionHasBeenAdded",
"::",
"class",
",",
"IncrementAggregates",
"::",
"class",
")",
";",
"Event",
"::",
"listen",
"(",
"ReactionHasBeenRemoved",
"::",
"class",
",",
"DecrementAggregates",
"::",
"class",
")",
";",
"}"
] | Register the Love event listeners.
@return void | [
"Register",
"the",
"Love",
"event",
"listeners",
"."
] | train | https://github.com/cybercog/laravel-love/blob/115cf188f9ee308569fd779ca61c365f421c01ad/src/LoveServiceProvider.php#L108-L112 |
bobthecow/psysh | src/Readline/Transient.php | Transient.addHistory | public function addHistory($line)
{
if ($this->eraseDups) {
if (($key = \array_search($line, $this->history)) !== false) {
unset($this->history[$key]);
}
}
$this->history[] = $line;
if ($this->historySize > 0) {
$histsize = \count($this->history);
if ($histsize > $this->historySize) {
$this->history = \array_slice($this->history, $histsize - $this->historySize);
}
}
$this->history = \array_values($this->history);
return true;
} | php | public function addHistory($line)
{
if ($this->eraseDups) {
if (($key = \array_search($line, $this->history)) !== false) {
unset($this->history[$key]);
}
}
$this->history[] = $line;
if ($this->historySize > 0) {
$histsize = \count($this->history);
if ($histsize > $this->historySize) {
$this->history = \array_slice($this->history, $histsize - $this->historySize);
}
}
$this->history = \array_values($this->history);
return true;
} | [
"public",
"function",
"addHistory",
"(",
"$",
"line",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"eraseDups",
")",
"{",
"if",
"(",
"(",
"$",
"key",
"=",
"\\",
"array_search",
"(",
"$",
"line",
",",
"$",
"this",
"->",
"history",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"history",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"history",
"[",
"]",
"=",
"$",
"line",
";",
"if",
"(",
"$",
"this",
"->",
"historySize",
">",
"0",
")",
"{",
"$",
"histsize",
"=",
"\\",
"count",
"(",
"$",
"this",
"->",
"history",
")",
";",
"if",
"(",
"$",
"histsize",
">",
"$",
"this",
"->",
"historySize",
")",
"{",
"$",
"this",
"->",
"history",
"=",
"\\",
"array_slice",
"(",
"$",
"this",
"->",
"history",
",",
"$",
"histsize",
"-",
"$",
"this",
"->",
"historySize",
")",
";",
"}",
"}",
"$",
"this",
"->",
"history",
"=",
"\\",
"array_values",
"(",
"$",
"this",
"->",
"history",
")",
";",
"return",
"true",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Readline/Transient.php#L50-L70 |
bobthecow/psysh | src/Readline/Transient.php | Transient.getStdin | private function getStdin()
{
if (!isset($this->stdin)) {
$this->stdin = \fopen('php://stdin', 'r');
}
if (\feof($this->stdin)) {
throw new BreakException('Ctrl+D');
}
return $this->stdin;
} | php | private function getStdin()
{
if (!isset($this->stdin)) {
$this->stdin = \fopen('php:
}
if (\feof($this->stdin)) {
throw new BreakException('Ctrl+D');
}
return $this->stdin;
} | [
"private",
"function",
"getStdin",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"stdin",
")",
")",
"{",
"$",
"this",
"->",
"stdin",
"=",
"\\",
"fopen",
"(",
"'php://stdin'",
",",
"'r'",
")",
";",
"}",
"if",
"(",
"\\",
"feof",
"(",
"$",
"this",
"->",
"stdin",
")",
")",
"{",
"throw",
"new",
"BreakException",
"(",
"'Ctrl+D'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"stdin",
";",
"}"
] | Get a STDIN file handle.
@throws BreakException if user hits Ctrl+D
@return resource | [
"Get",
"a",
"STDIN",
"file",
"handle",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Readline/Transient.php#L135-L146 |
bobthecow/psysh | src/TabCompletion/Matcher/VariablesMatcher.php | VariablesMatcher.getMatches | public function getMatches(array $tokens, array $info = [])
{
$var = \str_replace('$', '', $this->getInput($tokens));
return \array_filter(\array_keys($this->getVariables()), function ($variable) use ($var) {
return AbstractMatcher::startsWith($var, $variable);
});
} | php | public function getMatches(array $tokens, array $info = [])
{
$var = \str_replace('$', '', $this->getInput($tokens));
return \array_filter(\array_keys($this->getVariables()), function ($variable) use ($var) {
return AbstractMatcher::startsWith($var, $variable);
});
} | [
"public",
"function",
"getMatches",
"(",
"array",
"$",
"tokens",
",",
"array",
"$",
"info",
"=",
"[",
"]",
")",
"{",
"$",
"var",
"=",
"\\",
"str_replace",
"(",
"'$'",
",",
"''",
",",
"$",
"this",
"->",
"getInput",
"(",
"$",
"tokens",
")",
")",
";",
"return",
"\\",
"array_filter",
"(",
"\\",
"array_keys",
"(",
"$",
"this",
"->",
"getVariables",
"(",
")",
")",
",",
"function",
"(",
"$",
"variable",
")",
"use",
"(",
"$",
"var",
")",
"{",
"return",
"AbstractMatcher",
"::",
"startsWith",
"(",
"$",
"var",
",",
"$",
"variable",
")",
";",
"}",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/VariablesMatcher.php#L26-L33 |
bobthecow/psysh | src/TabCompletion/Matcher/VariablesMatcher.php | VariablesMatcher.hasMatched | public function hasMatched(array $tokens)
{
$token = \array_pop($tokens);
switch (true) {
case self::hasToken([self::T_OPEN_TAG, self::T_VARIABLE], $token):
case \is_string($token) && $token === '$':
case self::isOperator($token):
return true;
}
return false;
} | php | public function hasMatched(array $tokens)
{
$token = \array_pop($tokens);
switch (true) {
case self::hasToken([self::T_OPEN_TAG, self::T_VARIABLE], $token):
case \is_string($token) && $token === '$':
case self::isOperator($token):
return true;
}
return false;
} | [
"public",
"function",
"hasMatched",
"(",
"array",
"$",
"tokens",
")",
"{",
"$",
"token",
"=",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"self",
"::",
"hasToken",
"(",
"[",
"self",
"::",
"T_OPEN_TAG",
",",
"self",
"::",
"T_VARIABLE",
"]",
",",
"$",
"token",
")",
":",
"case",
"\\",
"is_string",
"(",
"$",
"token",
")",
"&&",
"$",
"token",
"===",
"'$'",
":",
"case",
"self",
"::",
"isOperator",
"(",
"$",
"token",
")",
":",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/VariablesMatcher.php#L38-L50 |
bobthecow/psysh | src/TabCompletion/Matcher/MongoDatabaseMatcher.php | MongoDatabaseMatcher.getMatches | public function getMatches(array $tokens, array $info = [])
{
$input = $this->getInput($tokens);
$firstToken = \array_pop($tokens);
if (self::tokenIs($firstToken, self::T_STRING)) {
// second token is the object operator
\array_pop($tokens);
}
$objectToken = \array_pop($tokens);
$objectName = \str_replace('$', '', $objectToken[1]);
$object = $this->getVariable($objectName);
if (!$object instanceof \MongoDB) {
return [];
}
return \array_filter(
$object->getCollectionNames(),
function ($var) use ($input) {
return AbstractMatcher::startsWith($input, $var);
}
);
} | php | public function getMatches(array $tokens, array $info = [])
{
$input = $this->getInput($tokens);
$firstToken = \array_pop($tokens);
if (self::tokenIs($firstToken, self::T_STRING)) {
\array_pop($tokens);
}
$objectToken = \array_pop($tokens);
$objectName = \str_replace('$', '', $objectToken[1]);
$object = $this->getVariable($objectName);
if (!$object instanceof \MongoDB) {
return [];
}
return \array_filter(
$object->getCollectionNames(),
function ($var) use ($input) {
return AbstractMatcher::startsWith($input, $var);
}
);
} | [
"public",
"function",
"getMatches",
"(",
"array",
"$",
"tokens",
",",
"array",
"$",
"info",
"=",
"[",
"]",
")",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"getInput",
"(",
"$",
"tokens",
")",
";",
"$",
"firstToken",
"=",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"if",
"(",
"self",
"::",
"tokenIs",
"(",
"$",
"firstToken",
",",
"self",
"::",
"T_STRING",
")",
")",
"{",
"// second token is the object operator",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"}",
"$",
"objectToken",
"=",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"$",
"objectName",
"=",
"\\",
"str_replace",
"(",
"'$'",
",",
"''",
",",
"$",
"objectToken",
"[",
"1",
"]",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getVariable",
"(",
"$",
"objectName",
")",
";",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"\\",
"MongoDB",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"\\",
"array_filter",
"(",
"$",
"object",
"->",
"getCollectionNames",
"(",
")",
",",
"function",
"(",
"$",
"var",
")",
"use",
"(",
"$",
"input",
")",
"{",
"return",
"AbstractMatcher",
"::",
"startsWith",
"(",
"$",
"input",
",",
"$",
"var",
")",
";",
"}",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/MongoDatabaseMatcher.php#L26-L49 |
bobthecow/psysh | src/TabCompletion/Matcher/MongoDatabaseMatcher.php | MongoDatabaseMatcher.hasMatched | public function hasMatched(array $tokens)
{
$token = \array_pop($tokens);
$prevToken = \array_pop($tokens);
switch (true) {
case self::tokenIs($token, self::T_OBJECT_OPERATOR):
case self::tokenIs($prevToken, self::T_OBJECT_OPERATOR):
return true;
}
return false;
} | php | public function hasMatched(array $tokens)
{
$token = \array_pop($tokens);
$prevToken = \array_pop($tokens);
switch (true) {
case self::tokenIs($token, self::T_OBJECT_OPERATOR):
case self::tokenIs($prevToken, self::T_OBJECT_OPERATOR):
return true;
}
return false;
} | [
"public",
"function",
"hasMatched",
"(",
"array",
"$",
"tokens",
")",
"{",
"$",
"token",
"=",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"$",
"prevToken",
"=",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"self",
"::",
"tokenIs",
"(",
"$",
"token",
",",
"self",
"::",
"T_OBJECT_OPERATOR",
")",
":",
"case",
"self",
"::",
"tokenIs",
"(",
"$",
"prevToken",
",",
"self",
"::",
"T_OBJECT_OPERATOR",
")",
":",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/MongoDatabaseMatcher.php#L54-L66 |
bobthecow/psysh | src/Command/ListCommand/ConstantEnumerator.php | ConstantEnumerator.listItems | protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
{
// only list constants when no Reflector is present.
//
// @todo make a NamespaceReflector and pass that in for commands like:
//
// ls --constants Foo
//
// ... for listing constants in the Foo namespace
if ($reflector !== null || $target !== null) {
return;
}
// only list constants if we are specifically asked
if (!$input->getOption('constants')) {
return;
}
$user = $input->getOption('user');
$internal = $input->getOption('internal');
$category = $input->getOption('category');
$ret = [];
if ($user) {
$ret['User Constants'] = $this->getConstants('user');
}
if ($internal) {
$ret['Interal Constants'] = $this->getConstants('internal');
}
if ($category) {
$label = \ucfirst($category) . ' Constants';
$ret[$label] = $this->getConstants($category);
}
if (!$user && !$internal && !$category) {
$ret['Constants'] = $this->getConstants();
}
return \array_map([$this, 'prepareConstants'], \array_filter($ret));
} | php | protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
{
if ($reflector !== null || $target !== null) {
return;
}
if (!$input->getOption('constants')) {
return;
}
$user = $input->getOption('user');
$internal = $input->getOption('internal');
$category = $input->getOption('category');
$ret = [];
if ($user) {
$ret['User Constants'] = $this->getConstants('user');
}
if ($internal) {
$ret['Interal Constants'] = $this->getConstants('internal');
}
if ($category) {
$label = \ucfirst($category) . ' Constants';
$ret[$label] = $this->getConstants($category);
}
if (!$user && !$internal && !$category) {
$ret['Constants'] = $this->getConstants();
}
return \array_map([$this, 'prepareConstants'], \array_filter($ret));
} | [
"protected",
"function",
"listItems",
"(",
"InputInterface",
"$",
"input",
",",
"\\",
"Reflector",
"$",
"reflector",
"=",
"null",
",",
"$",
"target",
"=",
"null",
")",
"{",
"// only list constants when no Reflector is present.",
"//",
"// @todo make a NamespaceReflector and pass that in for commands like:",
"//",
"// ls --constants Foo",
"//",
"// ... for listing constants in the Foo namespace",
"if",
"(",
"$",
"reflector",
"!==",
"null",
"||",
"$",
"target",
"!==",
"null",
")",
"{",
"return",
";",
"}",
"// only list constants if we are specifically asked",
"if",
"(",
"!",
"$",
"input",
"->",
"getOption",
"(",
"'constants'",
")",
")",
"{",
"return",
";",
"}",
"$",
"user",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'user'",
")",
";",
"$",
"internal",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'internal'",
")",
";",
"$",
"category",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'category'",
")",
";",
"$",
"ret",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"ret",
"[",
"'User Constants'",
"]",
"=",
"$",
"this",
"->",
"getConstants",
"(",
"'user'",
")",
";",
"}",
"if",
"(",
"$",
"internal",
")",
"{",
"$",
"ret",
"[",
"'Interal Constants'",
"]",
"=",
"$",
"this",
"->",
"getConstants",
"(",
"'internal'",
")",
";",
"}",
"if",
"(",
"$",
"category",
")",
"{",
"$",
"label",
"=",
"\\",
"ucfirst",
"(",
"$",
"category",
")",
".",
"' Constants'",
";",
"$",
"ret",
"[",
"$",
"label",
"]",
"=",
"$",
"this",
"->",
"getConstants",
"(",
"$",
"category",
")",
";",
"}",
"if",
"(",
"!",
"$",
"user",
"&&",
"!",
"$",
"internal",
"&&",
"!",
"$",
"category",
")",
"{",
"$",
"ret",
"[",
"'Constants'",
"]",
"=",
"$",
"this",
"->",
"getConstants",
"(",
")",
";",
"}",
"return",
"\\",
"array_map",
"(",
"[",
"$",
"this",
",",
"'prepareConstants'",
"]",
",",
"\\",
"array_filter",
"(",
"$",
"ret",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ListCommand/ConstantEnumerator.php#L24-L66 |
bobthecow/psysh | src/Command/ListCommand/ConstantEnumerator.php | ConstantEnumerator.getConstants | protected function getConstants($category = null)
{
if (!$category) {
return \get_defined_constants();
}
$consts = \get_defined_constants(true);
if ($category === 'internal') {
unset($consts['user']);
return \call_user_func_array('array_merge', $consts);
}
return isset($consts[$category]) ? $consts[$category] : [];
} | php | protected function getConstants($category = null)
{
if (!$category) {
return \get_defined_constants();
}
$consts = \get_defined_constants(true);
if ($category === 'internal') {
unset($consts['user']);
return \call_user_func_array('array_merge', $consts);
}
return isset($consts[$category]) ? $consts[$category] : [];
} | [
"protected",
"function",
"getConstants",
"(",
"$",
"category",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"category",
")",
"{",
"return",
"\\",
"get_defined_constants",
"(",
")",
";",
"}",
"$",
"consts",
"=",
"\\",
"get_defined_constants",
"(",
"true",
")",
";",
"if",
"(",
"$",
"category",
"===",
"'internal'",
")",
"{",
"unset",
"(",
"$",
"consts",
"[",
"'user'",
"]",
")",
";",
"return",
"\\",
"call_user_func_array",
"(",
"'array_merge'",
",",
"$",
"consts",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"consts",
"[",
"$",
"category",
"]",
")",
"?",
"$",
"consts",
"[",
"$",
"category",
"]",
":",
"[",
"]",
";",
"}"
] | Get defined constants.
Optionally restrict constants to a given category, e.g. "date". If the
category is "internal", include all non-user-defined constants.
@param string $category
@return array | [
"Get",
"defined",
"constants",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ListCommand/ConstantEnumerator.php#L78-L93 |
bobthecow/psysh | src/Command/ListCommand/ConstantEnumerator.php | ConstantEnumerator.prepareConstants | protected function prepareConstants(array $constants)
{
// My kingdom for a generator.
$ret = [];
$names = \array_keys($constants);
\natcasesort($names);
foreach ($names as $name) {
if ($this->showItem($name)) {
$ret[$name] = [
'name' => $name,
'style' => self::IS_CONSTANT,
'value' => $this->presentRef($constants[$name]),
];
}
}
return $ret;
} | php | protected function prepareConstants(array $constants)
{
$ret = [];
$names = \array_keys($constants);
\natcasesort($names);
foreach ($names as $name) {
if ($this->showItem($name)) {
$ret[$name] = [
'name' => $name,
'style' => self::IS_CONSTANT,
'value' => $this->presentRef($constants[$name]),
];
}
}
return $ret;
} | [
"protected",
"function",
"prepareConstants",
"(",
"array",
"$",
"constants",
")",
"{",
"// My kingdom for a generator.",
"$",
"ret",
"=",
"[",
"]",
";",
"$",
"names",
"=",
"\\",
"array_keys",
"(",
"$",
"constants",
")",
";",
"\\",
"natcasesort",
"(",
"$",
"names",
")",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"showItem",
"(",
"$",
"name",
")",
")",
"{",
"$",
"ret",
"[",
"$",
"name",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'style'",
"=>",
"self",
"::",
"IS_CONSTANT",
",",
"'value'",
"=>",
"$",
"this",
"->",
"presentRef",
"(",
"$",
"constants",
"[",
"$",
"name",
"]",
")",
",",
"]",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Prepare formatted constant array.
@param array $constants
@return array | [
"Prepare",
"formatted",
"constant",
"array",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ListCommand/ConstantEnumerator.php#L102-L121 |
bobthecow/psysh | src/ExecutionLoop/RunkitReloader.php | RunkitReloader.reload | private function reload(Shell $shell)
{
\clearstatcache();
$modified = [];
foreach (\get_included_files() as $file) {
$timestamp = \filemtime($file);
if (!isset($this->timestamps[$file])) {
$this->timestamps[$file] = $timestamp;
continue;
}
if ($this->timestamps[$file] === $timestamp) {
continue;
}
if (!$this->lintFile($file)) {
$msg = \sprintf('Modified file "%s" could not be reloaded', $file);
$shell->writeException(new ParseErrorException($msg));
continue;
}
$modified[] = $file;
$this->timestamps[$file] = $timestamp;
}
// switch (count($modified)) {
// case 0:
// return;
// case 1:
// printf("Reloading modified file: \"%s\"\n", str_replace(getcwd(), '.', $file));
// break;
// default:
// printf("Reloading %d modified files\n", count($modified));
// break;
// }
foreach ($modified as $file) {
runkit_import($file, (
RUNKIT_IMPORT_FUNCTIONS |
RUNKIT_IMPORT_CLASSES |
RUNKIT_IMPORT_CLASS_METHODS |
RUNKIT_IMPORT_CLASS_CONSTS |
RUNKIT_IMPORT_CLASS_PROPS |
RUNKIT_IMPORT_OVERRIDE
));
}
} | php | private function reload(Shell $shell)
{
\clearstatcache();
$modified = [];
foreach (\get_included_files() as $file) {
$timestamp = \filemtime($file);
if (!isset($this->timestamps[$file])) {
$this->timestamps[$file] = $timestamp;
continue;
}
if ($this->timestamps[$file] === $timestamp) {
continue;
}
if (!$this->lintFile($file)) {
$msg = \sprintf('Modified file "%s" could not be reloaded', $file);
$shell->writeException(new ParseErrorException($msg));
continue;
}
$modified[] = $file;
$this->timestamps[$file] = $timestamp;
}
foreach ($modified as $file) {
runkit_import($file, (
RUNKIT_IMPORT_FUNCTIONS |
RUNKIT_IMPORT_CLASSES |
RUNKIT_IMPORT_CLASS_METHODS |
RUNKIT_IMPORT_CLASS_CONSTS |
RUNKIT_IMPORT_CLASS_PROPS |
RUNKIT_IMPORT_OVERRIDE
));
}
} | [
"private",
"function",
"reload",
"(",
"Shell",
"$",
"shell",
")",
"{",
"\\",
"clearstatcache",
"(",
")",
";",
"$",
"modified",
"=",
"[",
"]",
";",
"foreach",
"(",
"\\",
"get_included_files",
"(",
")",
"as",
"$",
"file",
")",
"{",
"$",
"timestamp",
"=",
"\\",
"filemtime",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"timestamps",
"[",
"$",
"file",
"]",
")",
")",
"{",
"$",
"this",
"->",
"timestamps",
"[",
"$",
"file",
"]",
"=",
"$",
"timestamp",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"timestamps",
"[",
"$",
"file",
"]",
"===",
"$",
"timestamp",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"lintFile",
"(",
"$",
"file",
")",
")",
"{",
"$",
"msg",
"=",
"\\",
"sprintf",
"(",
"'Modified file \"%s\" could not be reloaded'",
",",
"$",
"file",
")",
";",
"$",
"shell",
"->",
"writeException",
"(",
"new",
"ParseErrorException",
"(",
"$",
"msg",
")",
")",
";",
"continue",
";",
"}",
"$",
"modified",
"[",
"]",
"=",
"$",
"file",
";",
"$",
"this",
"->",
"timestamps",
"[",
"$",
"file",
"]",
"=",
"$",
"timestamp",
";",
"}",
"// switch (count($modified)) {",
"// case 0:",
"// return;",
"// case 1:",
"// printf(\"Reloading modified file: \\\"%s\\\"\\n\", str_replace(getcwd(), '.', $file));",
"// break;",
"// default:",
"// printf(\"Reloading %d modified files\\n\", count($modified));",
"// break;",
"// }",
"foreach",
"(",
"$",
"modified",
"as",
"$",
"file",
")",
"{",
"runkit_import",
"(",
"$",
"file",
",",
"(",
"RUNKIT_IMPORT_FUNCTIONS",
"|",
"RUNKIT_IMPORT_CLASSES",
"|",
"RUNKIT_IMPORT_CLASS_METHODS",
"|",
"RUNKIT_IMPORT_CLASS_CONSTS",
"|",
"RUNKIT_IMPORT_CLASS_PROPS",
"|",
"RUNKIT_IMPORT_OVERRIDE",
")",
")",
";",
"}",
"}"
] | Look through included files and update anything with a new timestamp.
@param Shell $shell | [
"Look",
"through",
"included",
"files",
"and",
"update",
"anything",
"with",
"a",
"new",
"timestamp",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/ExecutionLoop/RunkitReloader.php#L63-L113 |
bobthecow/psysh | src/ExecutionLoop/RunkitReloader.php | RunkitReloader.lintFile | private function lintFile($file)
{
// first try to parse it
try {
$this->parser->parse(\file_get_contents($file));
} catch (\Exception $e) {
return false;
}
return true;
} | php | private function lintFile($file)
{
try {
$this->parser->parse(\file_get_contents($file));
} catch (\Exception $e) {
return false;
}
return true;
} | [
"private",
"function",
"lintFile",
"(",
"$",
"file",
")",
"{",
"// first try to parse it",
"try",
"{",
"$",
"this",
"->",
"parser",
"->",
"parse",
"(",
"\\",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Should this file be re-imported?
Use PHP-Parser to ensure that the file is valid PHP.
@param string $file
@return bool | [
"Should",
"this",
"file",
"be",
"re",
"-",
"imported?"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/ExecutionLoop/RunkitReloader.php#L124-L134 |
bobthecow/psysh | src/Command/BufferCommand.php | BufferCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$buf = $this->getApplication()->getCodeBuffer();
if ($input->getOption('clear')) {
$this->getApplication()->resetCodeBuffer();
$output->writeln($this->formatLines($buf, 'urgent'), ShellOutput::NUMBER_LINES);
} else {
$output->writeln($this->formatLines($buf), ShellOutput::NUMBER_LINES);
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$buf = $this->getApplication()->getCodeBuffer();
if ($input->getOption('clear')) {
$this->getApplication()->resetCodeBuffer();
$output->writeln($this->formatLines($buf, 'urgent'), ShellOutput::NUMBER_LINES);
} else {
$output->writeln($this->formatLines($buf), ShellOutput::NUMBER_LINES);
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"buf",
"=",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"getCodeBuffer",
"(",
")",
";",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'clear'",
")",
")",
"{",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"resetCodeBuffer",
"(",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"formatLines",
"(",
"$",
"buf",
",",
"'urgent'",
")",
",",
"ShellOutput",
"::",
"NUMBER_LINES",
")",
";",
"}",
"else",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"formatLines",
"(",
"$",
"buf",
")",
",",
"ShellOutput",
"::",
"NUMBER_LINES",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/BufferCommand.php#L50-L59 |
bobthecow/psysh | src/Command/BufferCommand.php | BufferCommand.formatLines | protected function formatLines(array $lines, $type = 'return')
{
$template = \sprintf('<%s>%%s</%s>', $type, $type);
return \array_map(function ($line) use ($template) {
return \sprintf($template, $line);
}, $lines);
} | php | protected function formatLines(array $lines, $type = 'return')
{
$template = \sprintf('<%s>%%s</%s>', $type, $type);
return \array_map(function ($line) use ($template) {
return \sprintf($template, $line);
}, $lines);
} | [
"protected",
"function",
"formatLines",
"(",
"array",
"$",
"lines",
",",
"$",
"type",
"=",
"'return'",
")",
"{",
"$",
"template",
"=",
"\\",
"sprintf",
"(",
"'<%s>%%s</%s>'",
",",
"$",
"type",
",",
"$",
"type",
")",
";",
"return",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"line",
")",
"use",
"(",
"$",
"template",
")",
"{",
"return",
"\\",
"sprintf",
"(",
"$",
"template",
",",
"$",
"line",
")",
";",
"}",
",",
"$",
"lines",
")",
";",
"}"
] | A helper method for wrapping buffer lines in `<urgent>` and `<return>` formatter strings.
@param array $lines
@param string $type (default: 'return')
@return array Formatted strings | [
"A",
"helper",
"method",
"for",
"wrapping",
"buffer",
"lines",
"in",
"<urgent",
">",
"and",
"<return",
">",
"formatter",
"strings",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/BufferCommand.php#L69-L76 |
bobthecow/psysh | src/Formatter/SignatureFormatter.php | SignatureFormatter.format | public static function format(\Reflector $reflector)
{
switch (true) {
case $reflector instanceof \ReflectionFunction:
case $reflector instanceof ReflectionLanguageConstruct:
return self::formatFunction($reflector);
// this case also covers \ReflectionObject:
case $reflector instanceof \ReflectionClass:
return self::formatClass($reflector);
case $reflector instanceof ReflectionClassConstant:
case $reflector instanceof \ReflectionClassConstant:
return self::formatClassConstant($reflector);
case $reflector instanceof \ReflectionMethod:
return self::formatMethod($reflector);
case $reflector instanceof \ReflectionProperty:
return self::formatProperty($reflector);
case $reflector instanceof ReflectionConstant_:
return self::formatConstant($reflector);
default:
throw new \InvalidArgumentException('Unexpected Reflector class: ' . \get_class($reflector));
}
} | php | public static function format(\Reflector $reflector)
{
switch (true) {
case $reflector instanceof \ReflectionFunction:
case $reflector instanceof ReflectionLanguageConstruct:
return self::formatFunction($reflector);
case $reflector instanceof \ReflectionClass:
return self::formatClass($reflector);
case $reflector instanceof ReflectionClassConstant:
case $reflector instanceof \ReflectionClassConstant:
return self::formatClassConstant($reflector);
case $reflector instanceof \ReflectionMethod:
return self::formatMethod($reflector);
case $reflector instanceof \ReflectionProperty:
return self::formatProperty($reflector);
case $reflector instanceof ReflectionConstant_:
return self::formatConstant($reflector);
default:
throw new \InvalidArgumentException('Unexpected Reflector class: ' . \get_class($reflector));
}
} | [
"public",
"static",
"function",
"format",
"(",
"\\",
"Reflector",
"$",
"reflector",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"reflector",
"instanceof",
"\\",
"ReflectionFunction",
":",
"case",
"$",
"reflector",
"instanceof",
"ReflectionLanguageConstruct",
":",
"return",
"self",
"::",
"formatFunction",
"(",
"$",
"reflector",
")",
";",
"// this case also covers \\ReflectionObject:",
"case",
"$",
"reflector",
"instanceof",
"\\",
"ReflectionClass",
":",
"return",
"self",
"::",
"formatClass",
"(",
"$",
"reflector",
")",
";",
"case",
"$",
"reflector",
"instanceof",
"ReflectionClassConstant",
":",
"case",
"$",
"reflector",
"instanceof",
"\\",
"ReflectionClassConstant",
":",
"return",
"self",
"::",
"formatClassConstant",
"(",
"$",
"reflector",
")",
";",
"case",
"$",
"reflector",
"instanceof",
"\\",
"ReflectionMethod",
":",
"return",
"self",
"::",
"formatMethod",
"(",
"$",
"reflector",
")",
";",
"case",
"$",
"reflector",
"instanceof",
"\\",
"ReflectionProperty",
":",
"return",
"self",
"::",
"formatProperty",
"(",
"$",
"reflector",
")",
";",
"case",
"$",
"reflector",
"instanceof",
"ReflectionConstant_",
":",
"return",
"self",
"::",
"formatConstant",
"(",
"$",
"reflector",
")",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unexpected Reflector class: '",
".",
"\\",
"get_class",
"(",
"$",
"reflector",
")",
")",
";",
"}",
"}"
] | Format a signature for the given reflector.
Defers to subclasses to do the actual formatting.
@param \Reflector $reflector
@return string Formatted signature | [
"Format",
"a",
"signature",
"for",
"the",
"given",
"reflector",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/SignatureFormatter.php#L34-L61 |
bobthecow/psysh | src/Formatter/SignatureFormatter.php | SignatureFormatter.formatModifiers | private static function formatModifiers(\Reflector $reflector)
{
if ($reflector instanceof \ReflectionClass && $reflector->isTrait()) {
// For some reason, PHP 5.x returns `abstract public` modifiers for
// traits. Let's just ignore that business entirely.
if (\version_compare(PHP_VERSION, '7.0.0', '<')) {
return [];
}
}
return \implode(' ', \array_map(function ($modifier) {
return \sprintf('<keyword>%s</keyword>', $modifier);
}, \Reflection::getModifierNames($reflector->getModifiers())));
} | php | private static function formatModifiers(\Reflector $reflector)
{
if ($reflector instanceof \ReflectionClass && $reflector->isTrait()) {
if (\version_compare(PHP_VERSION, '7.0.0', '<')) {
return [];
}
}
return \implode(' ', \array_map(function ($modifier) {
return \sprintf('<keyword>%s</keyword>', $modifier);
}, \Reflection::getModifierNames($reflector->getModifiers())));
} | [
"private",
"static",
"function",
"formatModifiers",
"(",
"\\",
"Reflector",
"$",
"reflector",
")",
"{",
"if",
"(",
"$",
"reflector",
"instanceof",
"\\",
"ReflectionClass",
"&&",
"$",
"reflector",
"->",
"isTrait",
"(",
")",
")",
"{",
"// For some reason, PHP 5.x returns `abstract public` modifiers for",
"// traits. Let's just ignore that business entirely.",
"if",
"(",
"\\",
"version_compare",
"(",
"PHP_VERSION",
",",
"'7.0.0'",
",",
"'<'",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"}",
"return",
"\\",
"implode",
"(",
"' '",
",",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"modifier",
")",
"{",
"return",
"\\",
"sprintf",
"(",
"'<keyword>%s</keyword>'",
",",
"$",
"modifier",
")",
";",
"}",
",",
"\\",
"Reflection",
"::",
"getModifierNames",
"(",
"$",
"reflector",
"->",
"getModifiers",
"(",
")",
")",
")",
")",
";",
"}"
] | Print the method, property or class modifiers.
@param \Reflector $reflector
@return string Formatted modifiers | [
"Print",
"the",
"method",
"property",
"or",
"class",
"modifiers",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/SignatureFormatter.php#L82-L95 |
bobthecow/psysh | src/Formatter/SignatureFormatter.php | SignatureFormatter.formatClass | private static function formatClass(\ReflectionClass $reflector)
{
$chunks = [];
if ($modifiers = self::formatModifiers($reflector)) {
$chunks[] = $modifiers;
}
if ($reflector->isTrait()) {
$chunks[] = 'trait';
} else {
$chunks[] = $reflector->isInterface() ? 'interface' : 'class';
}
$chunks[] = \sprintf('<class>%s</class>', self::formatName($reflector));
if ($parent = $reflector->getParentClass()) {
$chunks[] = 'extends';
$chunks[] = \sprintf('<class>%s</class>', $parent->getName());
}
$interfaces = $reflector->getInterfaceNames();
if (!empty($interfaces)) {
\sort($interfaces);
$chunks[] = 'implements';
$chunks[] = \implode(', ', \array_map(function ($name) {
return \sprintf('<class>%s</class>', $name);
}, $interfaces));
}
return \implode(' ', $chunks);
} | php | private static function formatClass(\ReflectionClass $reflector)
{
$chunks = [];
if ($modifiers = self::formatModifiers($reflector)) {
$chunks[] = $modifiers;
}
if ($reflector->isTrait()) {
$chunks[] = 'trait';
} else {
$chunks[] = $reflector->isInterface() ? 'interface' : 'class';
}
$chunks[] = \sprintf('<class>%s</class>', self::formatName($reflector));
if ($parent = $reflector->getParentClass()) {
$chunks[] = 'extends';
$chunks[] = \sprintf('<class>%s</class>', $parent->getName());
}
$interfaces = $reflector->getInterfaceNames();
if (!empty($interfaces)) {
\sort($interfaces);
$chunks[] = 'implements';
$chunks[] = \implode(', ', \array_map(function ($name) {
return \sprintf('<class>%s</class>', $name);
}, $interfaces));
}
return \implode(' ', $chunks);
} | [
"private",
"static",
"function",
"formatClass",
"(",
"\\",
"ReflectionClass",
"$",
"reflector",
")",
"{",
"$",
"chunks",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"modifiers",
"=",
"self",
"::",
"formatModifiers",
"(",
"$",
"reflector",
")",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"$",
"modifiers",
";",
"}",
"if",
"(",
"$",
"reflector",
"->",
"isTrait",
"(",
")",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"'trait'",
";",
"}",
"else",
"{",
"$",
"chunks",
"[",
"]",
"=",
"$",
"reflector",
"->",
"isInterface",
"(",
")",
"?",
"'interface'",
":",
"'class'",
";",
"}",
"$",
"chunks",
"[",
"]",
"=",
"\\",
"sprintf",
"(",
"'<class>%s</class>'",
",",
"self",
"::",
"formatName",
"(",
"$",
"reflector",
")",
")",
";",
"if",
"(",
"$",
"parent",
"=",
"$",
"reflector",
"->",
"getParentClass",
"(",
")",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"'extends'",
";",
"$",
"chunks",
"[",
"]",
"=",
"\\",
"sprintf",
"(",
"'<class>%s</class>'",
",",
"$",
"parent",
"->",
"getName",
"(",
")",
")",
";",
"}",
"$",
"interfaces",
"=",
"$",
"reflector",
"->",
"getInterfaceNames",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"interfaces",
")",
")",
"{",
"\\",
"sort",
"(",
"$",
"interfaces",
")",
";",
"$",
"chunks",
"[",
"]",
"=",
"'implements'",
";",
"$",
"chunks",
"[",
"]",
"=",
"\\",
"implode",
"(",
"', '",
",",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"name",
")",
"{",
"return",
"\\",
"sprintf",
"(",
"'<class>%s</class>'",
",",
"$",
"name",
")",
";",
"}",
",",
"$",
"interfaces",
")",
")",
";",
"}",
"return",
"\\",
"implode",
"(",
"' '",
",",
"$",
"chunks",
")",
";",
"}"
] | Format a class signature.
@param \ReflectionClass $reflector
@return string Formatted signature | [
"Format",
"a",
"class",
"signature",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/SignatureFormatter.php#L104-L136 |
bobthecow/psysh | src/Formatter/SignatureFormatter.php | SignatureFormatter.formatClassConstant | private static function formatClassConstant($reflector)
{
$value = $reflector->getValue();
$style = self::getTypeStyle($value);
return \sprintf(
'<keyword>const</keyword> <const>%s</const> = <%s>%s</%s>',
self::formatName($reflector),
$style,
OutputFormatter::escape(Json::encode($value)),
$style
);
} | php | private static function formatClassConstant($reflector)
{
$value = $reflector->getValue();
$style = self::getTypeStyle($value);
return \sprintf(
'<keyword>const</keyword> <const>%s</const> = <%s>%s</%s>',
self::formatName($reflector),
$style,
OutputFormatter::escape(Json::encode($value)),
$style
);
} | [
"private",
"static",
"function",
"formatClassConstant",
"(",
"$",
"reflector",
")",
"{",
"$",
"value",
"=",
"$",
"reflector",
"->",
"getValue",
"(",
")",
";",
"$",
"style",
"=",
"self",
"::",
"getTypeStyle",
"(",
"$",
"value",
")",
";",
"return",
"\\",
"sprintf",
"(",
"'<keyword>const</keyword> <const>%s</const> = <%s>%s</%s>'",
",",
"self",
"::",
"formatName",
"(",
"$",
"reflector",
")",
",",
"$",
"style",
",",
"OutputFormatter",
"::",
"escape",
"(",
"Json",
"::",
"encode",
"(",
"$",
"value",
")",
")",
",",
"$",
"style",
")",
";",
"}"
] | Format a constant signature.
@param ReflectionClassConstant|\ReflectionClassConstant $reflector
@return string Formatted signature | [
"Format",
"a",
"constant",
"signature",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/SignatureFormatter.php#L145-L157 |
bobthecow/psysh | src/Formatter/SignatureFormatter.php | SignatureFormatter.formatConstant | private static function formatConstant($reflector)
{
$value = $reflector->getValue();
$style = self::getTypeStyle($value);
return \sprintf(
'<keyword>define</keyword>(<string>%s</string>, <%s>%s</%s>)',
OutputFormatter::escape(Json::encode($reflector->getName())),
$style,
OutputFormatter::escape(Json::encode($value)),
$style
);
} | php | private static function formatConstant($reflector)
{
$value = $reflector->getValue();
$style = self::getTypeStyle($value);
return \sprintf(
'<keyword>define</keyword>(<string>%s</string>, <%s>%s</%s>)',
OutputFormatter::escape(Json::encode($reflector->getName())),
$style,
OutputFormatter::escape(Json::encode($value)),
$style
);
} | [
"private",
"static",
"function",
"formatConstant",
"(",
"$",
"reflector",
")",
"{",
"$",
"value",
"=",
"$",
"reflector",
"->",
"getValue",
"(",
")",
";",
"$",
"style",
"=",
"self",
"::",
"getTypeStyle",
"(",
"$",
"value",
")",
";",
"return",
"\\",
"sprintf",
"(",
"'<keyword>define</keyword>(<string>%s</string>, <%s>%s</%s>)'",
",",
"OutputFormatter",
"::",
"escape",
"(",
"Json",
"::",
"encode",
"(",
"$",
"reflector",
"->",
"getName",
"(",
")",
")",
")",
",",
"$",
"style",
",",
"OutputFormatter",
"::",
"escape",
"(",
"Json",
"::",
"encode",
"(",
"$",
"value",
")",
")",
",",
"$",
"style",
")",
";",
"}"
] | Format a constant signature.
@param ReflectionConstant_ $reflector
@return string Formatted signature | [
"Format",
"a",
"constant",
"signature",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/SignatureFormatter.php#L166-L178 |
bobthecow/psysh | src/Formatter/SignatureFormatter.php | SignatureFormatter.getTypeStyle | private static function getTypeStyle($value)
{
if (\is_int($value) || \is_float($value)) {
return 'number';
} elseif (\is_string($value)) {
return 'string';
} elseif (\is_bool($value) || \is_null($value)) {
return 'bool';
} else {
return 'strong'; // @codeCoverageIgnore
}
} | php | private static function getTypeStyle($value)
{
if (\is_int($value) || \is_float($value)) {
return 'number';
} elseif (\is_string($value)) {
return 'string';
} elseif (\is_bool($value) || \is_null($value)) {
return 'bool';
} else {
return 'strong';
}
} | [
"private",
"static",
"function",
"getTypeStyle",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"\\",
"is_int",
"(",
"$",
"value",
")",
"||",
"\\",
"is_float",
"(",
"$",
"value",
")",
")",
"{",
"return",
"'number'",
";",
"}",
"elseif",
"(",
"\\",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"'string'",
";",
"}",
"elseif",
"(",
"\\",
"is_bool",
"(",
"$",
"value",
")",
"||",
"\\",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"return",
"'bool'",
";",
"}",
"else",
"{",
"return",
"'strong'",
";",
"// @codeCoverageIgnore",
"}",
"}"
] | Helper for getting output style for a given value's type.
@param mixed $value
@return string | [
"Helper",
"for",
"getting",
"output",
"style",
"for",
"a",
"given",
"value",
"s",
"type",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/SignatureFormatter.php#L187-L198 |
bobthecow/psysh | src/Formatter/SignatureFormatter.php | SignatureFormatter.formatFunction | private static function formatFunction(\ReflectionFunctionAbstract $reflector)
{
return \sprintf(
'<keyword>function</keyword> %s<function>%s</function>(%s)',
$reflector->returnsReference() ? '&' : '',
self::formatName($reflector),
\implode(', ', self::formatFunctionParams($reflector))
);
} | php | private static function formatFunction(\ReflectionFunctionAbstract $reflector)
{
return \sprintf(
'<keyword>function</keyword> %s<function>%s</function>(%s)',
$reflector->returnsReference() ? '&' : '',
self::formatName($reflector),
\implode(', ', self::formatFunctionParams($reflector))
);
} | [
"private",
"static",
"function",
"formatFunction",
"(",
"\\",
"ReflectionFunctionAbstract",
"$",
"reflector",
")",
"{",
"return",
"\\",
"sprintf",
"(",
"'<keyword>function</keyword> %s<function>%s</function>(%s)'",
",",
"$",
"reflector",
"->",
"returnsReference",
"(",
")",
"?",
"'&'",
":",
"''",
",",
"self",
"::",
"formatName",
"(",
"$",
"reflector",
")",
",",
"\\",
"implode",
"(",
"', '",
",",
"self",
"::",
"formatFunctionParams",
"(",
"$",
"reflector",
")",
")",
")",
";",
"}"
] | Format a function signature.
@param \ReflectionFunction $reflector
@return string Formatted signature | [
"Format",
"a",
"function",
"signature",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/SignatureFormatter.php#L223-L231 |
bobthecow/psysh | src/Formatter/SignatureFormatter.php | SignatureFormatter.formatMethod | private static function formatMethod(\ReflectionMethod $reflector)
{
return \sprintf(
'%s %s',
self::formatModifiers($reflector),
self::formatFunction($reflector)
);
} | php | private static function formatMethod(\ReflectionMethod $reflector)
{
return \sprintf(
'%s %s',
self::formatModifiers($reflector),
self::formatFunction($reflector)
);
} | [
"private",
"static",
"function",
"formatMethod",
"(",
"\\",
"ReflectionMethod",
"$",
"reflector",
")",
"{",
"return",
"\\",
"sprintf",
"(",
"'%s %s'",
",",
"self",
"::",
"formatModifiers",
"(",
"$",
"reflector",
")",
",",
"self",
"::",
"formatFunction",
"(",
"$",
"reflector",
")",
")",
";",
"}"
] | Format a method signature.
@param \ReflectionMethod $reflector
@return string Formatted signature | [
"Format",
"a",
"method",
"signature",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/SignatureFormatter.php#L240-L247 |
bobthecow/psysh | src/Formatter/SignatureFormatter.php | SignatureFormatter.formatFunctionParams | private static function formatFunctionParams(\ReflectionFunctionAbstract $reflector)
{
$params = [];
foreach ($reflector->getParameters() as $param) {
$hint = '';
try {
if ($param->isArray()) {
$hint = '<keyword>array</keyword> ';
} elseif ($class = $param->getClass()) {
$hint = \sprintf('<class>%s</class> ', $class->getName());
}
} catch (\Exception $e) {
// sometimes we just don't know...
// bad class names, or autoloaded classes that haven't been loaded yet, or whathaveyou.
// come to think of it, the only time I've seen this is with the intl extension.
// Hax: we'll try to extract it :P
// @codeCoverageIgnoreStart
$chunks = \explode('$' . $param->getName(), (string) $param);
$chunks = \explode(' ', \trim($chunks[0]));
$guess = \end($chunks);
$hint = \sprintf('<urgent>%s</urgent> ', $guess);
// @codeCoverageIgnoreEnd
}
if ($param->isOptional()) {
if (!$param->isDefaultValueAvailable()) {
$value = 'unknown';
$typeStyle = 'urgent';
} else {
$value = $param->getDefaultValue();
$typeStyle = self::getTypeStyle($value);
$value = \is_array($value) ? 'array()' : \is_null($value) ? 'null' : \var_export($value, true);
}
$default = \sprintf(' = <%s>%s</%s>', $typeStyle, OutputFormatter::escape($value), $typeStyle);
} else {
$default = '';
}
$params[] = \sprintf(
'%s%s<strong>$%s</strong>%s',
$param->isPassedByReference() ? '&' : '',
$hint,
$param->getName(),
$default
);
}
return $params;
} | php | private static function formatFunctionParams(\ReflectionFunctionAbstract $reflector)
{
$params = [];
foreach ($reflector->getParameters() as $param) {
$hint = '';
try {
if ($param->isArray()) {
$hint = '<keyword>array</keyword> ';
} elseif ($class = $param->getClass()) {
$hint = \sprintf('<class>%s</class> ', $class->getName());
}
} catch (\Exception $e) {
$chunks = \explode('$' . $param->getName(), (string) $param);
$chunks = \explode(' ', \trim($chunks[0]));
$guess = \end($chunks);
$hint = \sprintf('<urgent>%s</urgent> ', $guess);
}
if ($param->isOptional()) {
if (!$param->isDefaultValueAvailable()) {
$value = 'unknown';
$typeStyle = 'urgent';
} else {
$value = $param->getDefaultValue();
$typeStyle = self::getTypeStyle($value);
$value = \is_array($value) ? 'array()' : \is_null($value) ? 'null' : \var_export($value, true);
}
$default = \sprintf(' = <%s>%s</%s>', $typeStyle, OutputFormatter::escape($value), $typeStyle);
} else {
$default = '';
}
$params[] = \sprintf(
'%s%s<strong>$%s</strong>%s',
$param->isPassedByReference() ? '&' : '',
$hint,
$param->getName(),
$default
);
}
return $params;
} | [
"private",
"static",
"function",
"formatFunctionParams",
"(",
"\\",
"ReflectionFunctionAbstract",
"$",
"reflector",
")",
"{",
"$",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"reflector",
"->",
"getParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"$",
"hint",
"=",
"''",
";",
"try",
"{",
"if",
"(",
"$",
"param",
"->",
"isArray",
"(",
")",
")",
"{",
"$",
"hint",
"=",
"'<keyword>array</keyword> '",
";",
"}",
"elseif",
"(",
"$",
"class",
"=",
"$",
"param",
"->",
"getClass",
"(",
")",
")",
"{",
"$",
"hint",
"=",
"\\",
"sprintf",
"(",
"'<class>%s</class> '",
",",
"$",
"class",
"->",
"getName",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// sometimes we just don't know...",
"// bad class names, or autoloaded classes that haven't been loaded yet, or whathaveyou.",
"// come to think of it, the only time I've seen this is with the intl extension.",
"// Hax: we'll try to extract it :P",
"// @codeCoverageIgnoreStart",
"$",
"chunks",
"=",
"\\",
"explode",
"(",
"'$'",
".",
"$",
"param",
"->",
"getName",
"(",
")",
",",
"(",
"string",
")",
"$",
"param",
")",
";",
"$",
"chunks",
"=",
"\\",
"explode",
"(",
"' '",
",",
"\\",
"trim",
"(",
"$",
"chunks",
"[",
"0",
"]",
")",
")",
";",
"$",
"guess",
"=",
"\\",
"end",
"(",
"$",
"chunks",
")",
";",
"$",
"hint",
"=",
"\\",
"sprintf",
"(",
"'<urgent>%s</urgent> '",
",",
"$",
"guess",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"if",
"(",
"$",
"param",
"->",
"isOptional",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"param",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"$",
"value",
"=",
"'unknown'",
";",
"$",
"typeStyle",
"=",
"'urgent'",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
";",
"$",
"typeStyle",
"=",
"self",
"::",
"getTypeStyle",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"\\",
"is_array",
"(",
"$",
"value",
")",
"?",
"'array()'",
":",
"\\",
"is_null",
"(",
"$",
"value",
")",
"?",
"'null'",
":",
"\\",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
";",
"}",
"$",
"default",
"=",
"\\",
"sprintf",
"(",
"' = <%s>%s</%s>'",
",",
"$",
"typeStyle",
",",
"OutputFormatter",
"::",
"escape",
"(",
"$",
"value",
")",
",",
"$",
"typeStyle",
")",
";",
"}",
"else",
"{",
"$",
"default",
"=",
"''",
";",
"}",
"$",
"params",
"[",
"]",
"=",
"\\",
"sprintf",
"(",
"'%s%s<strong>$%s</strong>%s'",
",",
"$",
"param",
"->",
"isPassedByReference",
"(",
")",
"?",
"'&'",
":",
"''",
",",
"$",
"hint",
",",
"$",
"param",
"->",
"getName",
"(",
")",
",",
"$",
"default",
")",
";",
"}",
"return",
"$",
"params",
";",
"}"
] | Print the function params.
@param \ReflectionFunctionAbstract $reflector
@return array | [
"Print",
"the",
"function",
"params",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/SignatureFormatter.php#L256-L307 |
bobthecow/psysh | src/Util/Docblock.php | Docblock.setComment | protected function setComment($comment)
{
$this->desc = '';
$this->tags = [];
$this->comment = $comment;
$this->parseComment($comment);
} | php | protected function setComment($comment)
{
$this->desc = '';
$this->tags = [];
$this->comment = $comment;
$this->parseComment($comment);
} | [
"protected",
"function",
"setComment",
"(",
"$",
"comment",
")",
"{",
"$",
"this",
"->",
"desc",
"=",
"''",
";",
"$",
"this",
"->",
"tags",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"comment",
"=",
"$",
"comment",
";",
"$",
"this",
"->",
"parseComment",
"(",
"$",
"comment",
")",
";",
"}"
] | Set and parse the docblock comment.
@param string $comment The docblock | [
"Set",
"and",
"parse",
"the",
"docblock",
"comment",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Util/Docblock.php#L85-L92 |
bobthecow/psysh | src/Util/Docblock.php | Docblock.prefixLength | protected static function prefixLength(array $lines)
{
// find only lines with interesting things
$lines = \array_filter($lines, function ($line) {
return \substr($line, \strspn($line, "* \t\n\r\0\x0B"));
});
// if we sort the lines, we only have to compare two items
\sort($lines);
$first = \reset($lines);
$last = \end($lines);
// find the longest common substring
$count = \min(\strlen($first), \strlen($last));
for ($i = 0; $i < $count; $i++) {
if ($first[$i] !== $last[$i]) {
return $i;
}
}
return $count;
} | php | protected static function prefixLength(array $lines)
{
$lines = \array_filter($lines, function ($line) {
return \substr($line, \strspn($line, "* \t\n\r\0\x0B"));
});
\sort($lines);
$first = \reset($lines);
$last = \end($lines);
$count = \min(\strlen($first), \strlen($last));
for ($i = 0; $i < $count; $i++) {
if ($first[$i] !== $last[$i]) {
return $i;
}
}
return $count;
} | [
"protected",
"static",
"function",
"prefixLength",
"(",
"array",
"$",
"lines",
")",
"{",
"// find only lines with interesting things",
"$",
"lines",
"=",
"\\",
"array_filter",
"(",
"$",
"lines",
",",
"function",
"(",
"$",
"line",
")",
"{",
"return",
"\\",
"substr",
"(",
"$",
"line",
",",
"\\",
"strspn",
"(",
"$",
"line",
",",
"\"* \\t\\n\\r\\0\\x0B\"",
")",
")",
";",
"}",
")",
";",
"// if we sort the lines, we only have to compare two items",
"\\",
"sort",
"(",
"$",
"lines",
")",
";",
"$",
"first",
"=",
"\\",
"reset",
"(",
"$",
"lines",
")",
";",
"$",
"last",
"=",
"\\",
"end",
"(",
"$",
"lines",
")",
";",
"// find the longest common substring",
"$",
"count",
"=",
"\\",
"min",
"(",
"\\",
"strlen",
"(",
"$",
"first",
")",
",",
"\\",
"strlen",
"(",
"$",
"last",
")",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"first",
"[",
"$",
"i",
"]",
"!==",
"$",
"last",
"[",
"$",
"i",
"]",
")",
"{",
"return",
"$",
"i",
";",
"}",
"}",
"return",
"$",
"count",
";",
"}"
] | Find the length of the docblock prefix.
@param array $lines
@return int Prefix length | [
"Find",
"the",
"length",
"of",
"the",
"docblock",
"prefix",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Util/Docblock.php#L101-L123 |
bobthecow/psysh | src/Util/Docblock.php | Docblock.parseComment | protected function parseComment($comment)
{
// Strip the opening and closing tags of the docblock
$comment = \substr($comment, 3, -2);
// Split into arrays of lines
$comment = \array_filter(\preg_split('/\r?\n\r?/', $comment));
// Trim asterisks and whitespace from the beginning and whitespace from the end of lines
$prefixLength = self::prefixLength($comment);
$comment = \array_map(function ($line) use ($prefixLength) {
return \rtrim(\substr($line, $prefixLength));
}, $comment);
// Group the lines together by @tags
$blocks = [];
$b = -1;
foreach ($comment as $line) {
if (self::isTagged($line)) {
$b++;
$blocks[] = [];
} elseif ($b === -1) {
$b = 0;
$blocks[] = [];
}
$blocks[$b][] = $line;
}
// Parse the blocks
foreach ($blocks as $block => $body) {
$body = \trim(\implode("\n", $body));
if ($block === 0 && !self::isTagged($body)) {
// This is the description block
$this->desc = $body;
} else {
// This block is tagged
$tag = \substr(self::strTag($body), 1);
$body = \ltrim(\substr($body, \strlen($tag) + 2));
if (isset(self::$vectors[$tag])) {
// The tagged block is a vector
$count = \count(self::$vectors[$tag]);
if ($body) {
$parts = \preg_split('/\s+/', $body, $count);
} else {
$parts = [];
}
// Default the trailing values
$parts = \array_pad($parts, $count, null);
// Store as a mapped array
$this->tags[$tag][] = \array_combine(self::$vectors[$tag], $parts);
} else {
// The tagged block is only text
$this->tags[$tag][] = $body;
}
}
}
} | php | protected function parseComment($comment)
{
$comment = \substr($comment, 3, -2);
$comment = \array_filter(\preg_split('/\r?\n\r?/', $comment));
$prefixLength = self::prefixLength($comment);
$comment = \array_map(function ($line) use ($prefixLength) {
return \rtrim(\substr($line, $prefixLength));
}, $comment);
$blocks = [];
$b = -1;
foreach ($comment as $line) {
if (self::isTagged($line)) {
$b++;
$blocks[] = [];
} elseif ($b === -1) {
$b = 0;
$blocks[] = [];
}
$blocks[$b][] = $line;
}
foreach ($blocks as $block => $body) {
$body = \trim(\implode("\n", $body));
if ($block === 0 && !self::isTagged($body)) {
$this->desc = $body;
} else {
$tag = \substr(self::strTag($body), 1);
$body = \ltrim(\substr($body, \strlen($tag) + 2));
if (isset(self::$vectors[$tag])) {
$count = \count(self::$vectors[$tag]);
if ($body) {
$parts = \preg_split('/\s+/', $body, $count);
} else {
$parts = [];
}
$parts = \array_pad($parts, $count, null);
$this->tags[$tag][] = \array_combine(self::$vectors[$tag], $parts);
} else {
$this->tags[$tag][] = $body;
}
}
}
} | [
"protected",
"function",
"parseComment",
"(",
"$",
"comment",
")",
"{",
"// Strip the opening and closing tags of the docblock",
"$",
"comment",
"=",
"\\",
"substr",
"(",
"$",
"comment",
",",
"3",
",",
"-",
"2",
")",
";",
"// Split into arrays of lines",
"$",
"comment",
"=",
"\\",
"array_filter",
"(",
"\\",
"preg_split",
"(",
"'/\\r?\\n\\r?/'",
",",
"$",
"comment",
")",
")",
";",
"// Trim asterisks and whitespace from the beginning and whitespace from the end of lines",
"$",
"prefixLength",
"=",
"self",
"::",
"prefixLength",
"(",
"$",
"comment",
")",
";",
"$",
"comment",
"=",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"line",
")",
"use",
"(",
"$",
"prefixLength",
")",
"{",
"return",
"\\",
"rtrim",
"(",
"\\",
"substr",
"(",
"$",
"line",
",",
"$",
"prefixLength",
")",
")",
";",
"}",
",",
"$",
"comment",
")",
";",
"// Group the lines together by @tags",
"$",
"blocks",
"=",
"[",
"]",
";",
"$",
"b",
"=",
"-",
"1",
";",
"foreach",
"(",
"$",
"comment",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"self",
"::",
"isTagged",
"(",
"$",
"line",
")",
")",
"{",
"$",
"b",
"++",
";",
"$",
"blocks",
"[",
"]",
"=",
"[",
"]",
";",
"}",
"elseif",
"(",
"$",
"b",
"===",
"-",
"1",
")",
"{",
"$",
"b",
"=",
"0",
";",
"$",
"blocks",
"[",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"blocks",
"[",
"$",
"b",
"]",
"[",
"]",
"=",
"$",
"line",
";",
"}",
"// Parse the blocks",
"foreach",
"(",
"$",
"blocks",
"as",
"$",
"block",
"=>",
"$",
"body",
")",
"{",
"$",
"body",
"=",
"\\",
"trim",
"(",
"\\",
"implode",
"(",
"\"\\n\"",
",",
"$",
"body",
")",
")",
";",
"if",
"(",
"$",
"block",
"===",
"0",
"&&",
"!",
"self",
"::",
"isTagged",
"(",
"$",
"body",
")",
")",
"{",
"// This is the description block",
"$",
"this",
"->",
"desc",
"=",
"$",
"body",
";",
"}",
"else",
"{",
"// This block is tagged",
"$",
"tag",
"=",
"\\",
"substr",
"(",
"self",
"::",
"strTag",
"(",
"$",
"body",
")",
",",
"1",
")",
";",
"$",
"body",
"=",
"\\",
"ltrim",
"(",
"\\",
"substr",
"(",
"$",
"body",
",",
"\\",
"strlen",
"(",
"$",
"tag",
")",
"+",
"2",
")",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"vectors",
"[",
"$",
"tag",
"]",
")",
")",
"{",
"// The tagged block is a vector",
"$",
"count",
"=",
"\\",
"count",
"(",
"self",
"::",
"$",
"vectors",
"[",
"$",
"tag",
"]",
")",
";",
"if",
"(",
"$",
"body",
")",
"{",
"$",
"parts",
"=",
"\\",
"preg_split",
"(",
"'/\\s+/'",
",",
"$",
"body",
",",
"$",
"count",
")",
";",
"}",
"else",
"{",
"$",
"parts",
"=",
"[",
"]",
";",
"}",
"// Default the trailing values",
"$",
"parts",
"=",
"\\",
"array_pad",
"(",
"$",
"parts",
",",
"$",
"count",
",",
"null",
")",
";",
"// Store as a mapped array",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"]",
"[",
"]",
"=",
"\\",
"array_combine",
"(",
"self",
"::",
"$",
"vectors",
"[",
"$",
"tag",
"]",
",",
"$",
"parts",
")",
";",
"}",
"else",
"{",
"// The tagged block is only text",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"]",
"[",
"]",
"=",
"$",
"body",
";",
"}",
"}",
"}",
"}"
] | Parse the comment into the component parts and set the state of the object.
@param string $comment The docblock | [
"Parse",
"the",
"comment",
"into",
"the",
"component",
"parts",
"and",
"set",
"the",
"state",
"of",
"the",
"object",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Util/Docblock.php#L130-L190 |
bobthecow/psysh | src/CodeCleaner/FunctionReturnInWriteContextPass.php | FunctionReturnInWriteContextPass.enterNode | public function enterNode(Node $node)
{
if ($node instanceof Array_ || $this->isCallNode($node)) {
$items = $node instanceof Array_ ? $node->items : $node->args;
foreach ($items as $item) {
if ($item && $item->byRef && $this->isCallNode($item->value)) {
throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
}
}
} elseif ($node instanceof Isset_ || $node instanceof Unset_) {
foreach ($node->vars as $var) {
if (!$this->isCallNode($var)) {
continue;
}
$msg = ($node instanceof Isset_ && $this->atLeastPhp55) ? self::PHP55_MESSAGE : self::EXCEPTION_MESSAGE;
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
} elseif ($node instanceof Empty_ && !$this->atLeastPhp55 && $this->isCallNode($node->expr)) {
throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine()); // @codeCoverageIgnore
} elseif ($node instanceof Assign && $this->isCallNode($node->var)) {
throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
}
} | php | public function enterNode(Node $node)
{
if ($node instanceof Array_ || $this->isCallNode($node)) {
$items = $node instanceof Array_ ? $node->items : $node->args;
foreach ($items as $item) {
if ($item && $item->byRef && $this->isCallNode($item->value)) {
throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
}
}
} elseif ($node instanceof Isset_ || $node instanceof Unset_) {
foreach ($node->vars as $var) {
if (!$this->isCallNode($var)) {
continue;
}
$msg = ($node instanceof Isset_ && $this->atLeastPhp55) ? self::PHP55_MESSAGE : self::EXCEPTION_MESSAGE;
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
} elseif ($node instanceof Empty_ && !$this->atLeastPhp55 && $this->isCallNode($node->expr)) {
throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
} elseif ($node instanceof Assign && $this->isCallNode($node->var)) {
throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
}
} | [
"public",
"function",
"enterNode",
"(",
"Node",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"Array_",
"||",
"$",
"this",
"->",
"isCallNode",
"(",
"$",
"node",
")",
")",
"{",
"$",
"items",
"=",
"$",
"node",
"instanceof",
"Array_",
"?",
"$",
"node",
"->",
"items",
":",
"$",
"node",
"->",
"args",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"&&",
"$",
"item",
"->",
"byRef",
"&&",
"$",
"this",
"->",
"isCallNode",
"(",
"$",
"item",
"->",
"value",
")",
")",
"{",
"throw",
"new",
"FatalErrorException",
"(",
"self",
"::",
"EXCEPTION_MESSAGE",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"node",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"Isset_",
"||",
"$",
"node",
"instanceof",
"Unset_",
")",
"{",
"foreach",
"(",
"$",
"node",
"->",
"vars",
"as",
"$",
"var",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCallNode",
"(",
"$",
"var",
")",
")",
"{",
"continue",
";",
"}",
"$",
"msg",
"=",
"(",
"$",
"node",
"instanceof",
"Isset_",
"&&",
"$",
"this",
"->",
"atLeastPhp55",
")",
"?",
"self",
"::",
"PHP55_MESSAGE",
":",
"self",
"::",
"EXCEPTION_MESSAGE",
";",
"throw",
"new",
"FatalErrorException",
"(",
"$",
"msg",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"node",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"Empty_",
"&&",
"!",
"$",
"this",
"->",
"atLeastPhp55",
"&&",
"$",
"this",
"->",
"isCallNode",
"(",
"$",
"node",
"->",
"expr",
")",
")",
"{",
"throw",
"new",
"FatalErrorException",
"(",
"self",
"::",
"EXCEPTION_MESSAGE",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"node",
"->",
"getLine",
"(",
")",
")",
";",
"// @codeCoverageIgnore",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"Assign",
"&&",
"$",
"this",
"->",
"isCallNode",
"(",
"$",
"node",
"->",
"var",
")",
")",
"{",
"throw",
"new",
"FatalErrorException",
"(",
"self",
"::",
"EXCEPTION_MESSAGE",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"node",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"}"
] | Validate that the functions are used correctly.
@throws FatalErrorException if a function is passed as an argument reference
@throws FatalErrorException if a function is used as an argument in the isset
@throws FatalErrorException if a function is used as an argument in the empty, only for PHP < 5.5
@throws FatalErrorException if a value is assigned to a function
@param Node $node | [
"Validate",
"that",
"the",
"functions",
"are",
"used",
"correctly",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/FunctionReturnInWriteContextPass.php#L52-L75 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.enterNode | public function enterNode(Node $node)
{
parent::enterNode($node);
if (self::isConditional($node)) {
$this->conditionalScopes++;
} else {
// @todo add an "else" here which adds a runtime check for instances where we can't tell
// whether a class is being redefined by static analysis alone.
if ($this->conditionalScopes === 0) {
if ($node instanceof Class_) {
$this->validateClassStatement($node);
} elseif ($node instanceof Interface_) {
$this->validateInterfaceStatement($node);
} elseif ($node instanceof Trait_) {
$this->validateTraitStatement($node);
}
}
}
} | php | public function enterNode(Node $node)
{
parent::enterNode($node);
if (self::isConditional($node)) {
$this->conditionalScopes++;
} else {
if ($this->conditionalScopes === 0) {
if ($node instanceof Class_) {
$this->validateClassStatement($node);
} elseif ($node instanceof Interface_) {
$this->validateInterfaceStatement($node);
} elseif ($node instanceof Trait_) {
$this->validateTraitStatement($node);
}
}
}
} | [
"public",
"function",
"enterNode",
"(",
"Node",
"$",
"node",
")",
"{",
"parent",
"::",
"enterNode",
"(",
"$",
"node",
")",
";",
"if",
"(",
"self",
"::",
"isConditional",
"(",
"$",
"node",
")",
")",
"{",
"$",
"this",
"->",
"conditionalScopes",
"++",
";",
"}",
"else",
"{",
"// @todo add an \"else\" here which adds a runtime check for instances where we can't tell",
"// whether a class is being redefined by static analysis alone.",
"if",
"(",
"$",
"this",
"->",
"conditionalScopes",
"===",
"0",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"Class_",
")",
"{",
"$",
"this",
"->",
"validateClassStatement",
"(",
"$",
"node",
")",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"Interface_",
")",
"{",
"$",
"this",
"->",
"validateInterfaceStatement",
"(",
"$",
"node",
")",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"Trait_",
")",
"{",
"$",
"this",
"->",
"validateTraitStatement",
"(",
"$",
"node",
")",
";",
"}",
"}",
"}",
"}"
] | Validate class, interface and trait definitions.
Validate them upon entering the node, so that we know about their
presence and can validate constant fetches and static calls in class or
trait methods.
@param Node $node | [
"Validate",
"class",
"interface",
"and",
"trait",
"definitions",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L58-L77 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.leaveNode | public function leaveNode(Node $node)
{
if (self::isConditional($node)) {
$this->conditionalScopes--;
} elseif ($node instanceof New_) {
$this->validateNewExpression($node);
} elseif ($node instanceof ClassConstFetch) {
$this->validateClassConstFetchExpression($node);
} elseif ($node instanceof StaticCall) {
$this->validateStaticCallExpression($node);
}
} | php | public function leaveNode(Node $node)
{
if (self::isConditional($node)) {
$this->conditionalScopes--;
} elseif ($node instanceof New_) {
$this->validateNewExpression($node);
} elseif ($node instanceof ClassConstFetch) {
$this->validateClassConstFetchExpression($node);
} elseif ($node instanceof StaticCall) {
$this->validateStaticCallExpression($node);
}
} | [
"public",
"function",
"leaveNode",
"(",
"Node",
"$",
"node",
")",
"{",
"if",
"(",
"self",
"::",
"isConditional",
"(",
"$",
"node",
")",
")",
"{",
"$",
"this",
"->",
"conditionalScopes",
"--",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"New_",
")",
"{",
"$",
"this",
"->",
"validateNewExpression",
"(",
"$",
"node",
")",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"ClassConstFetch",
")",
"{",
"$",
"this",
"->",
"validateClassConstFetchExpression",
"(",
"$",
"node",
")",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"StaticCall",
")",
"{",
"$",
"this",
"->",
"validateStaticCallExpression",
"(",
"$",
"node",
")",
";",
"}",
"}"
] | Validate `new` expressions, class constant fetches, and static calls.
@throws FatalErrorException if a class, interface or trait is referenced which does not exist
@throws FatalErrorException if a class extends something that is not a class
@throws FatalErrorException if a class implements something that is not an interface
@throws FatalErrorException if an interface extends something that is not an interface
@throws FatalErrorException if a class, interface or trait redefines an existing class, interface or trait name
@param Node $node | [
"Validate",
"new",
"expressions",
"class",
"constant",
"fetches",
"and",
"static",
"calls",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L90-L101 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.validateClassStatement | protected function validateClassStatement(Class_ $stmt)
{
$this->ensureCanDefine($stmt, self::CLASS_TYPE);
if (isset($stmt->extends)) {
$this->ensureClassExists($this->getFullyQualifiedName($stmt->extends), $stmt);
}
$this->ensureInterfacesExist($stmt->implements, $stmt);
} | php | protected function validateClassStatement(Class_ $stmt)
{
$this->ensureCanDefine($stmt, self::CLASS_TYPE);
if (isset($stmt->extends)) {
$this->ensureClassExists($this->getFullyQualifiedName($stmt->extends), $stmt);
}
$this->ensureInterfacesExist($stmt->implements, $stmt);
} | [
"protected",
"function",
"validateClassStatement",
"(",
"Class_",
"$",
"stmt",
")",
"{",
"$",
"this",
"->",
"ensureCanDefine",
"(",
"$",
"stmt",
",",
"self",
"::",
"CLASS_TYPE",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"stmt",
"->",
"extends",
")",
")",
"{",
"$",
"this",
"->",
"ensureClassExists",
"(",
"$",
"this",
"->",
"getFullyQualifiedName",
"(",
"$",
"stmt",
"->",
"extends",
")",
",",
"$",
"stmt",
")",
";",
"}",
"$",
"this",
"->",
"ensureInterfacesExist",
"(",
"$",
"stmt",
"->",
"implements",
",",
"$",
"stmt",
")",
";",
"}"
] | Validate a class definition statement.
@param Class_ $stmt | [
"Validate",
"a",
"class",
"definition",
"statement",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L116-L123 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.validateInterfaceStatement | protected function validateInterfaceStatement(Interface_ $stmt)
{
$this->ensureCanDefine($stmt, self::INTERFACE_TYPE);
$this->ensureInterfacesExist($stmt->extends, $stmt);
} | php | protected function validateInterfaceStatement(Interface_ $stmt)
{
$this->ensureCanDefine($stmt, self::INTERFACE_TYPE);
$this->ensureInterfacesExist($stmt->extends, $stmt);
} | [
"protected",
"function",
"validateInterfaceStatement",
"(",
"Interface_",
"$",
"stmt",
")",
"{",
"$",
"this",
"->",
"ensureCanDefine",
"(",
"$",
"stmt",
",",
"self",
"::",
"INTERFACE_TYPE",
")",
";",
"$",
"this",
"->",
"ensureInterfacesExist",
"(",
"$",
"stmt",
"->",
"extends",
",",
"$",
"stmt",
")",
";",
"}"
] | Validate an interface definition statement.
@param Interface_ $stmt | [
"Validate",
"an",
"interface",
"definition",
"statement",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L130-L134 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.validateNewExpression | protected function validateNewExpression(New_ $stmt)
{
// if class name is an expression or an anonymous class, give it a pass for now
if (!$stmt->class instanceof Expr && !$stmt->class instanceof Class_) {
$this->ensureClassExists($this->getFullyQualifiedName($stmt->class), $stmt);
}
} | php | protected function validateNewExpression(New_ $stmt)
{
if (!$stmt->class instanceof Expr && !$stmt->class instanceof Class_) {
$this->ensureClassExists($this->getFullyQualifiedName($stmt->class), $stmt);
}
} | [
"protected",
"function",
"validateNewExpression",
"(",
"New_",
"$",
"stmt",
")",
"{",
"// if class name is an expression or an anonymous class, give it a pass for now",
"if",
"(",
"!",
"$",
"stmt",
"->",
"class",
"instanceof",
"Expr",
"&&",
"!",
"$",
"stmt",
"->",
"class",
"instanceof",
"Class_",
")",
"{",
"$",
"this",
"->",
"ensureClassExists",
"(",
"$",
"this",
"->",
"getFullyQualifiedName",
"(",
"$",
"stmt",
"->",
"class",
")",
",",
"$",
"stmt",
")",
";",
"}",
"}"
] | Validate a `new` expression.
@param New_ $stmt | [
"Validate",
"a",
"new",
"expression",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L151-L157 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.validateClassConstFetchExpression | protected function validateClassConstFetchExpression(ClassConstFetch $stmt)
{
// there is no need to check exists for ::class const for php 5.5 or newer
if (\strtolower($stmt->name) === 'class' && $this->atLeastPhp55) {
return;
}
// if class name is an expression, give it a pass for now
if (!$stmt->class instanceof Expr) {
$this->ensureClassOrInterfaceExists($this->getFullyQualifiedName($stmt->class), $stmt);
}
} | php | protected function validateClassConstFetchExpression(ClassConstFetch $stmt)
{
if (\strtolower($stmt->name) === 'class' && $this->atLeastPhp55) {
return;
}
if (!$stmt->class instanceof Expr) {
$this->ensureClassOrInterfaceExists($this->getFullyQualifiedName($stmt->class), $stmt);
}
} | [
"protected",
"function",
"validateClassConstFetchExpression",
"(",
"ClassConstFetch",
"$",
"stmt",
")",
"{",
"// there is no need to check exists for ::class const for php 5.5 or newer",
"if",
"(",
"\\",
"strtolower",
"(",
"$",
"stmt",
"->",
"name",
")",
"===",
"'class'",
"&&",
"$",
"this",
"->",
"atLeastPhp55",
")",
"{",
"return",
";",
"}",
"// if class name is an expression, give it a pass for now",
"if",
"(",
"!",
"$",
"stmt",
"->",
"class",
"instanceof",
"Expr",
")",
"{",
"$",
"this",
"->",
"ensureClassOrInterfaceExists",
"(",
"$",
"this",
"->",
"getFullyQualifiedName",
"(",
"$",
"stmt",
"->",
"class",
")",
",",
"$",
"stmt",
")",
";",
"}",
"}"
] | Validate a class constant fetch expression's class.
@param ClassConstFetch $stmt | [
"Validate",
"a",
"class",
"constant",
"fetch",
"expression",
"s",
"class",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L164-L175 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.validateStaticCallExpression | protected function validateStaticCallExpression(StaticCall $stmt)
{
// if class name is an expression, give it a pass for now
if (!$stmt->class instanceof Expr) {
$this->ensureMethodExists($this->getFullyQualifiedName($stmt->class), $stmt->name, $stmt);
}
} | php | protected function validateStaticCallExpression(StaticCall $stmt)
{
if (!$stmt->class instanceof Expr) {
$this->ensureMethodExists($this->getFullyQualifiedName($stmt->class), $stmt->name, $stmt);
}
} | [
"protected",
"function",
"validateStaticCallExpression",
"(",
"StaticCall",
"$",
"stmt",
")",
"{",
"// if class name is an expression, give it a pass for now",
"if",
"(",
"!",
"$",
"stmt",
"->",
"class",
"instanceof",
"Expr",
")",
"{",
"$",
"this",
"->",
"ensureMethodExists",
"(",
"$",
"this",
"->",
"getFullyQualifiedName",
"(",
"$",
"stmt",
"->",
"class",
")",
",",
"$",
"stmt",
"->",
"name",
",",
"$",
"stmt",
")",
";",
"}",
"}"
] | Validate a class constant fetch expression's class.
@param StaticCall $stmt | [
"Validate",
"a",
"class",
"constant",
"fetch",
"expression",
"s",
"class",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L182-L188 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.ensureCanDefine | protected function ensureCanDefine(Stmt $stmt, $scopeType = self::CLASS_TYPE)
{
$name = $this->getFullyQualifiedName($stmt->name);
// check for name collisions
$errorType = null;
if ($this->classExists($name)) {
$errorType = self::CLASS_TYPE;
} elseif ($this->interfaceExists($name)) {
$errorType = self::INTERFACE_TYPE;
} elseif ($this->traitExists($name)) {
$errorType = self::TRAIT_TYPE;
}
if ($errorType !== null) {
throw $this->createError(\sprintf('%s named %s already exists', \ucfirst($errorType), $name), $stmt);
}
// Store creation for the rest of this code snippet so we can find local
// issue too
$this->currentScope[\strtolower($name)] = $scopeType;
} | php | protected function ensureCanDefine(Stmt $stmt, $scopeType = self::CLASS_TYPE)
{
$name = $this->getFullyQualifiedName($stmt->name);
$errorType = null;
if ($this->classExists($name)) {
$errorType = self::CLASS_TYPE;
} elseif ($this->interfaceExists($name)) {
$errorType = self::INTERFACE_TYPE;
} elseif ($this->traitExists($name)) {
$errorType = self::TRAIT_TYPE;
}
if ($errorType !== null) {
throw $this->createError(\sprintf('%s named %s already exists', \ucfirst($errorType), $name), $stmt);
}
$this->currentScope[\strtolower($name)] = $scopeType;
} | [
"protected",
"function",
"ensureCanDefine",
"(",
"Stmt",
"$",
"stmt",
",",
"$",
"scopeType",
"=",
"self",
"::",
"CLASS_TYPE",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getFullyQualifiedName",
"(",
"$",
"stmt",
"->",
"name",
")",
";",
"// check for name collisions",
"$",
"errorType",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"classExists",
"(",
"$",
"name",
")",
")",
"{",
"$",
"errorType",
"=",
"self",
"::",
"CLASS_TYPE",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"interfaceExists",
"(",
"$",
"name",
")",
")",
"{",
"$",
"errorType",
"=",
"self",
"::",
"INTERFACE_TYPE",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"traitExists",
"(",
"$",
"name",
")",
")",
"{",
"$",
"errorType",
"=",
"self",
"::",
"TRAIT_TYPE",
";",
"}",
"if",
"(",
"$",
"errorType",
"!==",
"null",
")",
"{",
"throw",
"$",
"this",
"->",
"createError",
"(",
"\\",
"sprintf",
"(",
"'%s named %s already exists'",
",",
"\\",
"ucfirst",
"(",
"$",
"errorType",
")",
",",
"$",
"name",
")",
",",
"$",
"stmt",
")",
";",
"}",
"// Store creation for the rest of this code snippet so we can find local",
"// issue too",
"$",
"this",
"->",
"currentScope",
"[",
"\\",
"strtolower",
"(",
"$",
"name",
")",
"]",
"=",
"$",
"scopeType",
";",
"}"
] | Ensure that no class, interface or trait name collides with a new definition.
@throws FatalErrorException
@param Stmt $stmt
@param string $scopeType | [
"Ensure",
"that",
"no",
"class",
"interface",
"or",
"trait",
"name",
"collides",
"with",
"a",
"new",
"definition",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L198-L219 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.ensureClassExists | protected function ensureClassExists($name, $stmt)
{
if (!$this->classExists($name)) {
throw $this->createError(\sprintf('Class \'%s\' not found', $name), $stmt);
}
} | php | protected function ensureClassExists($name, $stmt)
{
if (!$this->classExists($name)) {
throw $this->createError(\sprintf('Class \'%s\' not found', $name), $stmt);
}
} | [
"protected",
"function",
"ensureClassExists",
"(",
"$",
"name",
",",
"$",
"stmt",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"classExists",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createError",
"(",
"\\",
"sprintf",
"(",
"'Class \\'%s\\' not found'",
",",
"$",
"name",
")",
",",
"$",
"stmt",
")",
";",
"}",
"}"
] | Ensure that a referenced class exists.
@throws FatalErrorException
@param string $name
@param Stmt $stmt | [
"Ensure",
"that",
"a",
"referenced",
"class",
"exists",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L229-L234 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.ensureClassOrInterfaceExists | protected function ensureClassOrInterfaceExists($name, $stmt)
{
if (!$this->classExists($name) && !$this->interfaceExists($name)) {
throw $this->createError(\sprintf('Class \'%s\' not found', $name), $stmt);
}
} | php | protected function ensureClassOrInterfaceExists($name, $stmt)
{
if (!$this->classExists($name) && !$this->interfaceExists($name)) {
throw $this->createError(\sprintf('Class \'%s\' not found', $name), $stmt);
}
} | [
"protected",
"function",
"ensureClassOrInterfaceExists",
"(",
"$",
"name",
",",
"$",
"stmt",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"classExists",
"(",
"$",
"name",
")",
"&&",
"!",
"$",
"this",
"->",
"interfaceExists",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createError",
"(",
"\\",
"sprintf",
"(",
"'Class \\'%s\\' not found'",
",",
"$",
"name",
")",
",",
"$",
"stmt",
")",
";",
"}",
"}"
] | Ensure that a referenced class _or interface_ exists.
@throws FatalErrorException
@param string $name
@param Stmt $stmt | [
"Ensure",
"that",
"a",
"referenced",
"class",
"_or",
"interface_",
"exists",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L244-L249 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.ensureClassOrTraitExists | protected function ensureClassOrTraitExists($name, $stmt)
{
if (!$this->classExists($name) && !$this->traitExists($name)) {
throw $this->createError(\sprintf('Class \'%s\' not found', $name), $stmt);
}
} | php | protected function ensureClassOrTraitExists($name, $stmt)
{
if (!$this->classExists($name) && !$this->traitExists($name)) {
throw $this->createError(\sprintf('Class \'%s\' not found', $name), $stmt);
}
} | [
"protected",
"function",
"ensureClassOrTraitExists",
"(",
"$",
"name",
",",
"$",
"stmt",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"classExists",
"(",
"$",
"name",
")",
"&&",
"!",
"$",
"this",
"->",
"traitExists",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createError",
"(",
"\\",
"sprintf",
"(",
"'Class \\'%s\\' not found'",
",",
"$",
"name",
")",
",",
"$",
"stmt",
")",
";",
"}",
"}"
] | Ensure that a referenced class _or trait_ exists.
@throws FatalErrorException
@param string $name
@param Stmt $stmt | [
"Ensure",
"that",
"a",
"referenced",
"class",
"_or",
"trait_",
"exists",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L259-L264 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.ensureMethodExists | protected function ensureMethodExists($class, $name, $stmt)
{
$this->ensureClassOrTraitExists($class, $stmt);
// let's pretend all calls to self, parent and static are valid
if (\in_array(\strtolower($class), ['self', 'parent', 'static'])) {
return;
}
// ... and all calls to classes defined right now
if ($this->findInScope($class) === self::CLASS_TYPE) {
return;
}
// if method name is an expression, give it a pass for now
if ($name instanceof Expr) {
return;
}
if (!\method_exists($class, $name) && !\method_exists($class, '__callStatic')) {
throw $this->createError(\sprintf('Call to undefined method %s::%s()', $class, $name), $stmt);
}
} | php | protected function ensureMethodExists($class, $name, $stmt)
{
$this->ensureClassOrTraitExists($class, $stmt);
if (\in_array(\strtolower($class), ['self', 'parent', 'static'])) {
return;
}
if ($this->findInScope($class) === self::CLASS_TYPE) {
return;
}
if ($name instanceof Expr) {
return;
}
if (!\method_exists($class, $name) && !\method_exists($class, '__callStatic')) {
throw $this->createError(\sprintf('Call to undefined method %s::%s()', $class, $name), $stmt);
}
} | [
"protected",
"function",
"ensureMethodExists",
"(",
"$",
"class",
",",
"$",
"name",
",",
"$",
"stmt",
")",
"{",
"$",
"this",
"->",
"ensureClassOrTraitExists",
"(",
"$",
"class",
",",
"$",
"stmt",
")",
";",
"// let's pretend all calls to self, parent and static are valid",
"if",
"(",
"\\",
"in_array",
"(",
"\\",
"strtolower",
"(",
"$",
"class",
")",
",",
"[",
"'self'",
",",
"'parent'",
",",
"'static'",
"]",
")",
")",
"{",
"return",
";",
"}",
"// ... and all calls to classes defined right now",
"if",
"(",
"$",
"this",
"->",
"findInScope",
"(",
"$",
"class",
")",
"===",
"self",
"::",
"CLASS_TYPE",
")",
"{",
"return",
";",
"}",
"// if method name is an expression, give it a pass for now",
"if",
"(",
"$",
"name",
"instanceof",
"Expr",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"\\",
"method_exists",
"(",
"$",
"class",
",",
"$",
"name",
")",
"&&",
"!",
"\\",
"method_exists",
"(",
"$",
"class",
",",
"'__callStatic'",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createError",
"(",
"\\",
"sprintf",
"(",
"'Call to undefined method %s::%s()'",
",",
"$",
"class",
",",
"$",
"name",
")",
",",
"$",
"stmt",
")",
";",
"}",
"}"
] | Ensure that a statically called method exists.
@throws FatalErrorException
@param string $class
@param string $name
@param Stmt $stmt | [
"Ensure",
"that",
"a",
"statically",
"called",
"method",
"exists",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L275-L297 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.ensureInterfacesExist | protected function ensureInterfacesExist($interfaces, $stmt)
{
foreach ($interfaces as $interface) {
/** @var string $name */
$name = $this->getFullyQualifiedName($interface);
if (!$this->interfaceExists($name)) {
throw $this->createError(\sprintf('Interface \'%s\' not found', $name), $stmt);
}
}
} | php | protected function ensureInterfacesExist($interfaces, $stmt)
{
foreach ($interfaces as $interface) {
$name = $this->getFullyQualifiedName($interface);
if (!$this->interfaceExists($name)) {
throw $this->createError(\sprintf('Interface \'%s\' not found', $name), $stmt);
}
}
} | [
"protected",
"function",
"ensureInterfacesExist",
"(",
"$",
"interfaces",
",",
"$",
"stmt",
")",
"{",
"foreach",
"(",
"$",
"interfaces",
"as",
"$",
"interface",
")",
"{",
"/** @var string $name */",
"$",
"name",
"=",
"$",
"this",
"->",
"getFullyQualifiedName",
"(",
"$",
"interface",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"interfaceExists",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createError",
"(",
"\\",
"sprintf",
"(",
"'Interface \\'%s\\' not found'",
",",
"$",
"name",
")",
",",
"$",
"stmt",
")",
";",
"}",
"}",
"}"
] | Ensure that a referenced interface exists.
@throws FatalErrorException
@param Interface_[] $interfaces
@param Stmt $stmt | [
"Ensure",
"that",
"a",
"referenced",
"interface",
"exists",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L307-L316 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.getScopeType | protected function getScopeType(Stmt $stmt)
{
if ($stmt instanceof Class_) {
return self::CLASS_TYPE;
} elseif ($stmt instanceof Interface_) {
return self::INTERFACE_TYPE;
} elseif ($stmt instanceof Trait_) {
return self::TRAIT_TYPE;
}
} | php | protected function getScopeType(Stmt $stmt)
{
if ($stmt instanceof Class_) {
return self::CLASS_TYPE;
} elseif ($stmt instanceof Interface_) {
return self::INTERFACE_TYPE;
} elseif ($stmt instanceof Trait_) {
return self::TRAIT_TYPE;
}
} | [
"protected",
"function",
"getScopeType",
"(",
"Stmt",
"$",
"stmt",
")",
"{",
"if",
"(",
"$",
"stmt",
"instanceof",
"Class_",
")",
"{",
"return",
"self",
"::",
"CLASS_TYPE",
";",
"}",
"elseif",
"(",
"$",
"stmt",
"instanceof",
"Interface_",
")",
"{",
"return",
"self",
"::",
"INTERFACE_TYPE",
";",
"}",
"elseif",
"(",
"$",
"stmt",
"instanceof",
"Trait_",
")",
"{",
"return",
"self",
"::",
"TRAIT_TYPE",
";",
"}",
"}"
] | Get a symbol type key for storing in the scope name cache.
@deprecated No longer used. Scope type should be passed into ensureCanDefine directly.
@codeCoverageIgnore
@param Stmt $stmt
@return string | [
"Get",
"a",
"symbol",
"type",
"key",
"for",
"storing",
"in",
"the",
"scope",
"name",
"cache",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L328-L337 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.classExists | protected function classExists($name)
{
// Give `self`, `static` and `parent` a pass. This will actually let
// some errors through, since we're not checking whether the keyword is
// being used in a class scope.
if (\in_array(\strtolower($name), ['self', 'static', 'parent'])) {
return true;
}
return \class_exists($name) || $this->findInScope($name) === self::CLASS_TYPE;
} | php | protected function classExists($name)
{
if (\in_array(\strtolower($name), ['self', 'static', 'parent'])) {
return true;
}
return \class_exists($name) || $this->findInScope($name) === self::CLASS_TYPE;
} | [
"protected",
"function",
"classExists",
"(",
"$",
"name",
")",
"{",
"// Give `self`, `static` and `parent` a pass. This will actually let",
"// some errors through, since we're not checking whether the keyword is",
"// being used in a class scope.",
"if",
"(",
"\\",
"in_array",
"(",
"\\",
"strtolower",
"(",
"$",
"name",
")",
",",
"[",
"'self'",
",",
"'static'",
",",
"'parent'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"\\",
"class_exists",
"(",
"$",
"name",
")",
"||",
"$",
"this",
"->",
"findInScope",
"(",
"$",
"name",
")",
"===",
"self",
"::",
"CLASS_TYPE",
";",
"}"
] | Check whether a class exists, or has been defined in the current code snippet.
Gives `self`, `static` and `parent` a free pass.
@param string $name
@return bool | [
"Check",
"whether",
"a",
"class",
"exists",
"or",
"has",
"been",
"defined",
"in",
"the",
"current",
"code",
"snippet",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L348-L358 |
bobthecow/psysh | src/CodeCleaner/ValidClassNamePass.php | ValidClassNamePass.findInScope | protected function findInScope($name)
{
$name = \strtolower($name);
if (isset($this->currentScope[$name])) {
return $this->currentScope[$name];
}
} | php | protected function findInScope($name)
{
$name = \strtolower($name);
if (isset($this->currentScope[$name])) {
return $this->currentScope[$name];
}
} | [
"protected",
"function",
"findInScope",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"\\",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"currentScope",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"currentScope",
"[",
"$",
"name",
"]",
";",
"}",
"}"
] | Find a symbol in the current code snippet scope.
@param string $name
@return string|null | [
"Find",
"a",
"symbol",
"in",
"the",
"current",
"code",
"snippet",
"scope",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidClassNamePass.php#L391-L397 |
bobthecow/psysh | src/Sudo.php | Sudo.fetchProperty | public static function fetchProperty($object, $property)
{
$refl = new \ReflectionObject($object);
$prop = $refl->getProperty($property);
$prop->setAccessible(true);
return $prop->getValue($object);
} | php | public static function fetchProperty($object, $property)
{
$refl = new \ReflectionObject($object);
$prop = $refl->getProperty($property);
$prop->setAccessible(true);
return $prop->getValue($object);
} | [
"public",
"static",
"function",
"fetchProperty",
"(",
"$",
"object",
",",
"$",
"property",
")",
"{",
"$",
"refl",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"object",
")",
";",
"$",
"prop",
"=",
"$",
"refl",
"->",
"getProperty",
"(",
"$",
"property",
")",
";",
"$",
"prop",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"prop",
"->",
"getValue",
"(",
"$",
"object",
")",
";",
"}"
] | Fetch a property of an object, bypassing visibility restrictions.
@param object $object
@param string $property property name
@return mixed Value of $object->property | [
"Fetch",
"a",
"property",
"of",
"an",
"object",
"bypassing",
"visibility",
"restrictions",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Sudo.php#L28-L35 |
bobthecow/psysh | src/Sudo.php | Sudo.assignProperty | public static function assignProperty($object, $property, $value)
{
$refl = new \ReflectionObject($object);
$prop = $refl->getProperty($property);
$prop->setAccessible(true);
$prop->setValue($object, $value);
return $value;
} | php | public static function assignProperty($object, $property, $value)
{
$refl = new \ReflectionObject($object);
$prop = $refl->getProperty($property);
$prop->setAccessible(true);
$prop->setValue($object, $value);
return $value;
} | [
"public",
"static",
"function",
"assignProperty",
"(",
"$",
"object",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"$",
"refl",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"object",
")",
";",
"$",
"prop",
"=",
"$",
"refl",
"->",
"getProperty",
"(",
"$",
"property",
")",
";",
"$",
"prop",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"prop",
"->",
"setValue",
"(",
"$",
"object",
",",
"$",
"value",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Assign the value of a property of an object, bypassing visibility restrictions.
@param object $object
@param string $property property name
@param mixed $value
@return mixed Value of $object->property | [
"Assign",
"the",
"value",
"of",
"a",
"property",
"of",
"an",
"object",
"bypassing",
"visibility",
"restrictions",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Sudo.php#L46-L54 |
bobthecow/psysh | src/Sudo.php | Sudo.callMethod | public static function callMethod($object, $method, $args = null)
{
$args = \func_get_args();
$object = \array_shift($args);
$method = \array_shift($args);
$refl = new \ReflectionObject($object);
$reflMethod = $refl->getMethod($method);
$reflMethod->setAccessible(true);
return $reflMethod->invokeArgs($object, $args);
} | php | public static function callMethod($object, $method, $args = null)
{
$args = \func_get_args();
$object = \array_shift($args);
$method = \array_shift($args);
$refl = new \ReflectionObject($object);
$reflMethod = $refl->getMethod($method);
$reflMethod->setAccessible(true);
return $reflMethod->invokeArgs($object, $args);
} | [
"public",
"static",
"function",
"callMethod",
"(",
"$",
"object",
",",
"$",
"method",
",",
"$",
"args",
"=",
"null",
")",
"{",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"$",
"object",
"=",
"\\",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"method",
"=",
"\\",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"refl",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"object",
")",
";",
"$",
"reflMethod",
"=",
"$",
"refl",
"->",
"getMethod",
"(",
"$",
"method",
")",
";",
"$",
"reflMethod",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"reflMethod",
"->",
"invokeArgs",
"(",
"$",
"object",
",",
"$",
"args",
")",
";",
"}"
] | Call a method on an object, bypassing visibility restrictions.
@param object $object
@param string $method method name
@param mixed $args...
@return mixed | [
"Call",
"a",
"method",
"on",
"an",
"object",
"bypassing",
"visibility",
"restrictions",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Sudo.php#L65-L76 |
bobthecow/psysh | src/Sudo.php | Sudo.fetchStaticProperty | public static function fetchStaticProperty($class, $property)
{
$refl = new \ReflectionClass($class);
$prop = $refl->getProperty($property);
$prop->setAccessible(true);
return $prop->getValue();
} | php | public static function fetchStaticProperty($class, $property)
{
$refl = new \ReflectionClass($class);
$prop = $refl->getProperty($property);
$prop->setAccessible(true);
return $prop->getValue();
} | [
"public",
"static",
"function",
"fetchStaticProperty",
"(",
"$",
"class",
",",
"$",
"property",
")",
"{",
"$",
"refl",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"prop",
"=",
"$",
"refl",
"->",
"getProperty",
"(",
"$",
"property",
")",
";",
"$",
"prop",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"prop",
"->",
"getValue",
"(",
")",
";",
"}"
] | Fetch a property of a class, bypassing visibility restrictions.
@param string|object $class class name or instance
@param string $property property name
@return mixed Value of $class::$property | [
"Fetch",
"a",
"property",
"of",
"a",
"class",
"bypassing",
"visibility",
"restrictions",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Sudo.php#L86-L93 |
bobthecow/psysh | src/Sudo.php | Sudo.assignStaticProperty | public static function assignStaticProperty($class, $property, $value)
{
$refl = new \ReflectionClass($class);
$prop = $refl->getProperty($property);
$prop->setAccessible(true);
$prop->setValue($value);
return $value;
} | php | public static function assignStaticProperty($class, $property, $value)
{
$refl = new \ReflectionClass($class);
$prop = $refl->getProperty($property);
$prop->setAccessible(true);
$prop->setValue($value);
return $value;
} | [
"public",
"static",
"function",
"assignStaticProperty",
"(",
"$",
"class",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"$",
"refl",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"prop",
"=",
"$",
"refl",
"->",
"getProperty",
"(",
"$",
"property",
")",
";",
"$",
"prop",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"prop",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Assign the value of a static property of a class, bypassing visibility restrictions.
@param string|object $class class name or instance
@param string $property property name
@param mixed $value
@return mixed Value of $class::$property | [
"Assign",
"the",
"value",
"of",
"a",
"static",
"property",
"of",
"a",
"class",
"bypassing",
"visibility",
"restrictions",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Sudo.php#L104-L112 |
bobthecow/psysh | src/Sudo.php | Sudo.callStatic | public static function callStatic($class, $method, $args = null)
{
$args = \func_get_args();
$class = \array_shift($args);
$method = \array_shift($args);
$refl = new \ReflectionClass($class);
$reflMethod = $refl->getMethod($method);
$reflMethod->setAccessible(true);
return $reflMethod->invokeArgs(null, $args);
} | php | public static function callStatic($class, $method, $args = null)
{
$args = \func_get_args();
$class = \array_shift($args);
$method = \array_shift($args);
$refl = new \ReflectionClass($class);
$reflMethod = $refl->getMethod($method);
$reflMethod->setAccessible(true);
return $reflMethod->invokeArgs(null, $args);
} | [
"public",
"static",
"function",
"callStatic",
"(",
"$",
"class",
",",
"$",
"method",
",",
"$",
"args",
"=",
"null",
")",
"{",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"$",
"class",
"=",
"\\",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"method",
"=",
"\\",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"refl",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"reflMethod",
"=",
"$",
"refl",
"->",
"getMethod",
"(",
"$",
"method",
")",
";",
"$",
"reflMethod",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"reflMethod",
"->",
"invokeArgs",
"(",
"null",
",",
"$",
"args",
")",
";",
"}"
] | Call a static method on a class, bypassing visibility restrictions.
@param string|object $class class name or instance
@param string $method method name
@param mixed $args...
@return mixed | [
"Call",
"a",
"static",
"method",
"on",
"a",
"class",
"bypassing",
"visibility",
"restrictions",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Sudo.php#L123-L134 |
bobthecow/psysh | src/TabCompletion/Matcher/CommandsMatcher.php | CommandsMatcher.setCommands | public function setCommands(array $commands)
{
$names = [];
foreach ($commands as $command) {
$names = \array_merge([$command->getName()], $names);
$names = \array_merge($command->getAliases(), $names);
}
$this->commands = $names;
} | php | public function setCommands(array $commands)
{
$names = [];
foreach ($commands as $command) {
$names = \array_merge([$command->getName()], $names);
$names = \array_merge($command->getAliases(), $names);
}
$this->commands = $names;
} | [
"public",
"function",
"setCommands",
"(",
"array",
"$",
"commands",
")",
"{",
"$",
"names",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"command",
")",
"{",
"$",
"names",
"=",
"\\",
"array_merge",
"(",
"[",
"$",
"command",
"->",
"getName",
"(",
")",
"]",
",",
"$",
"names",
")",
";",
"$",
"names",
"=",
"\\",
"array_merge",
"(",
"$",
"command",
"->",
"getAliases",
"(",
")",
",",
"$",
"names",
")",
";",
"}",
"$",
"this",
"->",
"commands",
"=",
"$",
"names",
";",
"}"
] | Set Commands for completion.
@param Command[] $commands | [
"Set",
"Commands",
"for",
"completion",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/CommandsMatcher.php#L44-L52 |
bobthecow/psysh | src/TabCompletion/Matcher/CommandsMatcher.php | CommandsMatcher.matchCommand | protected function matchCommand($name)
{
foreach ($this->commands as $cmd) {
if ($this->startsWith($name, $cmd)) {
return true;
}
}
return false;
} | php | protected function matchCommand($name)
{
foreach ($this->commands as $cmd) {
if ($this->startsWith($name, $cmd)) {
return true;
}
}
return false;
} | [
"protected",
"function",
"matchCommand",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"commands",
"as",
"$",
"cmd",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"startsWith",
"(",
"$",
"name",
",",
"$",
"cmd",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check whether input matches a defined command.
@param string $name
@return bool | [
"Check",
"whether",
"input",
"matches",
"a",
"defined",
"command",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/CommandsMatcher.php#L73-L82 |
bobthecow/psysh | src/TabCompletion/Matcher/CommandsMatcher.php | CommandsMatcher.getMatches | public function getMatches(array $tokens, array $info = [])
{
$input = $this->getInput($tokens);
return \array_filter($this->commands, function ($command) use ($input) {
return AbstractMatcher::startsWith($input, $command);
});
} | php | public function getMatches(array $tokens, array $info = [])
{
$input = $this->getInput($tokens);
return \array_filter($this->commands, function ($command) use ($input) {
return AbstractMatcher::startsWith($input, $command);
});
} | [
"public",
"function",
"getMatches",
"(",
"array",
"$",
"tokens",
",",
"array",
"$",
"info",
"=",
"[",
"]",
")",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"getInput",
"(",
"$",
"tokens",
")",
";",
"return",
"\\",
"array_filter",
"(",
"$",
"this",
"->",
"commands",
",",
"function",
"(",
"$",
"command",
")",
"use",
"(",
"$",
"input",
")",
"{",
"return",
"AbstractMatcher",
"::",
"startsWith",
"(",
"$",
"input",
",",
"$",
"command",
")",
";",
"}",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/CommandsMatcher.php#L87-L94 |
bobthecow/psysh | src/TabCompletion/Matcher/CommandsMatcher.php | CommandsMatcher.hasMatched | public function hasMatched(array $tokens)
{
/* $openTag */ \array_shift($tokens);
$command = \array_shift($tokens);
switch (true) {
case self::tokenIs($command, self::T_STRING) &&
!$this->isCommand($command[1]) &&
$this->matchCommand($command[1]) &&
empty($tokens):
return true;
}
return false;
} | php | public function hasMatched(array $tokens)
{
\array_shift($tokens);
$command = \array_shift($tokens);
switch (true) {
case self::tokenIs($command, self::T_STRING) &&
!$this->isCommand($command[1]) &&
$this->matchCommand($command[1]) &&
empty($tokens):
return true;
}
return false;
} | [
"public",
"function",
"hasMatched",
"(",
"array",
"$",
"tokens",
")",
"{",
"/* $openTag */",
"\\",
"array_shift",
"(",
"$",
"tokens",
")",
";",
"$",
"command",
"=",
"\\",
"array_shift",
"(",
"$",
"tokens",
")",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"self",
"::",
"tokenIs",
"(",
"$",
"command",
",",
"self",
"::",
"T_STRING",
")",
"&&",
"!",
"$",
"this",
"->",
"isCommand",
"(",
"$",
"command",
"[",
"1",
"]",
")",
"&&",
"$",
"this",
"->",
"matchCommand",
"(",
"$",
"command",
"[",
"1",
"]",
")",
"&&",
"empty",
"(",
"$",
"tokens",
")",
":",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/CommandsMatcher.php#L99-L113 |
bobthecow/psysh | src/Reflection/ReflectionClassConstant.php | ReflectionClassConstant.export | public static function export($class, $name, $return = false)
{
$refl = new self($class, $name);
$value = $refl->getValue();
$str = \sprintf('Constant [ public %s %s ] { %s }', \gettype($value), $refl->getName(), $value);
if ($return) {
return $str;
}
echo $str . "\n";
} | php | public static function export($class, $name, $return = false)
{
$refl = new self($class, $name);
$value = $refl->getValue();
$str = \sprintf('Constant [ public %s %s ] { %s }', \gettype($value), $refl->getName(), $value);
if ($return) {
return $str;
}
echo $str . "\n";
} | [
"public",
"static",
"function",
"export",
"(",
"$",
"class",
",",
"$",
"name",
",",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"refl",
"=",
"new",
"self",
"(",
"$",
"class",
",",
"$",
"name",
")",
";",
"$",
"value",
"=",
"$",
"refl",
"->",
"getValue",
"(",
")",
";",
"$",
"str",
"=",
"\\",
"sprintf",
"(",
"'Constant [ public %s %s ] { %s }'",
",",
"\\",
"gettype",
"(",
"$",
"value",
")",
",",
"$",
"refl",
"->",
"getName",
"(",
")",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"str",
";",
"}",
"echo",
"$",
"str",
".",
"\"\\n\"",
";",
"}"
] | Exports a reflection.
@param string|object $class
@param string $name
@param bool $return pass true to return the export, as opposed to emitting it
@return null|string | [
"Exports",
"a",
"reflection",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Reflection/ReflectionClassConstant.php#L57-L69 |
bobthecow/psysh | src/Reflection/ReflectionClassConstant.php | ReflectionClassConstant.getDeclaringClass | public function getDeclaringClass()
{
$parent = $this->class;
// Since we don't have real reflection constants, we can't see where
// it's actually defined. Let's check for a constant that is also
// available on the parent class which has exactly the same value.
//
// While this isn't _technically_ correct, it's prolly close enough.
do {
$class = $parent;
$parent = $class->getParentClass();
} while ($parent && $parent->hasConstant($this->name) && $parent->getConstant($this->name) === $this->value);
return $class;
} | php | public function getDeclaringClass()
{
$parent = $this->class;
do {
$class = $parent;
$parent = $class->getParentClass();
} while ($parent && $parent->hasConstant($this->name) && $parent->getConstant($this->name) === $this->value);
return $class;
} | [
"public",
"function",
"getDeclaringClass",
"(",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"class",
";",
"// Since we don't have real reflection constants, we can't see where",
"// it's actually defined. Let's check for a constant that is also",
"// available on the parent class which has exactly the same value.",
"//",
"// While this isn't _technically_ correct, it's prolly close enough.",
"do",
"{",
"$",
"class",
"=",
"$",
"parent",
";",
"$",
"parent",
"=",
"$",
"class",
"->",
"getParentClass",
"(",
")",
";",
"}",
"while",
"(",
"$",
"parent",
"&&",
"$",
"parent",
"->",
"hasConstant",
"(",
"$",
"this",
"->",
"name",
")",
"&&",
"$",
"parent",
"->",
"getConstant",
"(",
"$",
"this",
"->",
"name",
")",
"===",
"$",
"this",
"->",
"value",
")",
";",
"return",
"$",
"class",
";",
"}"
] | Gets the declaring class.
@return \ReflectionClass | [
"Gets",
"the",
"declaring",
"class",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Reflection/ReflectionClassConstant.php#L76-L91 |
bobthecow/psysh | src/Command/ReflectingCommand.php | ReflectingCommand.getTarget | protected function getTarget($valueName)
{
$valueName = \trim($valueName);
$matches = [];
switch (true) {
case \preg_match(self::CLASS_OR_FUNC, $valueName, $matches):
return [$this->resolveName($matches[0], true), null, 0];
case \preg_match(self::CLASS_MEMBER, $valueName, $matches):
return [$this->resolveName($matches[1]), $matches[2], Mirror::CONSTANT | Mirror::METHOD];
case \preg_match(self::CLASS_STATIC, $valueName, $matches):
return [$this->resolveName($matches[1]), $matches[2], Mirror::STATIC_PROPERTY | Mirror::PROPERTY];
case \preg_match(self::INSTANCE_MEMBER, $valueName, $matches):
if ($matches[2] === '->') {
$kind = Mirror::METHOD | Mirror::PROPERTY;
} else {
$kind = Mirror::CONSTANT | Mirror::METHOD;
}
return [$this->resolveObject($matches[1]), $matches[3], $kind];
default:
return [$this->resolveObject($valueName), null, 0];
}
} | php | protected function getTarget($valueName)
{
$valueName = \trim($valueName);
$matches = [];
switch (true) {
case \preg_match(self::CLASS_OR_FUNC, $valueName, $matches):
return [$this->resolveName($matches[0], true), null, 0];
case \preg_match(self::CLASS_MEMBER, $valueName, $matches):
return [$this->resolveName($matches[1]), $matches[2], Mirror::CONSTANT | Mirror::METHOD];
case \preg_match(self::CLASS_STATIC, $valueName, $matches):
return [$this->resolveName($matches[1]), $matches[2], Mirror::STATIC_PROPERTY | Mirror::PROPERTY];
case \preg_match(self::INSTANCE_MEMBER, $valueName, $matches):
if ($matches[2] === '->') {
$kind = Mirror::METHOD | Mirror::PROPERTY;
} else {
$kind = Mirror::CONSTANT | Mirror::METHOD;
}
return [$this->resolveObject($matches[1]), $matches[3], $kind];
default:
return [$this->resolveObject($valueName), null, 0];
}
} | [
"protected",
"function",
"getTarget",
"(",
"$",
"valueName",
")",
"{",
"$",
"valueName",
"=",
"\\",
"trim",
"(",
"$",
"valueName",
")",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"\\",
"preg_match",
"(",
"self",
"::",
"CLASS_OR_FUNC",
",",
"$",
"valueName",
",",
"$",
"matches",
")",
":",
"return",
"[",
"$",
"this",
"->",
"resolveName",
"(",
"$",
"matches",
"[",
"0",
"]",
",",
"true",
")",
",",
"null",
",",
"0",
"]",
";",
"case",
"\\",
"preg_match",
"(",
"self",
"::",
"CLASS_MEMBER",
",",
"$",
"valueName",
",",
"$",
"matches",
")",
":",
"return",
"[",
"$",
"this",
"->",
"resolveName",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
",",
"$",
"matches",
"[",
"2",
"]",
",",
"Mirror",
"::",
"CONSTANT",
"|",
"Mirror",
"::",
"METHOD",
"]",
";",
"case",
"\\",
"preg_match",
"(",
"self",
"::",
"CLASS_STATIC",
",",
"$",
"valueName",
",",
"$",
"matches",
")",
":",
"return",
"[",
"$",
"this",
"->",
"resolveName",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
",",
"$",
"matches",
"[",
"2",
"]",
",",
"Mirror",
"::",
"STATIC_PROPERTY",
"|",
"Mirror",
"::",
"PROPERTY",
"]",
";",
"case",
"\\",
"preg_match",
"(",
"self",
"::",
"INSTANCE_MEMBER",
",",
"$",
"valueName",
",",
"$",
"matches",
")",
":",
"if",
"(",
"$",
"matches",
"[",
"2",
"]",
"===",
"'->'",
")",
"{",
"$",
"kind",
"=",
"Mirror",
"::",
"METHOD",
"|",
"Mirror",
"::",
"PROPERTY",
";",
"}",
"else",
"{",
"$",
"kind",
"=",
"Mirror",
"::",
"CONSTANT",
"|",
"Mirror",
"::",
"METHOD",
";",
"}",
"return",
"[",
"$",
"this",
"->",
"resolveObject",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
",",
"$",
"matches",
"[",
"3",
"]",
",",
"$",
"kind",
"]",
";",
"default",
":",
"return",
"[",
"$",
"this",
"->",
"resolveObject",
"(",
"$",
"valueName",
")",
",",
"null",
",",
"0",
"]",
";",
"}",
"}"
] | Get the target for a value.
@throws \InvalidArgumentException when the value specified can't be resolved
@param string $valueName Function, class, variable, constant, method or property name
@return array (class or instance name, member name, kind) | [
"Get",
"the",
"target",
"for",
"a",
"value",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ReflectingCommand.php#L57-L83 |
bobthecow/psysh | src/Command/ReflectingCommand.php | ReflectingCommand.resolveName | protected function resolveName($name, $includeFunctions = false)
{
$shell = $this->getApplication();
// While not *technically* 100% accurate, let's treat `self` and `static` as equivalent.
if (\in_array(\strtolower($name), ['self', 'static'])) {
if ($boundClass = $shell->getBoundClass()) {
return $boundClass;
}
if ($boundObject = $shell->getBoundObject()) {
return \get_class($boundObject);
}
$msg = \sprintf('Cannot use "%s" when no class scope is active', \strtolower($name));
throw new ErrorException($msg, 0, E_USER_ERROR, "eval()'d code", 1);
}
if (\substr($name, 0, 1) === '\\') {
return $name;
}
if ($namespace = $shell->getNamespace()) {
$fullName = $namespace . '\\' . $name;
if (\class_exists($fullName) || \interface_exists($fullName) || ($includeFunctions && \function_exists($fullName))) {
return $fullName;
}
}
return $name;
} | php | protected function resolveName($name, $includeFunctions = false)
{
$shell = $this->getApplication();
if (\in_array(\strtolower($name), ['self', 'static'])) {
if ($boundClass = $shell->getBoundClass()) {
return $boundClass;
}
if ($boundObject = $shell->getBoundObject()) {
return \get_class($boundObject);
}
$msg = \sprintf('Cannot use "%s" when no class scope is active', \strtolower($name));
throw new ErrorException($msg, 0, E_USER_ERROR, "eval()'d code", 1);
}
if (\substr($name, 0, 1) === '\\') {
return $name;
}
if ($namespace = $shell->getNamespace()) {
$fullName = $namespace . '\\' . $name;
if (\class_exists($fullName) || \interface_exists($fullName) || ($includeFunctions && \function_exists($fullName))) {
return $fullName;
}
}
return $name;
} | [
"protected",
"function",
"resolveName",
"(",
"$",
"name",
",",
"$",
"includeFunctions",
"=",
"false",
")",
"{",
"$",
"shell",
"=",
"$",
"this",
"->",
"getApplication",
"(",
")",
";",
"// While not *technically* 100% accurate, let's treat `self` and `static` as equivalent.",
"if",
"(",
"\\",
"in_array",
"(",
"\\",
"strtolower",
"(",
"$",
"name",
")",
",",
"[",
"'self'",
",",
"'static'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"boundClass",
"=",
"$",
"shell",
"->",
"getBoundClass",
"(",
")",
")",
"{",
"return",
"$",
"boundClass",
";",
"}",
"if",
"(",
"$",
"boundObject",
"=",
"$",
"shell",
"->",
"getBoundObject",
"(",
")",
")",
"{",
"return",
"\\",
"get_class",
"(",
"$",
"boundObject",
")",
";",
"}",
"$",
"msg",
"=",
"\\",
"sprintf",
"(",
"'Cannot use \"%s\" when no class scope is active'",
",",
"\\",
"strtolower",
"(",
"$",
"name",
")",
")",
";",
"throw",
"new",
"ErrorException",
"(",
"$",
"msg",
",",
"0",
",",
"E_USER_ERROR",
",",
"\"eval()'d code\"",
",",
"1",
")",
";",
"}",
"if",
"(",
"\\",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"1",
")",
"===",
"'\\\\'",
")",
"{",
"return",
"$",
"name",
";",
"}",
"if",
"(",
"$",
"namespace",
"=",
"$",
"shell",
"->",
"getNamespace",
"(",
")",
")",
"{",
"$",
"fullName",
"=",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"name",
";",
"if",
"(",
"\\",
"class_exists",
"(",
"$",
"fullName",
")",
"||",
"\\",
"interface_exists",
"(",
"$",
"fullName",
")",
"||",
"(",
"$",
"includeFunctions",
"&&",
"\\",
"function_exists",
"(",
"$",
"fullName",
")",
")",
")",
"{",
"return",
"$",
"fullName",
";",
"}",
"}",
"return",
"$",
"name",
";",
"}"
] | Resolve a class or function name (with the current shell namespace).
@throws ErrorException when `self` or `static` is used in a non-class scope
@param string $name
@param bool $includeFunctions (default: false)
@return string | [
"Resolve",
"a",
"class",
"or",
"function",
"name",
"(",
"with",
"the",
"current",
"shell",
"namespace",
")",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ReflectingCommand.php#L95-L126 |
bobthecow/psysh | src/Command/ReflectingCommand.php | ReflectingCommand.getTargetAndReflector | protected function getTargetAndReflector($valueName)
{
list($value, $member, $kind) = $this->getTarget($valueName);
return [$value, Mirror::get($value, $member, $kind)];
} | php | protected function getTargetAndReflector($valueName)
{
list($value, $member, $kind) = $this->getTarget($valueName);
return [$value, Mirror::get($value, $member, $kind)];
} | [
"protected",
"function",
"getTargetAndReflector",
"(",
"$",
"valueName",
")",
"{",
"list",
"(",
"$",
"value",
",",
"$",
"member",
",",
"$",
"kind",
")",
"=",
"$",
"this",
"->",
"getTarget",
"(",
"$",
"valueName",
")",
";",
"return",
"[",
"$",
"value",
",",
"Mirror",
"::",
"get",
"(",
"$",
"value",
",",
"$",
"member",
",",
"$",
"kind",
")",
"]",
";",
"}"
] | Get a Reflector and documentation for a function, class or instance, constant, method or property.
@param string $valueName Function, class, variable, constant, method or property name
@return array (value, Reflector) | [
"Get",
"a",
"Reflector",
"and",
"documentation",
"for",
"a",
"function",
"class",
"or",
"instance",
"constant",
"method",
"or",
"property",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ReflectingCommand.php#L135-L140 |
bobthecow/psysh | src/Command/ReflectingCommand.php | ReflectingCommand.resolveCode | protected function resolveCode($code)
{
try {
$value = $this->getApplication()->execute($code, true);
} catch (\Exception $e) {
// Swallow all exceptions?
}
if (!isset($value) || $value instanceof NoReturnValue) {
throw new RuntimeException('Unknown target: ' . $code);
}
return $value;
} | php | protected function resolveCode($code)
{
try {
$value = $this->getApplication()->execute($code, true);
} catch (\Exception $e) {
}
if (!isset($value) || $value instanceof NoReturnValue) {
throw new RuntimeException('Unknown target: ' . $code);
}
return $value;
} | [
"protected",
"function",
"resolveCode",
"(",
"$",
"code",
")",
"{",
"try",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"execute",
"(",
"$",
"code",
",",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// Swallow all exceptions?",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"instanceof",
"NoReturnValue",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Unknown target: '",
".",
"$",
"code",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Resolve code to a value in the current scope.
@throws RuntimeException when the code does not return a value in the current scope
@param string $code
@return mixed Variable value | [
"Resolve",
"code",
"to",
"a",
"value",
"in",
"the",
"current",
"scope",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ReflectingCommand.php#L151-L164 |
bobthecow/psysh | src/Command/ReflectingCommand.php | ReflectingCommand.resolveObject | private function resolveObject($code)
{
$value = $this->resolveCode($code);
if (!\is_object($value)) {
throw new RuntimeException('Unable to inspect a non-object');
}
return $value;
} | php | private function resolveObject($code)
{
$value = $this->resolveCode($code);
if (!\is_object($value)) {
throw new RuntimeException('Unable to inspect a non-object');
}
return $value;
} | [
"private",
"function",
"resolveObject",
"(",
"$",
"code",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"resolveCode",
"(",
"$",
"code",
")",
";",
"if",
"(",
"!",
"\\",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Unable to inspect a non-object'",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Resolve code to an object in the current scope.
@throws RuntimeException when the code resolves to a non-object value
@param string $code
@return object Variable instance | [
"Resolve",
"code",
"to",
"an",
"object",
"in",
"the",
"current",
"scope",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ReflectingCommand.php#L175-L184 |
bobthecow/psysh | src/Command/ReflectingCommand.php | ReflectingCommand.setCommandScopeVariables | protected function setCommandScopeVariables(\Reflector $reflector)
{
$vars = [];
switch (\get_class($reflector)) {
case 'ReflectionClass':
case 'ReflectionObject':
$vars['__class'] = $reflector->name;
if ($reflector->inNamespace()) {
$vars['__namespace'] = $reflector->getNamespaceName();
}
break;
case 'ReflectionMethod':
$vars['__method'] = \sprintf('%s::%s', $reflector->class, $reflector->name);
$vars['__class'] = $reflector->class;
$classReflector = $reflector->getDeclaringClass();
if ($classReflector->inNamespace()) {
$vars['__namespace'] = $classReflector->getNamespaceName();
}
break;
case 'ReflectionFunction':
$vars['__function'] = $reflector->name;
if ($reflector->inNamespace()) {
$vars['__namespace'] = $reflector->getNamespaceName();
}
break;
case 'ReflectionGenerator':
$funcReflector = $reflector->getFunction();
$vars['__function'] = $funcReflector->name;
if ($funcReflector->inNamespace()) {
$vars['__namespace'] = $funcReflector->getNamespaceName();
}
if ($fileName = $reflector->getExecutingFile()) {
$vars['__file'] = $fileName;
$vars['__line'] = $reflector->getExecutingLine();
$vars['__dir'] = \dirname($fileName);
}
break;
case 'ReflectionProperty':
case 'ReflectionClassConstant':
case 'Psy\Reflection\ReflectionClassConstant':
$classReflector = $reflector->getDeclaringClass();
$vars['__class'] = $classReflector->name;
if ($classReflector->inNamespace()) {
$vars['__namespace'] = $classReflector->getNamespaceName();
}
// no line for these, but this'll do
if ($fileName = $reflector->getDeclaringClass()->getFileName()) {
$vars['__file'] = $fileName;
$vars['__dir'] = \dirname($fileName);
}
break;
case 'Psy\Reflection\ReflectionConstant_':
if ($reflector->inNamespace()) {
$vars['__namespace'] = $reflector->getNamespaceName();
}
break;
}
if ($reflector instanceof \ReflectionClass || $reflector instanceof \ReflectionFunctionAbstract) {
if ($fileName = $reflector->getFileName()) {
$vars['__file'] = $fileName;
$vars['__line'] = $reflector->getStartLine();
$vars['__dir'] = \dirname($fileName);
}
}
$this->context->setCommandScopeVariables($vars);
} | php | protected function setCommandScopeVariables(\Reflector $reflector)
{
$vars = [];
switch (\get_class($reflector)) {
case 'ReflectionClass':
case 'ReflectionObject':
$vars['__class'] = $reflector->name;
if ($reflector->inNamespace()) {
$vars['__namespace'] = $reflector->getNamespaceName();
}
break;
case 'ReflectionMethod':
$vars['__method'] = \sprintf('%s::%s', $reflector->class, $reflector->name);
$vars['__class'] = $reflector->class;
$classReflector = $reflector->getDeclaringClass();
if ($classReflector->inNamespace()) {
$vars['__namespace'] = $classReflector->getNamespaceName();
}
break;
case 'ReflectionFunction':
$vars['__function'] = $reflector->name;
if ($reflector->inNamespace()) {
$vars['__namespace'] = $reflector->getNamespaceName();
}
break;
case 'ReflectionGenerator':
$funcReflector = $reflector->getFunction();
$vars['__function'] = $funcReflector->name;
if ($funcReflector->inNamespace()) {
$vars['__namespace'] = $funcReflector->getNamespaceName();
}
if ($fileName = $reflector->getExecutingFile()) {
$vars['__file'] = $fileName;
$vars['__line'] = $reflector->getExecutingLine();
$vars['__dir'] = \dirname($fileName);
}
break;
case 'ReflectionProperty':
case 'ReflectionClassConstant':
case 'Psy\Reflection\ReflectionClassConstant':
$classReflector = $reflector->getDeclaringClass();
$vars['__class'] = $classReflector->name;
if ($classReflector->inNamespace()) {
$vars['__namespace'] = $classReflector->getNamespaceName();
}
if ($fileName = $reflector->getDeclaringClass()->getFileName()) {
$vars['__file'] = $fileName;
$vars['__dir'] = \dirname($fileName);
}
break;
case 'Psy\Reflection\ReflectionConstant_':
if ($reflector->inNamespace()) {
$vars['__namespace'] = $reflector->getNamespaceName();
}
break;
}
if ($reflector instanceof \ReflectionClass || $reflector instanceof \ReflectionFunctionAbstract) {
if ($fileName = $reflector->getFileName()) {
$vars['__file'] = $fileName;
$vars['__line'] = $reflector->getStartLine();
$vars['__dir'] = \dirname($fileName);
}
}
$this->context->setCommandScopeVariables($vars);
} | [
"protected",
"function",
"setCommandScopeVariables",
"(",
"\\",
"Reflector",
"$",
"reflector",
")",
"{",
"$",
"vars",
"=",
"[",
"]",
";",
"switch",
"(",
"\\",
"get_class",
"(",
"$",
"reflector",
")",
")",
"{",
"case",
"'ReflectionClass'",
":",
"case",
"'ReflectionObject'",
":",
"$",
"vars",
"[",
"'__class'",
"]",
"=",
"$",
"reflector",
"->",
"name",
";",
"if",
"(",
"$",
"reflector",
"->",
"inNamespace",
"(",
")",
")",
"{",
"$",
"vars",
"[",
"'__namespace'",
"]",
"=",
"$",
"reflector",
"->",
"getNamespaceName",
"(",
")",
";",
"}",
"break",
";",
"case",
"'ReflectionMethod'",
":",
"$",
"vars",
"[",
"'__method'",
"]",
"=",
"\\",
"sprintf",
"(",
"'%s::%s'",
",",
"$",
"reflector",
"->",
"class",
",",
"$",
"reflector",
"->",
"name",
")",
";",
"$",
"vars",
"[",
"'__class'",
"]",
"=",
"$",
"reflector",
"->",
"class",
";",
"$",
"classReflector",
"=",
"$",
"reflector",
"->",
"getDeclaringClass",
"(",
")",
";",
"if",
"(",
"$",
"classReflector",
"->",
"inNamespace",
"(",
")",
")",
"{",
"$",
"vars",
"[",
"'__namespace'",
"]",
"=",
"$",
"classReflector",
"->",
"getNamespaceName",
"(",
")",
";",
"}",
"break",
";",
"case",
"'ReflectionFunction'",
":",
"$",
"vars",
"[",
"'__function'",
"]",
"=",
"$",
"reflector",
"->",
"name",
";",
"if",
"(",
"$",
"reflector",
"->",
"inNamespace",
"(",
")",
")",
"{",
"$",
"vars",
"[",
"'__namespace'",
"]",
"=",
"$",
"reflector",
"->",
"getNamespaceName",
"(",
")",
";",
"}",
"break",
";",
"case",
"'ReflectionGenerator'",
":",
"$",
"funcReflector",
"=",
"$",
"reflector",
"->",
"getFunction",
"(",
")",
";",
"$",
"vars",
"[",
"'__function'",
"]",
"=",
"$",
"funcReflector",
"->",
"name",
";",
"if",
"(",
"$",
"funcReflector",
"->",
"inNamespace",
"(",
")",
")",
"{",
"$",
"vars",
"[",
"'__namespace'",
"]",
"=",
"$",
"funcReflector",
"->",
"getNamespaceName",
"(",
")",
";",
"}",
"if",
"(",
"$",
"fileName",
"=",
"$",
"reflector",
"->",
"getExecutingFile",
"(",
")",
")",
"{",
"$",
"vars",
"[",
"'__file'",
"]",
"=",
"$",
"fileName",
";",
"$",
"vars",
"[",
"'__line'",
"]",
"=",
"$",
"reflector",
"->",
"getExecutingLine",
"(",
")",
";",
"$",
"vars",
"[",
"'__dir'",
"]",
"=",
"\\",
"dirname",
"(",
"$",
"fileName",
")",
";",
"}",
"break",
";",
"case",
"'ReflectionProperty'",
":",
"case",
"'ReflectionClassConstant'",
":",
"case",
"'Psy\\Reflection\\ReflectionClassConstant'",
":",
"$",
"classReflector",
"=",
"$",
"reflector",
"->",
"getDeclaringClass",
"(",
")",
";",
"$",
"vars",
"[",
"'__class'",
"]",
"=",
"$",
"classReflector",
"->",
"name",
";",
"if",
"(",
"$",
"classReflector",
"->",
"inNamespace",
"(",
")",
")",
"{",
"$",
"vars",
"[",
"'__namespace'",
"]",
"=",
"$",
"classReflector",
"->",
"getNamespaceName",
"(",
")",
";",
"}",
"// no line for these, but this'll do",
"if",
"(",
"$",
"fileName",
"=",
"$",
"reflector",
"->",
"getDeclaringClass",
"(",
")",
"->",
"getFileName",
"(",
")",
")",
"{",
"$",
"vars",
"[",
"'__file'",
"]",
"=",
"$",
"fileName",
";",
"$",
"vars",
"[",
"'__dir'",
"]",
"=",
"\\",
"dirname",
"(",
"$",
"fileName",
")",
";",
"}",
"break",
";",
"case",
"'Psy\\Reflection\\ReflectionConstant_'",
":",
"if",
"(",
"$",
"reflector",
"->",
"inNamespace",
"(",
")",
")",
"{",
"$",
"vars",
"[",
"'__namespace'",
"]",
"=",
"$",
"reflector",
"->",
"getNamespaceName",
"(",
")",
";",
"}",
"break",
";",
"}",
"if",
"(",
"$",
"reflector",
"instanceof",
"\\",
"ReflectionClass",
"||",
"$",
"reflector",
"instanceof",
"\\",
"ReflectionFunctionAbstract",
")",
"{",
"if",
"(",
"$",
"fileName",
"=",
"$",
"reflector",
"->",
"getFileName",
"(",
")",
")",
"{",
"$",
"vars",
"[",
"'__file'",
"]",
"=",
"$",
"fileName",
";",
"$",
"vars",
"[",
"'__line'",
"]",
"=",
"$",
"reflector",
"->",
"getStartLine",
"(",
")",
";",
"$",
"vars",
"[",
"'__dir'",
"]",
"=",
"\\",
"dirname",
"(",
"$",
"fileName",
")",
";",
"}",
"}",
"$",
"this",
"->",
"context",
"->",
"setCommandScopeVariables",
"(",
"$",
"vars",
")",
";",
"}"
] | Given a Reflector instance, set command-scope variables in the shell
execution context. This is used to inject magic $__class, $__method and
$__file variables (as well as a handful of others).
@param \Reflector $reflector | [
"Given",
"a",
"Reflector",
"instance",
"set",
"command",
"-",
"scope",
"variables",
"in",
"the",
"shell",
"execution",
"context",
".",
"This",
"is",
"used",
"to",
"inject",
"magic",
"$__class",
"$__method",
"and",
"$__file",
"variables",
"(",
"as",
"well",
"as",
"a",
"handful",
"of",
"others",
")",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ReflectingCommand.php#L229-L302 |
bobthecow/psysh | src/Command/ListCommand/GlobalVariableEnumerator.php | GlobalVariableEnumerator.listItems | protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
{
// only list globals when no Reflector is present.
if ($reflector !== null || $target !== null) {
return;
}
// only list globals if we are specifically asked
if (!$input->getOption('globals')) {
return;
}
$globals = $this->prepareGlobals($this->getGlobals());
if (empty($globals)) {
return;
}
return [
'Global Variables' => $globals,
];
} | php | protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
{
if ($reflector !== null || $target !== null) {
return;
}
if (!$input->getOption('globals')) {
return;
}
$globals = $this->prepareGlobals($this->getGlobals());
if (empty($globals)) {
return;
}
return [
'Global Variables' => $globals,
];
} | [
"protected",
"function",
"listItems",
"(",
"InputInterface",
"$",
"input",
",",
"\\",
"Reflector",
"$",
"reflector",
"=",
"null",
",",
"$",
"target",
"=",
"null",
")",
"{",
"// only list globals when no Reflector is present.",
"if",
"(",
"$",
"reflector",
"!==",
"null",
"||",
"$",
"target",
"!==",
"null",
")",
"{",
"return",
";",
"}",
"// only list globals if we are specifically asked",
"if",
"(",
"!",
"$",
"input",
"->",
"getOption",
"(",
"'globals'",
")",
")",
"{",
"return",
";",
"}",
"$",
"globals",
"=",
"$",
"this",
"->",
"prepareGlobals",
"(",
"$",
"this",
"->",
"getGlobals",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"globals",
")",
")",
"{",
"return",
";",
"}",
"return",
"[",
"'Global Variables'",
"=>",
"$",
"globals",
",",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ListCommand/GlobalVariableEnumerator.php#L24-L45 |
bobthecow/psysh | src/Command/ListCommand/GlobalVariableEnumerator.php | GlobalVariableEnumerator.getGlobals | protected function getGlobals()
{
global $GLOBALS;
$names = \array_keys($GLOBALS);
\natcasesort($names);
$ret = [];
foreach ($names as $name) {
$ret[$name] = $GLOBALS[$name];
}
return $ret;
} | php | protected function getGlobals()
{
global $GLOBALS;
$names = \array_keys($GLOBALS);
\natcasesort($names);
$ret = [];
foreach ($names as $name) {
$ret[$name] = $GLOBALS[$name];
}
return $ret;
} | [
"protected",
"function",
"getGlobals",
"(",
")",
"{",
"global",
"$",
"GLOBALS",
";",
"$",
"names",
"=",
"\\",
"array_keys",
"(",
"$",
"GLOBALS",
")",
";",
"\\",
"natcasesort",
"(",
"$",
"names",
")",
";",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"name",
")",
"{",
"$",
"ret",
"[",
"$",
"name",
"]",
"=",
"$",
"GLOBALS",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get defined global variables.
@return array | [
"Get",
"defined",
"global",
"variables",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ListCommand/GlobalVariableEnumerator.php#L52-L65 |
bobthecow/psysh | src/Command/ListCommand/GlobalVariableEnumerator.php | GlobalVariableEnumerator.prepareGlobals | protected function prepareGlobals($globals)
{
// My kingdom for a generator.
$ret = [];
foreach ($globals as $name => $value) {
if ($this->showItem($name)) {
$fname = '$' . $name;
$ret[$fname] = [
'name' => $fname,
'style' => self::IS_GLOBAL,
'value' => $this->presentRef($value),
];
}
}
return $ret;
} | php | protected function prepareGlobals($globals)
{
$ret = [];
foreach ($globals as $name => $value) {
if ($this->showItem($name)) {
$fname = '$' . $name;
$ret[$fname] = [
'name' => $fname,
'style' => self::IS_GLOBAL,
'value' => $this->presentRef($value),
];
}
}
return $ret;
} | [
"protected",
"function",
"prepareGlobals",
"(",
"$",
"globals",
")",
"{",
"// My kingdom for a generator.",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"globals",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"showItem",
"(",
"$",
"name",
")",
")",
"{",
"$",
"fname",
"=",
"'$'",
".",
"$",
"name",
";",
"$",
"ret",
"[",
"$",
"fname",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"fname",
",",
"'style'",
"=>",
"self",
"::",
"IS_GLOBAL",
",",
"'value'",
"=>",
"$",
"this",
"->",
"presentRef",
"(",
"$",
"value",
")",
",",
"]",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Prepare formatted global variable array.
@param array $globals
@return array | [
"Prepare",
"formatted",
"global",
"variable",
"array",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ListCommand/GlobalVariableEnumerator.php#L74-L91 |
bobthecow/psysh | src/CodeCleaner/ValidConstructorPass.php | ValidConstructorPass.enterNode | public function enterNode(Node $node)
{
if ($node instanceof Namespace_) {
$this->namespace = isset($node->name) ? $node->name->parts : [];
} elseif ($node instanceof Class_) {
$constructor = null;
foreach ($node->stmts as $stmt) {
if ($stmt instanceof ClassMethod) {
// If we find a new-style constructor, no need to look for the old-style
if ('__construct' === \strtolower($stmt->name)) {
$this->validateConstructor($stmt, $node);
return;
}
// We found a possible old-style constructor (unless there is also a __construct method)
if (empty($this->namespace) && \strtolower($node->name) === \strtolower($stmt->name)) {
$constructor = $stmt;
}
}
}
if ($constructor) {
$this->validateConstructor($constructor, $node);
}
}
} | php | public function enterNode(Node $node)
{
if ($node instanceof Namespace_) {
$this->namespace = isset($node->name) ? $node->name->parts : [];
} elseif ($node instanceof Class_) {
$constructor = null;
foreach ($node->stmts as $stmt) {
if ($stmt instanceof ClassMethod) {
if ('__construct' === \strtolower($stmt->name)) {
$this->validateConstructor($stmt, $node);
return;
}
if (empty($this->namespace) && \strtolower($node->name) === \strtolower($stmt->name)) {
$constructor = $stmt;
}
}
}
if ($constructor) {
$this->validateConstructor($constructor, $node);
}
}
} | [
"public",
"function",
"enterNode",
"(",
"Node",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"Namespace_",
")",
"{",
"$",
"this",
"->",
"namespace",
"=",
"isset",
"(",
"$",
"node",
"->",
"name",
")",
"?",
"$",
"node",
"->",
"name",
"->",
"parts",
":",
"[",
"]",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"Class_",
")",
"{",
"$",
"constructor",
"=",
"null",
";",
"foreach",
"(",
"$",
"node",
"->",
"stmts",
"as",
"$",
"stmt",
")",
"{",
"if",
"(",
"$",
"stmt",
"instanceof",
"ClassMethod",
")",
"{",
"// If we find a new-style constructor, no need to look for the old-style",
"if",
"(",
"'__construct'",
"===",
"\\",
"strtolower",
"(",
"$",
"stmt",
"->",
"name",
")",
")",
"{",
"$",
"this",
"->",
"validateConstructor",
"(",
"$",
"stmt",
",",
"$",
"node",
")",
";",
"return",
";",
"}",
"// We found a possible old-style constructor (unless there is also a __construct method)",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"namespace",
")",
"&&",
"\\",
"strtolower",
"(",
"$",
"node",
"->",
"name",
")",
"===",
"\\",
"strtolower",
"(",
"$",
"stmt",
"->",
"name",
")",
")",
"{",
"$",
"constructor",
"=",
"$",
"stmt",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"constructor",
")",
"{",
"$",
"this",
"->",
"validateConstructor",
"(",
"$",
"constructor",
",",
"$",
"node",
")",
";",
"}",
"}",
"}"
] | Validate that the constructor is not static and does not have a return type.
@throws FatalErrorException the constructor function is static
@throws FatalErrorException the constructor function has a return type
@param Node $node | [
"Validate",
"that",
"the",
"constructor",
"is",
"not",
"static",
"and",
"does",
"not",
"have",
"a",
"return",
"type",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidConstructorPass.php#L51-L77 |
bobthecow/psysh | src/CodeCleaner/ValidConstructorPass.php | ValidConstructorPass.validateConstructor | private function validateConstructor(Node $constructor, Node $classNode)
{
if ($constructor->isStatic()) {
// For PHP Parser 4.x
$className = $classNode->name instanceof Identifier ? $classNode->name->toString() : $classNode->name;
$msg = \sprintf(
'Constructor %s::%s() cannot be static',
\implode('\\', \array_merge($this->namespace, (array) $className)),
$constructor->name
);
throw new FatalErrorException($msg, 0, E_ERROR, null, $classNode->getLine());
}
if (\method_exists($constructor, 'getReturnType') && $constructor->getReturnType()) {
// For PHP Parser 4.x
$className = $classNode->name instanceof Identifier ? $classNode->name->toString() : $classNode->name;
$msg = \sprintf(
'Constructor %s::%s() cannot declare a return type',
\implode('\\', \array_merge($this->namespace, (array) $className)),
$constructor->name
);
throw new FatalErrorException($msg, 0, E_ERROR, null, $classNode->getLine());
}
} | php | private function validateConstructor(Node $constructor, Node $classNode)
{
if ($constructor->isStatic()) {
$className = $classNode->name instanceof Identifier ? $classNode->name->toString() : $classNode->name;
$msg = \sprintf(
'Constructor %s::%s() cannot be static',
\implode('\\', \array_merge($this->namespace, (array) $className)),
$constructor->name
);
throw new FatalErrorException($msg, 0, E_ERROR, null, $classNode->getLine());
}
if (\method_exists($constructor, 'getReturnType') && $constructor->getReturnType()) {
$className = $classNode->name instanceof Identifier ? $classNode->name->toString() : $classNode->name;
$msg = \sprintf(
'Constructor %s::%s() cannot declare a return type',
\implode('\\', \array_merge($this->namespace, (array) $className)),
$constructor->name
);
throw new FatalErrorException($msg, 0, E_ERROR, null, $classNode->getLine());
}
} | [
"private",
"function",
"validateConstructor",
"(",
"Node",
"$",
"constructor",
",",
"Node",
"$",
"classNode",
")",
"{",
"if",
"(",
"$",
"constructor",
"->",
"isStatic",
"(",
")",
")",
"{",
"// For PHP Parser 4.x",
"$",
"className",
"=",
"$",
"classNode",
"->",
"name",
"instanceof",
"Identifier",
"?",
"$",
"classNode",
"->",
"name",
"->",
"toString",
"(",
")",
":",
"$",
"classNode",
"->",
"name",
";",
"$",
"msg",
"=",
"\\",
"sprintf",
"(",
"'Constructor %s::%s() cannot be static'",
",",
"\\",
"implode",
"(",
"'\\\\'",
",",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"namespace",
",",
"(",
"array",
")",
"$",
"className",
")",
")",
",",
"$",
"constructor",
"->",
"name",
")",
";",
"throw",
"new",
"FatalErrorException",
"(",
"$",
"msg",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"classNode",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"if",
"(",
"\\",
"method_exists",
"(",
"$",
"constructor",
",",
"'getReturnType'",
")",
"&&",
"$",
"constructor",
"->",
"getReturnType",
"(",
")",
")",
"{",
"// For PHP Parser 4.x",
"$",
"className",
"=",
"$",
"classNode",
"->",
"name",
"instanceof",
"Identifier",
"?",
"$",
"classNode",
"->",
"name",
"->",
"toString",
"(",
")",
":",
"$",
"classNode",
"->",
"name",
";",
"$",
"msg",
"=",
"\\",
"sprintf",
"(",
"'Constructor %s::%s() cannot declare a return type'",
",",
"\\",
"implode",
"(",
"'\\\\'",
",",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"namespace",
",",
"(",
"array",
")",
"$",
"className",
")",
")",
",",
"$",
"constructor",
"->",
"name",
")",
";",
"throw",
"new",
"FatalErrorException",
"(",
"$",
"msg",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"classNode",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"}"
] | @throws FatalErrorException the constructor function is static
@throws FatalErrorException the constructor function has a return type
@param Node $constructor
@param Node $classNode | [
"@throws",
"FatalErrorException",
"the",
"constructor",
"function",
"is",
"static",
"@throws",
"FatalErrorException",
"the",
"constructor",
"function",
"has",
"a",
"return",
"type"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/ValidConstructorPass.php#L86-L111 |
bobthecow/psysh | src/TabCompletion/Matcher/AbstractDefaultParametersMatcher.php | AbstractDefaultParametersMatcher.getDefaultParameterCompletion | public function getDefaultParameterCompletion(array $reflectionParameters)
{
$parametersProcessed = [];
foreach ($reflectionParameters as $parameter) {
if (!$parameter->isDefaultValueAvailable()) {
return [];
}
$defaultValue = $this->valueToShortString($parameter->getDefaultValue());
$parametersProcessed[] = "\${$parameter->getName()} = $defaultValue";
}
if (empty($parametersProcessed)) {
return [];
}
return [\implode(', ', $parametersProcessed) . ')'];
} | php | public function getDefaultParameterCompletion(array $reflectionParameters)
{
$parametersProcessed = [];
foreach ($reflectionParameters as $parameter) {
if (!$parameter->isDefaultValueAvailable()) {
return [];
}
$defaultValue = $this->valueToShortString($parameter->getDefaultValue());
$parametersProcessed[] = "\${$parameter->getName()} = $defaultValue";
}
if (empty($parametersProcessed)) {
return [];
}
return [\implode(', ', $parametersProcessed) . ')'];
} | [
"public",
"function",
"getDefaultParameterCompletion",
"(",
"array",
"$",
"reflectionParameters",
")",
"{",
"$",
"parametersProcessed",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"reflectionParameters",
"as",
"$",
"parameter",
")",
"{",
"if",
"(",
"!",
"$",
"parameter",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"defaultValue",
"=",
"$",
"this",
"->",
"valueToShortString",
"(",
"$",
"parameter",
"->",
"getDefaultValue",
"(",
")",
")",
";",
"$",
"parametersProcessed",
"[",
"]",
"=",
"\"\\${$parameter->getName()} = $defaultValue\"",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"parametersProcessed",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"[",
"\\",
"implode",
"(",
"', '",
",",
"$",
"parametersProcessed",
")",
".",
"')'",
"]",
";",
"}"
] | @param \ReflectionParameter[] $reflectionParameters
@return array | [
"@param",
"\\",
"ReflectionParameter",
"[]",
"$reflectionParameters"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/AbstractDefaultParametersMatcher.php#L21-L40 |
bobthecow/psysh | src/TabCompletion/Matcher/AbstractDefaultParametersMatcher.php | AbstractDefaultParametersMatcher.valueToShortString | private function valueToShortString($value)
{
if (!\is_array($value)) {
return \json_encode($value);
}
$chunks = [];
$chunksSequential = [];
$allSequential = true;
foreach ($value as $key => $item) {
$allSequential = $allSequential && \is_numeric($key) && $key === \count($chunksSequential);
$keyString = $this->valueToShortString($key);
$itemString = $this->valueToShortString($item);
$chunks[] = "{$keyString} => {$itemString}";
$chunksSequential[] = $itemString;
}
$chunksToImplode = $allSequential ? $chunksSequential : $chunks;
return '[' . \implode(', ', $chunksToImplode) . ']';
} | php | private function valueToShortString($value)
{
if (!\is_array($value)) {
return \json_encode($value);
}
$chunks = [];
$chunksSequential = [];
$allSequential = true;
foreach ($value as $key => $item) {
$allSequential = $allSequential && \is_numeric($key) && $key === \count($chunksSequential);
$keyString = $this->valueToShortString($key);
$itemString = $this->valueToShortString($item);
$chunks[] = "{$keyString} => {$itemString}";
$chunksSequential[] = $itemString;
}
$chunksToImplode = $allSequential ? $chunksSequential : $chunks;
return '[' . \implode(', ', $chunksToImplode) . ']';
} | [
"private",
"function",
"valueToShortString",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"\\",
"json_encode",
"(",
"$",
"value",
")",
";",
"}",
"$",
"chunks",
"=",
"[",
"]",
";",
"$",
"chunksSequential",
"=",
"[",
"]",
";",
"$",
"allSequential",
"=",
"true",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"allSequential",
"=",
"$",
"allSequential",
"&&",
"\\",
"is_numeric",
"(",
"$",
"key",
")",
"&&",
"$",
"key",
"===",
"\\",
"count",
"(",
"$",
"chunksSequential",
")",
";",
"$",
"keyString",
"=",
"$",
"this",
"->",
"valueToShortString",
"(",
"$",
"key",
")",
";",
"$",
"itemString",
"=",
"$",
"this",
"->",
"valueToShortString",
"(",
"$",
"item",
")",
";",
"$",
"chunks",
"[",
"]",
"=",
"\"{$keyString} => {$itemString}\"",
";",
"$",
"chunksSequential",
"[",
"]",
"=",
"$",
"itemString",
";",
"}",
"$",
"chunksToImplode",
"=",
"$",
"allSequential",
"?",
"$",
"chunksSequential",
":",
"$",
"chunks",
";",
"return",
"'['",
".",
"\\",
"implode",
"(",
"', '",
",",
"$",
"chunksToImplode",
")",
".",
"']'",
";",
"}"
] | Takes in the default value of a parameter and turns it into a
string representation that fits inline.
This is not 100% true to the original (newlines are inlined, for example).
@param mixed $value
@return string | [
"Takes",
"in",
"the",
"default",
"value",
"of",
"a",
"parameter",
"and",
"turns",
"it",
"into",
"a",
"string",
"representation",
"that",
"fits",
"inline",
".",
"This",
"is",
"not",
"100%",
"true",
"to",
"the",
"original",
"(",
"newlines",
"are",
"inlined",
"for",
"example",
")",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/AbstractDefaultParametersMatcher.php#L51-L75 |
bobthecow/psysh | src/TabCompletion/Matcher/ClassAttributesMatcher.php | ClassAttributesMatcher.getMatches | public function getMatches(array $tokens, array $info = [])
{
$input = $this->getInput($tokens);
$firstToken = \array_pop($tokens);
if (self::tokenIs($firstToken, self::T_STRING)) {
// second token is the nekudotayim operator
\array_pop($tokens);
}
$class = $this->getNamespaceAndClass($tokens);
try {
$reflection = new \ReflectionClass($class);
} catch (\ReflectionException $re) {
return [];
}
$vars = \array_merge(
\array_map(
function ($var) {
return '$' . $var;
},
\array_keys($reflection->getStaticProperties())
),
\array_keys($reflection->getConstants())
);
return \array_map(
function ($name) use ($class) {
$chunks = \explode('\\', $class);
$className = \array_pop($chunks);
return $className . '::' . $name;
},
\array_filter(
$vars,
function ($var) use ($input) {
return AbstractMatcher::startsWith($input, $var);
}
)
);
} | php | public function getMatches(array $tokens, array $info = [])
{
$input = $this->getInput($tokens);
$firstToken = \array_pop($tokens);
if (self::tokenIs($firstToken, self::T_STRING)) {
\array_pop($tokens);
}
$class = $this->getNamespaceAndClass($tokens);
try {
$reflection = new \ReflectionClass($class);
} catch (\ReflectionException $re) {
return [];
}
$vars = \array_merge(
\array_map(
function ($var) {
return '$' . $var;
},
\array_keys($reflection->getStaticProperties())
),
\array_keys($reflection->getConstants())
);
return \array_map(
function ($name) use ($class) {
$chunks = \explode('\\', $class);
$className = \array_pop($chunks);
return $className . '::' . $name;
},
\array_filter(
$vars,
function ($var) use ($input) {
return AbstractMatcher::startsWith($input, $var);
}
)
);
} | [
"public",
"function",
"getMatches",
"(",
"array",
"$",
"tokens",
",",
"array",
"$",
"info",
"=",
"[",
"]",
")",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"getInput",
"(",
"$",
"tokens",
")",
";",
"$",
"firstToken",
"=",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"if",
"(",
"self",
"::",
"tokenIs",
"(",
"$",
"firstToken",
",",
"self",
"::",
"T_STRING",
")",
")",
"{",
"// second token is the nekudotayim operator",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"getNamespaceAndClass",
"(",
"$",
"tokens",
")",
";",
"try",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"re",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"vars",
"=",
"\\",
"array_merge",
"(",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"var",
")",
"{",
"return",
"'$'",
".",
"$",
"var",
";",
"}",
",",
"\\",
"array_keys",
"(",
"$",
"reflection",
"->",
"getStaticProperties",
"(",
")",
")",
")",
",",
"\\",
"array_keys",
"(",
"$",
"reflection",
"->",
"getConstants",
"(",
")",
")",
")",
";",
"return",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"name",
")",
"use",
"(",
"$",
"class",
")",
"{",
"$",
"chunks",
"=",
"\\",
"explode",
"(",
"'\\\\'",
",",
"$",
"class",
")",
";",
"$",
"className",
"=",
"\\",
"array_pop",
"(",
"$",
"chunks",
")",
";",
"return",
"$",
"className",
".",
"'::'",
".",
"$",
"name",
";",
"}",
",",
"\\",
"array_filter",
"(",
"$",
"vars",
",",
"function",
"(",
"$",
"var",
")",
"use",
"(",
"$",
"input",
")",
"{",
"return",
"AbstractMatcher",
"::",
"startsWith",
"(",
"$",
"input",
",",
"$",
"var",
")",
";",
"}",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/ClassAttributesMatcher.php#L27-L69 |
bobthecow/psysh | src/TabCompletion/Matcher/ClassAttributesMatcher.php | ClassAttributesMatcher.hasMatched | public function hasMatched(array $tokens)
{
$token = \array_pop($tokens);
$prevToken = \array_pop($tokens);
switch (true) {
case self::tokenIs($prevToken, self::T_DOUBLE_COLON) && self::tokenIs($token, self::T_STRING):
case self::tokenIs($token, self::T_DOUBLE_COLON):
return true;
}
return false;
} | php | public function hasMatched(array $tokens)
{
$token = \array_pop($tokens);
$prevToken = \array_pop($tokens);
switch (true) {
case self::tokenIs($prevToken, self::T_DOUBLE_COLON) && self::tokenIs($token, self::T_STRING):
case self::tokenIs($token, self::T_DOUBLE_COLON):
return true;
}
return false;
} | [
"public",
"function",
"hasMatched",
"(",
"array",
"$",
"tokens",
")",
"{",
"$",
"token",
"=",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"$",
"prevToken",
"=",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"self",
"::",
"tokenIs",
"(",
"$",
"prevToken",
",",
"self",
"::",
"T_DOUBLE_COLON",
")",
"&&",
"self",
"::",
"tokenIs",
"(",
"$",
"token",
",",
"self",
"::",
"T_STRING",
")",
":",
"case",
"self",
"::",
"tokenIs",
"(",
"$",
"token",
",",
"self",
"::",
"T_DOUBLE_COLON",
")",
":",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/ClassAttributesMatcher.php#L74-L86 |
bobthecow/psysh | src/Formatter/DocblockFormatter.php | DocblockFormatter.format | public static function format(\Reflector $reflector)
{
$docblock = new Docblock($reflector);
$chunks = [];
if (!empty($docblock->desc)) {
$chunks[] = '<comment>Description:</comment>';
$chunks[] = self::indent(OutputFormatter::escape($docblock->desc), ' ');
$chunks[] = '';
}
if (!empty($docblock->tags)) {
foreach ($docblock::$vectors as $name => $vector) {
if (isset($docblock->tags[$name])) {
$chunks[] = \sprintf('<comment>%s:</comment>', self::inflect($name));
$chunks[] = self::formatVector($vector, $docblock->tags[$name]);
$chunks[] = '';
}
}
$tags = self::formatTags(\array_keys($docblock::$vectors), $docblock->tags);
if (!empty($tags)) {
$chunks[] = $tags;
$chunks[] = '';
}
}
return \rtrim(\implode("\n", $chunks));
} | php | public static function format(\Reflector $reflector)
{
$docblock = new Docblock($reflector);
$chunks = [];
if (!empty($docblock->desc)) {
$chunks[] = '<comment>Description:</comment>';
$chunks[] = self::indent(OutputFormatter::escape($docblock->desc), ' ');
$chunks[] = '';
}
if (!empty($docblock->tags)) {
foreach ($docblock::$vectors as $name => $vector) {
if (isset($docblock->tags[$name])) {
$chunks[] = \sprintf('<comment>%s:</comment>', self::inflect($name));
$chunks[] = self::formatVector($vector, $docblock->tags[$name]);
$chunks[] = '';
}
}
$tags = self::formatTags(\array_keys($docblock::$vectors), $docblock->tags);
if (!empty($tags)) {
$chunks[] = $tags;
$chunks[] = '';
}
}
return \rtrim(\implode("\n", $chunks));
} | [
"public",
"static",
"function",
"format",
"(",
"\\",
"Reflector",
"$",
"reflector",
")",
"{",
"$",
"docblock",
"=",
"new",
"Docblock",
"(",
"$",
"reflector",
")",
";",
"$",
"chunks",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"docblock",
"->",
"desc",
")",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"'<comment>Description:</comment>'",
";",
"$",
"chunks",
"[",
"]",
"=",
"self",
"::",
"indent",
"(",
"OutputFormatter",
"::",
"escape",
"(",
"$",
"docblock",
"->",
"desc",
")",
",",
"' '",
")",
";",
"$",
"chunks",
"[",
"]",
"=",
"''",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"docblock",
"->",
"tags",
")",
")",
"{",
"foreach",
"(",
"$",
"docblock",
"::",
"$",
"vectors",
"as",
"$",
"name",
"=>",
"$",
"vector",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"docblock",
"->",
"tags",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"\\",
"sprintf",
"(",
"'<comment>%s:</comment>'",
",",
"self",
"::",
"inflect",
"(",
"$",
"name",
")",
")",
";",
"$",
"chunks",
"[",
"]",
"=",
"self",
"::",
"formatVector",
"(",
"$",
"vector",
",",
"$",
"docblock",
"->",
"tags",
"[",
"$",
"name",
"]",
")",
";",
"$",
"chunks",
"[",
"]",
"=",
"''",
";",
"}",
"}",
"$",
"tags",
"=",
"self",
"::",
"formatTags",
"(",
"\\",
"array_keys",
"(",
"$",
"docblock",
"::",
"$",
"vectors",
")",
",",
"$",
"docblock",
"->",
"tags",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tags",
")",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"$",
"tags",
";",
"$",
"chunks",
"[",
"]",
"=",
"''",
";",
"}",
"}",
"return",
"\\",
"rtrim",
"(",
"\\",
"implode",
"(",
"\"\\n\"",
",",
"$",
"chunks",
")",
")",
";",
"}"
] | Format a docblock.
@param \Reflector $reflector
@return string Formatted docblock | [
"Format",
"a",
"docblock",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/DocblockFormatter.php#L34-L62 |
bobthecow/psysh | src/Formatter/DocblockFormatter.php | DocblockFormatter.formatVector | private static function formatVector(array $vector, array $lines)
{
$template = [' '];
foreach ($vector as $type) {
$max = 0;
foreach ($lines as $line) {
$chunk = $line[$type];
$cur = empty($chunk) ? 0 : \strlen($chunk) + 1;
if ($cur > $max) {
$max = $cur;
}
}
$template[] = self::getVectorParamTemplate($type, $max);
}
$template = \implode(' ', $template);
return \implode("\n", \array_map(function ($line) use ($template) {
$escaped = \array_map(['Symfony\Component\Console\Formatter\OutputFormatter', 'escape'], $line);
return \rtrim(\vsprintf($template, $escaped));
}, $lines));
} | php | private static function formatVector(array $vector, array $lines)
{
$template = [' '];
foreach ($vector as $type) {
$max = 0;
foreach ($lines as $line) {
$chunk = $line[$type];
$cur = empty($chunk) ? 0 : \strlen($chunk) + 1;
if ($cur > $max) {
$max = $cur;
}
}
$template[] = self::getVectorParamTemplate($type, $max);
}
$template = \implode(' ', $template);
return \implode("\n", \array_map(function ($line) use ($template) {
$escaped = \array_map(['Symfony\Component\Console\Formatter\OutputFormatter', 'escape'], $line);
return \rtrim(\vsprintf($template, $escaped));
}, $lines));
} | [
"private",
"static",
"function",
"formatVector",
"(",
"array",
"$",
"vector",
",",
"array",
"$",
"lines",
")",
"{",
"$",
"template",
"=",
"[",
"' '",
"]",
";",
"foreach",
"(",
"$",
"vector",
"as",
"$",
"type",
")",
"{",
"$",
"max",
"=",
"0",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"chunk",
"=",
"$",
"line",
"[",
"$",
"type",
"]",
";",
"$",
"cur",
"=",
"empty",
"(",
"$",
"chunk",
")",
"?",
"0",
":",
"\\",
"strlen",
"(",
"$",
"chunk",
")",
"+",
"1",
";",
"if",
"(",
"$",
"cur",
">",
"$",
"max",
")",
"{",
"$",
"max",
"=",
"$",
"cur",
";",
"}",
"}",
"$",
"template",
"[",
"]",
"=",
"self",
"::",
"getVectorParamTemplate",
"(",
"$",
"type",
",",
"$",
"max",
")",
";",
"}",
"$",
"template",
"=",
"\\",
"implode",
"(",
"' '",
",",
"$",
"template",
")",
";",
"return",
"\\",
"implode",
"(",
"\"\\n\"",
",",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"line",
")",
"use",
"(",
"$",
"template",
")",
"{",
"$",
"escaped",
"=",
"\\",
"array_map",
"(",
"[",
"'Symfony\\Component\\Console\\Formatter\\OutputFormatter'",
",",
"'escape'",
"]",
",",
"$",
"line",
")",
";",
"return",
"\\",
"rtrim",
"(",
"\\",
"vsprintf",
"(",
"$",
"template",
",",
"$",
"escaped",
")",
")",
";",
"}",
",",
"$",
"lines",
")",
")",
";",
"}"
] | Format a docblock vector, for example, `@throws`, `@param`, or `@return`.
@see DocBlock::$vectors
@param array $vector
@param array $lines
@return string | [
"Format",
"a",
"docblock",
"vector",
"for",
"example",
"@throws",
"@param",
"or",
"@return",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/DocblockFormatter.php#L74-L96 |
bobthecow/psysh | src/Formatter/DocblockFormatter.php | DocblockFormatter.formatTags | private static function formatTags(array $skip, array $tags)
{
$chunks = [];
foreach ($tags as $name => $values) {
if (\in_array($name, $skip)) {
continue;
}
foreach ($values as $value) {
$chunks[] = \sprintf('<comment>%s%s</comment> %s', self::inflect($name), empty($value) ? '' : ':', OutputFormatter::escape($value));
}
$chunks[] = '';
}
return \implode("\n", $chunks);
} | php | private static function formatTags(array $skip, array $tags)
{
$chunks = [];
foreach ($tags as $name => $values) {
if (\in_array($name, $skip)) {
continue;
}
foreach ($values as $value) {
$chunks[] = \sprintf('<comment>%s%s</comment> %s', self::inflect($name), empty($value) ? '' : ':', OutputFormatter::escape($value));
}
$chunks[] = '';
}
return \implode("\n", $chunks);
} | [
"private",
"static",
"function",
"formatTags",
"(",
"array",
"$",
"skip",
",",
"array",
"$",
"tags",
")",
"{",
"$",
"chunks",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tags",
"as",
"$",
"name",
"=>",
"$",
"values",
")",
"{",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"name",
",",
"$",
"skip",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"\\",
"sprintf",
"(",
"'<comment>%s%s</comment> %s'",
",",
"self",
"::",
"inflect",
"(",
"$",
"name",
")",
",",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"':'",
",",
"OutputFormatter",
"::",
"escape",
"(",
"$",
"value",
")",
")",
";",
"}",
"$",
"chunks",
"[",
"]",
"=",
"''",
";",
"}",
"return",
"\\",
"implode",
"(",
"\"\\n\"",
",",
"$",
"chunks",
")",
";",
"}"
] | Format docblock tags.
@param array $skip Tags to exclude
@param array $tags Tags to format
@return string formatted tags | [
"Format",
"docblock",
"tags",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/DocblockFormatter.php#L106-L123 |
bobthecow/psysh | src/Formatter/DocblockFormatter.php | DocblockFormatter.getVectorParamTemplate | private static function getVectorParamTemplate($type, $max)
{
if (!isset(self::$vectorParamTemplates[$type])) {
return \sprintf('%%-%ds', $max);
}
return \sprintf('<%s>%%-%ds</%s>', self::$vectorParamTemplates[$type], $max, self::$vectorParamTemplates[$type]);
} | php | private static function getVectorParamTemplate($type, $max)
{
if (!isset(self::$vectorParamTemplates[$type])) {
return \sprintf('%%-%ds', $max);
}
return \sprintf('<%s>%%-%ds</%s>', self::$vectorParamTemplates[$type], $max, self::$vectorParamTemplates[$type]);
} | [
"private",
"static",
"function",
"getVectorParamTemplate",
"(",
"$",
"type",
",",
"$",
"max",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"vectorParamTemplates",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"\\",
"sprintf",
"(",
"'%%-%ds'",
",",
"$",
"max",
")",
";",
"}",
"return",
"\\",
"sprintf",
"(",
"'<%s>%%-%ds</%s>'",
",",
"self",
"::",
"$",
"vectorParamTemplates",
"[",
"$",
"type",
"]",
",",
"$",
"max",
",",
"self",
"::",
"$",
"vectorParamTemplates",
"[",
"$",
"type",
"]",
")",
";",
"}"
] | Get a docblock vector template.
@param string $type Vector type
@param int $max Pad width
@return string | [
"Get",
"a",
"docblock",
"vector",
"template",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/DocblockFormatter.php#L133-L140 |
bobthecow/psysh | src/Formatter/DocblockFormatter.php | DocblockFormatter.inflect | private static function inflect($text)
{
$words = \trim(\preg_replace('/[\s_-]+/', ' ', \preg_replace('/([a-z])([A-Z])/', '$1 $2', $text)));
return \implode(' ', \array_map('ucfirst', \explode(' ', $words)));
} | php | private static function inflect($text)
{
$words = \trim(\preg_replace('/[\s_-]+/', ' ', \preg_replace('/([a-z])([A-Z])/', '$1 $2', $text)));
return \implode(' ', \array_map('ucfirst', \explode(' ', $words)));
} | [
"private",
"static",
"function",
"inflect",
"(",
"$",
"text",
")",
"{",
"$",
"words",
"=",
"\\",
"trim",
"(",
"\\",
"preg_replace",
"(",
"'/[\\s_-]+/'",
",",
"' '",
",",
"\\",
"preg_replace",
"(",
"'/([a-z])([A-Z])/'",
",",
"'$1 $2'",
",",
"$",
"text",
")",
")",
")",
";",
"return",
"\\",
"implode",
"(",
"' '",
",",
"\\",
"array_map",
"(",
"'ucfirst'",
",",
"\\",
"explode",
"(",
"' '",
",",
"$",
"words",
")",
")",
")",
";",
"}"
] | Convert underscored or whitespace separated words into sentence case.
@param string $text
@return string | [
"Convert",
"underscored",
"or",
"whitespace",
"separated",
"words",
"into",
"sentence",
"case",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Formatter/DocblockFormatter.php#L162-L167 |
bobthecow/psysh | src/CodeCleaner/LoopContextPass.php | LoopContextPass.enterNode | public function enterNode(Node $node)
{
switch (true) {
case $node instanceof Do_:
case $node instanceof For_:
case $node instanceof Foreach_:
case $node instanceof Switch_:
case $node instanceof While_:
$this->loopDepth++;
break;
case $node instanceof Break_:
case $node instanceof Continue_:
$operator = $node instanceof Break_ ? 'break' : 'continue';
if ($this->loopDepth === 0) {
$msg = \sprintf("'%s' not in the 'loop' or 'switch' context", $operator);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
if ($node->num instanceof LNumber || $node->num instanceof DNumber) {
$num = $node->num->value;
if ($node->num instanceof DNumber || $num < 1) {
$msg = \sprintf("'%s' operator accepts only positive numbers", $operator);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
if ($num > $this->loopDepth) {
$msg = \sprintf("Cannot '%s' %d levels", $operator, $num);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
} elseif ($node->num) {
$msg = \sprintf("'%s' operator with non-constant operand is no longer supported", $operator);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
break;
}
} | php | public function enterNode(Node $node)
{
switch (true) {
case $node instanceof Do_:
case $node instanceof For_:
case $node instanceof Foreach_:
case $node instanceof Switch_:
case $node instanceof While_:
$this->loopDepth++;
break;
case $node instanceof Break_:
case $node instanceof Continue_:
$operator = $node instanceof Break_ ? 'break' : 'continue';
if ($this->loopDepth === 0) {
$msg = \sprintf("'%s' not in the 'loop' or 'switch' context", $operator);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
if ($node->num instanceof LNumber || $node->num instanceof DNumber) {
$num = $node->num->value;
if ($node->num instanceof DNumber || $num < 1) {
$msg = \sprintf("'%s' operator accepts only positive numbers", $operator);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
if ($num > $this->loopDepth) {
$msg = \sprintf("Cannot '%s' %d levels", $operator, $num);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
} elseif ($node->num) {
$msg = \sprintf("'%s' operator with non-constant operand is no longer supported", $operator);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
break;
}
} | [
"public",
"function",
"enterNode",
"(",
"Node",
"$",
"node",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"node",
"instanceof",
"Do_",
":",
"case",
"$",
"node",
"instanceof",
"For_",
":",
"case",
"$",
"node",
"instanceof",
"Foreach_",
":",
"case",
"$",
"node",
"instanceof",
"Switch_",
":",
"case",
"$",
"node",
"instanceof",
"While_",
":",
"$",
"this",
"->",
"loopDepth",
"++",
";",
"break",
";",
"case",
"$",
"node",
"instanceof",
"Break_",
":",
"case",
"$",
"node",
"instanceof",
"Continue_",
":",
"$",
"operator",
"=",
"$",
"node",
"instanceof",
"Break_",
"?",
"'break'",
":",
"'continue'",
";",
"if",
"(",
"$",
"this",
"->",
"loopDepth",
"===",
"0",
")",
"{",
"$",
"msg",
"=",
"\\",
"sprintf",
"(",
"\"'%s' not in the 'loop' or 'switch' context\"",
",",
"$",
"operator",
")",
";",
"throw",
"new",
"FatalErrorException",
"(",
"$",
"msg",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"node",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"node",
"->",
"num",
"instanceof",
"LNumber",
"||",
"$",
"node",
"->",
"num",
"instanceof",
"DNumber",
")",
"{",
"$",
"num",
"=",
"$",
"node",
"->",
"num",
"->",
"value",
";",
"if",
"(",
"$",
"node",
"->",
"num",
"instanceof",
"DNumber",
"||",
"$",
"num",
"<",
"1",
")",
"{",
"$",
"msg",
"=",
"\\",
"sprintf",
"(",
"\"'%s' operator accepts only positive numbers\"",
",",
"$",
"operator",
")",
";",
"throw",
"new",
"FatalErrorException",
"(",
"$",
"msg",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"node",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"num",
">",
"$",
"this",
"->",
"loopDepth",
")",
"{",
"$",
"msg",
"=",
"\\",
"sprintf",
"(",
"\"Cannot '%s' %d levels\"",
",",
"$",
"operator",
",",
"$",
"num",
")",
";",
"throw",
"new",
"FatalErrorException",
"(",
"$",
"msg",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"node",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"node",
"->",
"num",
")",
"{",
"$",
"msg",
"=",
"\\",
"sprintf",
"(",
"\"'%s' operator with non-constant operand is no longer supported\"",
",",
"$",
"operator",
")",
";",
"throw",
"new",
"FatalErrorException",
"(",
"$",
"msg",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"node",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"break",
";",
"}",
"}"
] | @throws FatalErrorException if the node is a break or continue in a non-loop or switch context
@throws FatalErrorException if the node is trying to break out of more nested structures than exist
@throws FatalErrorException if the node is a break or continue and has a non-numeric argument
@throws FatalErrorException if the node is a break or continue and has an argument less than 1
@param Node $node | [
"@throws",
"FatalErrorException",
"if",
"the",
"node",
"is",
"a",
"break",
"or",
"continue",
"in",
"a",
"non",
"-",
"loop",
"or",
"switch",
"context",
"@throws",
"FatalErrorException",
"if",
"the",
"node",
"is",
"trying",
"to",
"break",
"out",
"of",
"more",
"nested",
"structures",
"than",
"exist",
"@throws",
"FatalErrorException",
"if",
"the",
"node",
"is",
"a",
"break",
"or",
"continue",
"and",
"has",
"a",
"non",
"-",
"numeric",
"argument",
"@throws",
"FatalErrorException",
"if",
"the",
"node",
"is",
"a",
"break",
"or",
"continue",
"and",
"has",
"an",
"argument",
"less",
"than",
"1"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/LoopContextPass.php#L49-L86 |
bobthecow/psysh | src/TabCompletion/Matcher/ClassMethodsMatcher.php | ClassMethodsMatcher.getMatches | public function getMatches(array $tokens, array $info = [])
{
$input = $this->getInput($tokens);
$firstToken = \array_pop($tokens);
if (self::tokenIs($firstToken, self::T_STRING)) {
// second token is the nekudotayim operator
\array_pop($tokens);
}
$class = $this->getNamespaceAndClass($tokens);
try {
$reflection = new \ReflectionClass($class);
} catch (\ReflectionException $re) {
return [];
}
if (self::needCompleteClass($tokens[1])) {
$methods = $reflection->getMethods();
} else {
$methods = $reflection->getMethods(\ReflectionMethod::IS_STATIC);
}
$methods = \array_map(function (\ReflectionMethod $method) {
return $method->getName();
}, $methods);
return \array_map(
function ($name) use ($class) {
$chunks = \explode('\\', $class);
$className = \array_pop($chunks);
return $className . '::' . $name;
},
\array_filter($methods, function ($method) use ($input) {
return AbstractMatcher::startsWith($input, $method);
})
);
} | php | public function getMatches(array $tokens, array $info = [])
{
$input = $this->getInput($tokens);
$firstToken = \array_pop($tokens);
if (self::tokenIs($firstToken, self::T_STRING)) {
\array_pop($tokens);
}
$class = $this->getNamespaceAndClass($tokens);
try {
$reflection = new \ReflectionClass($class);
} catch (\ReflectionException $re) {
return [];
}
if (self::needCompleteClass($tokens[1])) {
$methods = $reflection->getMethods();
} else {
$methods = $reflection->getMethods(\ReflectionMethod::IS_STATIC);
}
$methods = \array_map(function (\ReflectionMethod $method) {
return $method->getName();
}, $methods);
return \array_map(
function ($name) use ($class) {
$chunks = \explode('\\', $class);
$className = \array_pop($chunks);
return $className . '::' . $name;
},
\array_filter($methods, function ($method) use ($input) {
return AbstractMatcher::startsWith($input, $method);
})
);
} | [
"public",
"function",
"getMatches",
"(",
"array",
"$",
"tokens",
",",
"array",
"$",
"info",
"=",
"[",
"]",
")",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"getInput",
"(",
"$",
"tokens",
")",
";",
"$",
"firstToken",
"=",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"if",
"(",
"self",
"::",
"tokenIs",
"(",
"$",
"firstToken",
",",
"self",
"::",
"T_STRING",
")",
")",
"{",
"// second token is the nekudotayim operator",
"\\",
"array_pop",
"(",
"$",
"tokens",
")",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"getNamespaceAndClass",
"(",
"$",
"tokens",
")",
";",
"try",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"re",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"self",
"::",
"needCompleteClass",
"(",
"$",
"tokens",
"[",
"1",
"]",
")",
")",
"{",
"$",
"methods",
"=",
"$",
"reflection",
"->",
"getMethods",
"(",
")",
";",
"}",
"else",
"{",
"$",
"methods",
"=",
"$",
"reflection",
"->",
"getMethods",
"(",
"\\",
"ReflectionMethod",
"::",
"IS_STATIC",
")",
";",
"}",
"$",
"methods",
"=",
"\\",
"array_map",
"(",
"function",
"(",
"\\",
"ReflectionMethod",
"$",
"method",
")",
"{",
"return",
"$",
"method",
"->",
"getName",
"(",
")",
";",
"}",
",",
"$",
"methods",
")",
";",
"return",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"name",
")",
"use",
"(",
"$",
"class",
")",
"{",
"$",
"chunks",
"=",
"\\",
"explode",
"(",
"'\\\\'",
",",
"$",
"class",
")",
";",
"$",
"className",
"=",
"\\",
"array_pop",
"(",
"$",
"chunks",
")",
";",
"return",
"$",
"className",
".",
"'::'",
".",
"$",
"name",
";",
"}",
",",
"\\",
"array_filter",
"(",
"$",
"methods",
",",
"function",
"(",
"$",
"method",
")",
"use",
"(",
"$",
"input",
")",
"{",
"return",
"AbstractMatcher",
"::",
"startsWith",
"(",
"$",
"input",
",",
"$",
"method",
")",
";",
"}",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/ClassMethodsMatcher.php#L27-L66 |
bobthecow/psysh | src/CodeCleaner/AssignThisVariablePass.php | AssignThisVariablePass.enterNode | public function enterNode(Node $node)
{
if ($node instanceof Assign && $node->var instanceof Variable && $node->var->name === 'this') {
throw new FatalErrorException('Cannot re-assign $this', 0, E_ERROR, null, $node->getLine());
}
} | php | public function enterNode(Node $node)
{
if ($node instanceof Assign && $node->var instanceof Variable && $node->var->name === 'this') {
throw new FatalErrorException('Cannot re-assign $this', 0, E_ERROR, null, $node->getLine());
}
} | [
"public",
"function",
"enterNode",
"(",
"Node",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"Assign",
"&&",
"$",
"node",
"->",
"var",
"instanceof",
"Variable",
"&&",
"$",
"node",
"->",
"var",
"->",
"name",
"===",
"'this'",
")",
"{",
"throw",
"new",
"FatalErrorException",
"(",
"'Cannot re-assign $this'",
",",
"0",
",",
"E_ERROR",
",",
"null",
",",
"$",
"node",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"}"
] | Validate that the user input does not assign the `$this` variable.
@throws RuntimeException if the user assign the `$this` variable
@param Node $node | [
"Validate",
"that",
"the",
"user",
"input",
"does",
"not",
"assign",
"the",
"$this",
"variable",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/AssignThisVariablePass.php#L33-L38 |
bobthecow/psysh | src/CodeCleaner/MagicConstantsPass.php | MagicConstantsPass.enterNode | public function enterNode(Node $node)
{
if ($node instanceof Dir) {
return new FuncCall(new Name('getcwd'), [], $node->getAttributes());
} elseif ($node instanceof File) {
return new String_('', $node->getAttributes());
}
} | php | public function enterNode(Node $node)
{
if ($node instanceof Dir) {
return new FuncCall(new Name('getcwd'), [], $node->getAttributes());
} elseif ($node instanceof File) {
return new String_('', $node->getAttributes());
}
} | [
"public",
"function",
"enterNode",
"(",
"Node",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"Dir",
")",
"{",
"return",
"new",
"FuncCall",
"(",
"new",
"Name",
"(",
"'getcwd'",
")",
",",
"[",
"]",
",",
"$",
"node",
"->",
"getAttributes",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"File",
")",
"{",
"return",
"new",
"String_",
"(",
"''",
",",
"$",
"node",
"->",
"getAttributes",
"(",
")",
")",
";",
"}",
"}"
] | Swap out __DIR__ and __FILE__ constants, because the default ones when
calling eval() don't make sense.
@param Node $node
@return null|FuncCall|String_ | [
"Swap",
"out",
"__DIR__",
"and",
"__FILE__",
"constants",
"because",
"the",
"default",
"ones",
"when",
"calling",
"eval",
"()",
"don",
"t",
"make",
"sense",
"."
] | train | https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/MagicConstantsPass.php#L34-L41 |