作者:Jvbzephi
项目:pha
public function testMethodInCodeBase()
{
$context = $this->contextForCode("\n namespace A;\n Class B {\n public function c() {\n return 42;\n }\n }\n ");
$class_fqsen = FullyQualifiedClassName::fromFullyQualifiedString('\\A\\b');
self::assertTrue($this->code_base->hasClassWithFQSEN($class_fqsen), "Class with FQSEN {$class_fqsen} not found");
$clazz = $this->code_base->getClassByFQSEN($class_fqsen);
self::assertTrue($clazz->hasMethodWithName($this->code_base, 'c'), "Method with FQSEN not found");
}
作者:mgonya
项目:pha
/**
* @param Context $context
* The context of the current execution
*
* @param CodeBase $code_base
* The global code base
*
* @param string $class_name
* The name we're trying to validate
*/
public function __construct(Context $context, CodeBase $code_base, string $class_name)
{
$this->context = $context;
$this->code_base = $code_base;
$this->class_name = $class_name;
// Compute the FQSEN based on the current context
$this->class_fqsen = FullyQualifiedClassName::fromStringInContext($this->class_name, $this->context);
}
作者:nagyistg
项目:pha
public function testFullyQualifiedClassConstantName()
{
$this->assertFQSENEqual(FullyQualifiedClassConstantName::make(FullyQualifiedClassName::make('\\Name\\Space', 'a'), 'c'), '\\Name\\Space\\a::c');
$this->assertFQSENEqual(FullyQualifiedClassConstantName::fromFullyQualifiedString('\\Name\\a::c'), '\\Name\\a::c');
$this->assertFQSENEqual(FullyQualifiedClassConstantName::fromFullyQualifiedString('Name\\a::c'), '\\Name\\a::c');
$this->assertFQSENEqual(FullyQualifiedClassConstantName::fromFullyQualifiedString('\\Name\\Space\\a::c,2'), '\\Name\\Space\\a::c,2');
$this->assertFQSENEqual(FullyQualifiedClassConstantName::fromFullyQualifiedString('\\Name\\Space\\a,1::c,2'), '\\Name\\Space\\a,1::c,2');
$this->assertFQSENEqual(FullyQualifiedClassConstantName::fromStringInContext('a::methodName', $this->context), '\\a::methodName');
}
作者:ets
项目:pha
public function testSimple()
{
$context = new Context();
$context_namespace = $context->withNamespace('\\A');
$context_class = $context_namespace->withScope(new ClassScope($context_namespace->getScope(), FullyQualifiedClassName::fromFullyQualifiedString('\\A\\B')));
$context_method = $context_namespace->withScope(new FunctionLikeScope($context_namespace->getScope(), FullyQualifiedMethodName::fromFullyQualifiedString('\\A\\b::c')));
$this->assertTrue(!empty($context));
$this->assertTrue(!empty($context_namespace));
$this->assertTrue(!empty($context_class));
$this->assertTrue(!empty($context_method));
}
作者:ablyle
项目:pha
public function testSimple()
{
$context = new Context();
$context_namespace = $context->withNamespace('\\A');
$context_class = $context_namespace->withClassFQSEN(FullyQualifiedClassName::fromFullyQualifiedString('\\A\\B'));
$context_method = $context_namespace->withMethodFQSEN(FullyQualifiedMethodName::fromFullyQualifiedString('\\A\\b::c'));
$this->assertTrue(!empty($context));
$this->assertTrue(!empty($context_namespace));
$this->assertTrue(!empty($context_class));
$this->assertTrue(!empty($context_method));
}
作者:hslatma
项目:pha
/**
* @param array
* A map from column name to value
*
* @return Model
* An instance of the model derived from row data
*/
public static function fromRow(array $row) : Clazz
{
$parent_fqsen = $row['parent_class_fqsen'] ? FullyQualifiedClassName::fromFullyQualifiedString($row['parent_class_fqsen']) : null;
$interface_fqsen_list = array_map(function (string $fqsen_string) {
return FullyQualifiedClassName::fromFullyQualifiedString($fqsen_string);
}, array_filter(explode('|', $row['interface_fqsen_list'])));
$trait_fqsen_list = array_map(function (string $fqsen_string) {
return FullyQualifiedClassName::fromFullyQualifiedString($fqsen_string);
}, array_filter(explode('|', $row['trait_fqsen_list'])));
$clazz = new ClazzElement(unserialize(base64_decode($row['context'])), $row['name'], UnionType::fromFullyQualifiedString($row['type']), (int) $row['flags'], $parent_fqsen, $interface_fqsen_list, $trait_fqsen_list);
return new Clazz($clazz);
}
作者:tmli3b3rm4
项目:pha
public static function createSchema() : Schema
{
$schema = new Schema('File', [new Column('file_path', Column::TYPE_STRING, true), new Column('modification_time', Column::TYPE_INT)]);
$schema->addAssociation(new ListAssociation('FileClassFQSEN', Column::TYPE_STRING, function (File $file, array $class_fqsen_string_list) {
$file->getFile()->setClassFQSENList(array_map(function (string $fqsen_string) {
return FullyQualifiedClassName::fromFullyQualifiedString($fqsen_string);
}, $class_fqsen_string_list));
}, function (File $file) {
return array_map(function (FullyQualifiedClassName $fqsen) {
return (string) $fqsen;
}, $file->getFile()->getClassFQSENList());
}));
$schema->addAssociation(new ListAssociation('FileMethodFQSEN', Column::TYPE_STRING, function (File $file, array $method_fqsen_string_list) {
$file->getFile()->setMethodFQSENList(array_map(function (string $fqsen_string) {
if (false !== strpos($fqsen_string, '::')) {
return FullyQualifiedMethodName::fromFullyQualifiedString($fqsen_string);
} else {
return FullyQualifiedFunctionName::fromFullyQualifiedString($fqsen_string);
}
}, $method_fqsen_string_list));
}, function (File $file) {
return array_map(function (FQSEN $fqsen) {
return (string) $fqsen;
}, $file->getFile()->getMethodFQSENList());
}));
$schema->addAssociation(new ListAssociation('FilePropertyFQSEN', Column::TYPE_STRING, function (File $file, array $fqsen_string_list) {
$file->getFile()->setPropertyFQSENList(array_map(function (string $fqsen_string) {
if (false !== strpos($fqsen_string, '::')) {
return FullyQualifiedPropertyName::fromFullyQualifiedString($fqsen_string);
} else {
return FullyQualifiedFunctionName::fromFullyQualifiedString($fqsen_string);
}
}, $fqsen_string_list));
}, function (File $file) {
return array_map(function (FQSEN $fqsen) {
return (string) $fqsen;
}, $file->getFile()->getPropertyFQSENList());
}));
$schema->addAssociation(new ListAssociation('FileConstantFQSEN', Column::TYPE_STRING, function (File $file, array $fqsen_string_list) {
$file->getFile()->setConstantFQSENList(array_map(function (string $fqsen_string) {
if (false !== strpos($fqsen_string, '::')) {
return FullyQualifiedConstantName::fromFullyQualifiedString($fqsen_string);
} else {
return FullyQualifiedFunctionName::fromFullyQualifiedString($fqsen_string);
}
}, $fqsen_string_list));
}, function (File $file) {
return array_map(function (FQSEN $fqsen) {
return (string) $fqsen;
}, $file->getFile()->getConstantFQSENList());
}));
return $schema;
}
作者:actan
项目:pha
/**
* Visit a node with kind `\ast\AST_CLASS`
*
* @param Node $node
* A node to parse
*
* @return Context
* A new or an unchanged context resulting from
* parsing the node
*/
public function visitClass(Decl $node) : Context
{
if ($node->flags & \ast\flags\CLASS_ANONYMOUS) {
$class_name = (new ContextNode($this->code_base, $this->context, $node))->getUnqualifiedNameForAnonymousClass();
} else {
$class_name = (string) $node->name;
}
assert(!empty($class_name), "Class name cannot be empty");
$alternate_id = 0;
// Hunt for the alternate of this class defined
// in this file
do {
$class_fqsen = FullyQualifiedClassName::fromStringInContext($class_name, $this->context)->withAlternateId($alternate_id++);
if (!$this->code_base->hasClassWithFQSEN($class_fqsen)) {
throw new CodeBaseException($class_fqsen, "Can't find class {$class_fqsen} - aborting");
}
$clazz = $this->code_base->getClassByFQSEN($class_fqsen);
} while ($this->context->getProjectRelativePath() != $clazz->getContext()->getProjectRelativePath() || $this->context->getLineNumberStart() != $clazz->getContext()->getLineNumberStart());
return $clazz->getContext()->withClassFQSEN($class_fqsen);
}
作者:tpun
项目:pha
/**
* @param Context $context
* The context in which the FQSEN string was found
*
* @param $fqsen_string
* An FQSEN string like '\Namespace\Class::methodName'
*
* @return FullyQualifiedMethodName
*/
public static function fromStringInContext(string $fqsen_string, Context $context)
{
// Test to see if we have a class defined
if (false === strpos($fqsen_string, '::')) {
assert($context->isInClassScope(), "Cannot reference class element without class name when not in class scope.");
$fully_qualified_class_name = $context->getClassFQSEN();
} else {
assert(false !== strpos($fqsen_string, '::'), "Fully qualified class element lacks '::' delimiter");
list($class_name_string, $fqsen_string) = explode('::', $fqsen_string);
$fully_qualified_class_name = FullyQualifiedClassName::fromStringInContext($class_name_string, $context);
}
// Split off the alternate ID
$parts = explode(',', $fqsen_string);
$name = $parts[0];
$alternate_id = (int) ($parts[1] ?? 0);
assert(is_int($alternate_id), "Alternate must be an integer");
return static::make($fully_qualified_class_name, $name, $alternate_id);
}
作者:ablyle
项目:pha
/**
* @return array
* A map from alias to target
*/
private function aliasTargetMapFromUseNode(Node $node, string $prefix = '') : array
{
assert($node->kind == \ast\AST_USE, 'Method takes AST_USE nodes');
$map = [];
foreach ($node->children ?? [] as $child_node) {
$target = $child_node->children['name'];
if (empty($child_node->children['alias'])) {
if (($pos = strrpos($target, '\\')) !== false) {
$alias = substr($target, $pos + 1);
} else {
$alias = $target;
}
} else {
$alias = $child_node->children['alias'];
}
// if AST_USE does not have any flags set, then its AST_USE_ELEM
// children will (this will be for AST_GROUP_USE)
if ($node->flags !== 0) {
$target_node = $node;
} else {
$target_node = $child_node;
}
if ($target_node->flags == T_FUNCTION) {
$parts = explode('\\', $target);
$function_name = array_pop($parts);
$target = FullyQualifiedFunctionName::make($prefix . '\\' . implode('\\', $parts), $function_name);
} else {
if ($target_node->flags == T_CONST) {
$parts = explode('\\', $target);
$name = array_pop($parts);
$target = FullyQualifiedGlobalConstantName::make($prefix . '\\' . implode('\\', $parts), $name);
} else {
$target = FullyQualifiedClassName::fromFullyQualifiedString($prefix . '\\' . $target);
}
}
$map[$alias] = [$target_node->flags, $target];
}
return $map;
}
作者:hslatma
项目:pha
/**
* @param Node $node
* A node to parse
*
* @return Context
* A new or an unchanged context resulting from
* parsing the node
*/
public function visitCatch(Node $node) : Context
{
// Get the name of the class
$class_name = $node->children['class']->children['name'];
$clazz = null;
// If we can't figure out the class name (which happens
// from time to time), then give up
if (!empty($class_name)) {
$class_fqsen = FullyQualifiedClassName::fromStringInContext($class_name, $this->context);
// Check to see if the class actually exists
if ($this->code_base->hasClassWithFQSEN($class_fqsen)) {
$clazz = $this->code_base->getClassByFQSEN($class_fqsen);
} else {
Log::err(Log::EUNDEF, "call to method on undeclared class {$class_name}", $this->context->getFile(), $node->lineno);
}
}
$variable_name = AST::variableName($node->children['var']);
if (!empty($variable_name)) {
$variable = Variable::fromNodeInContext($node->children['var'], $this->context, $this->code_base, false);
if ($clazz) {
$variable->setUnionType($clazz->getUnionType());
}
$this->context->addScopeVariable($variable);
}
return $this->context;
}
作者:black-silenc
项目:pha
/**
* @param CodeBase $code_base
* A reference to the entire code base in which this
* context exists
*
* @param ReflectionClass $class
* A reflection class representing a builtin class.
*
* @return Clazz
* A Class structural element representing the given named
* builtin.
*/
public static function fromReflectionClass(CodeBase $code_base, \ReflectionClass $class) : Clazz
{
// Build a set of flags based on the constitution
// of the built-in class
$flags = 0;
if ($class->isFinal()) {
$flags = \ast\flags\CLASS_FINAL;
} elseif ($class->isInterface()) {
$flags = \ast\flags\CLASS_INTERFACE;
} elseif ($class->isTrait()) {
$flags = \ast\flags\CLASS_TRAIT;
}
if ($class->isAbstract()) {
$flags |= \ast\flags\CLASS_ABSTRACT;
}
$context = new Context();
// Build a base class element
$clazz = new Clazz($context, $class->getName(), UnionType::fromStringInContext($class->getName(), $context), $flags);
$clazz->setFQSEN(FullyQualifiedClassName::fromStringInContext($class->getName(), $context));
// If this class has a parent class, add it to the
// class info
if ($parent_class = $class->getParentClass()) {
$parent_class_fqsen = FullyQualifiedClassName::fromFullyQualifiedString('\\' . $parent_class->getName());
$clazz->setParentClassFQSEN($parent_class_fqsen);
}
foreach ($class->getDefaultProperties() as $name => $value) {
// TODO: whats going on here?
$reflection_property = new \ReflectionProperty($class->getName(), $name);
$property_context = $context->withClassFQSEN($clazz->getFQSEN());
$property = new Property($property_context, $name, Type::fromObject($value)->asUnionType(), 0);
$property->setFQSEN(FullyQualifiedPropertyName::make($clazz->getFQSEN(), $name));
$clazz->addProperty($code_base, $property);
}
foreach ($class->getInterfaceNames() as $name) {
$clazz->addInterfaceClassFQSEN(FullyQualifiedClassName::fromFullyQualifiedString('\\' . $name));
}
foreach ($class->getTraitNames() as $name) {
$clazz->addTraitFQSEN(FullyQualifiedClassName::fromFullyQualifiedString('\\' . $name));
}
foreach ($class->getConstants() as $name => $value) {
$constant = new ClassConstant($context, $name, Type::fromObject($value)->asUnionType(), 0);
$constant->setFQSEN(FullyQualifiedClassConstantName::make($clazz->getFQSEN(), $name));
$clazz->addConstant($code_base, $constant);
}
foreach ($class->getMethods() as $reflection_method) {
$method_list = FunctionFactory::methodListFromReflectionClassAndMethod($context->withClassFQSEN($clazz->getFQSEN()), $code_base, $class, $reflection_method);
foreach ($method_list as $method) {
$clazz->addMethod($code_base, $method);
}
}
return $clazz;
}
作者:gitter-badge
项目:pha
public function unserialize($serialized)
{
list($file_ref, $serialized) = explode('^', $serialized);
parent::unserialize($file_ref);
list($namespace, $is_conditional, $class_fqsen, $method_fqsen, $closure_fqsen) = explode('|', $serialized);
$this->namespace = $namespace;
$this->is_conditional = (bool) $is_conditional;
$this->class_fqsen = $class_fqsen ? FullyQualifiedClassName::fromFullyQualifiedString($class_fqsen) : null;
$this->method_fqsen = $method_fqsen ? FullyQualifiedMethodName::fromFullyQualifiedString($method_fqsen) : null;
$this->closure_fqsen = $closure_fqsen ? FullyQualifiedFunctionName::fromFullyQualifiedString($closure_fqsen) : null;
}
作者:hslatma
项目:pha
/**
* @return FQSEN
*/
public function getFQSEN() : FullyQualifiedClassName
{
// Allow overrides
if ($this->fqsen) {
return $this->fqsen;
}
return FullyQualifiedClassName::fromStringInContext($this->getName(), $this->getContext());
}
作者:nagyistg
项目:pha
/**
* @return void
*/
public function unserialize($serialized)
{
list($file_ref, $serialized) = explode('^', $serialized);
parent::unserialize($file_ref);
list($namespace, $class_fqsen, $method_fqsen, $closure_fqsen) = explode('|', $serialized);
$this->namespace = $namespace;
$this->class_fqsen = $class_fqsen ? FullyQualifiedClassName::fromFullyQualifiedString($class_fqsen) : null;
// Determine if we have a method or a function
if (false === strpos($method_fqsen, '::')) {
$this->method_fqsen = $method_fqsen ? FullyQualifiedFunctionName::fromFullyQualifiedString($method_fqsen) : null;
} else {
$this->method_fqsen = $method_fqsen ? FullyQualifiedMethodName::fromFullyQualifiedString($method_fqsen) : null;
}
$this->closure_fqsen = $closure_fqsen ? FullyQualifiedFunctionName::fromFullyQualifiedString($closure_fqsen) : null;
}
作者:tmli3b3rm4
项目:pha
/**
* @param Node $node
* The node that has a reference to a class
*
* @param Context $context
* The context in which we found the node
*
* @param CodeBase $code_base
* The global code base holding all state
*
* @param bool $validate_class_name
* If true, we'll validate that the name of the class
* is valid.
*
* @return Clazz
* The class being referenced in the given node in
* the given context
*
* @throws NodeException
* An exception is thrown if we can't understand the node
*
* @throws CodeBaseExtension
* An exception is thrown if we can't find the referenced
* class
*
* @throws TypeException
* An exception may be thrown if the only viable candidate
* is a non-class type.
*/
public static function classFromNodeInContext(Node $node, Context $context, CodeBase $code_base, bool $validate_class_name = true) : Clazz
{
// Figure out the name of the class
$class_name = self::classNameFromNode($context, $code_base, $node, $validate_class_name);
// If we can't figure out the class name (which happens
// from time to time), then give up
if (empty($class_name)) {
throw new NodeException($node, 'Could not find class name');
}
$class_fqsen = FullyQualifiedClassName::fromStringInContext($class_name, $context);
// Check to see if the class actually exists
if (!$code_base->hasClassWithFQSEN($class_fqsen)) {
throw new CodeBaseException("Can't find class {$class_fqsen}");
}
$class = $code_base->getClassByFQSEN($class_fqsen);
return $class;
}
作者:themario
项目:pha
/**
* Visit a node with kind `\ast\AST_METHOD_CALL`
*
* @param Node $node
* A node of the type indicated by the method name that we'd
* like to figure out the type that it produces.
*
* @return UnionType
* The set of types that are possibly produced by the
* given node
*/
public function visitMethodCall(Node $node) : UnionType
{
$class_name = AST::classNameFromNode($this->context, $this->code_base, $node);
if (empty($class_name)) {
return new UnionType();
}
$class_fqsen = FullyQualifiedClassName::fromstringInContext($class_name, $this->context);
assert($this->code_base->hasClassWithFQSEN($class_fqsen), "Class {$class_fqsen} must exist");
$clazz = $this->code_base->getClassByFQSEN($class_fqsen);
$method_name = $node->children['method'];
// Give up on any complicated nonsense where the
// method name is a variable such as in
// `$variable->$function_name()`.
if ($method_name instanceof Node) {
return new UnionType();
}
// Method names can some times turn up being
// other method calls.
assert(is_string($method_name), "Method name must be a string. Something else given.");
if (!$clazz->hasMethodWithName($this->code_base, $method_name)) {
Log::err(Log::EUNDEF, "call to undeclared method {$class_fqsen}->{$method_name}()", $this->context->getFile(), $node->lineno);
return new UnionType();
}
$method = $clazz->getMethodByNameInContext($this->code_base, $method_name, $this->context);
return $method->getUnionType();
}
作者:PHPfork
项目:pha
/**
* @param Node $node
* A node of the type indicated by the method name that we'd
* like to figure out the type that it produces.
*
* @return string
* The class name represented by the given call
*/
public function visitMethodCall(Node $node) : string
{
if ($node->children['expr']->kind == \ast\AST_VAR) {
if ($node->children['expr']->children['name'] instanceof Node) {
return '';
}
// $var->method()
if ($node->children['expr']->children['name'] == 'this') {
if (!$this->context->isInClassScope()) {
Log::err(Log::ESTATIC, 'Using $this when not in object context', $this->context->getFile(), $node->lineno);
return '';
}
return (string) $this->context->getClassFQSEN();
}
$variable_name = $node->children['expr']->children['name'];
if (!$this->context->getScope()->hasVariableWithName($variable_name)) {
// Got lost, couldn't find the variable in the current scope
// If it really isn't defined, it will be caught by the
// undefined var error
return '';
}
$variable = $this->context->getScope()->getVariableWithName($variable_name);
// Hack - loop through the possible types of the var and assume
// first found class is correct
foreach ($variable->getUnionType()->nonGenericArrayTypes()->getTypeList() as $type) {
$child_class_fqsen = FullyQualifiedClassName::fromStringInContext((string) $type, $this->context);
if ($this->code_base->hasClassWithFQSEN($child_class_fqsen)) {
return (string) FullyQualifiedClassName::fromStringInContext((string) $type, $this->context);
}
}
// Could not find name
return '';
}
if ($node->children['expr']->kind == \ast\AST_PROP) {
$prop = $node->children['expr'];
if (!($prop->children['expr']->kind == \ast\AST_VAR && !$prop->children['expr']->children['name'] instanceof Node)) {
return '';
}
// $var->prop->method()
$var = $prop->children['expr'];
if ($var->children['name'] == 'this') {
// If we're not in a class scope, 'this' won't work
if (!$this->context->isInClassScope()) {
Log::err(Log::ESTATIC, 'Using $this when not in object context', $this->context->getFile(), $node->lineno);
return '';
}
// Get the class in scope
$clazz = $this->code_base->getClassByFQSEN($this->context->getClassFQSEN());
if ($prop->children['prop'] instanceof Node) {
// $this->$prop->method() - too dynamic, give up
return '';
}
$property_name = $prop->children['prop'];
if ($clazz->hasPropertyWithName($this->code_base, $property_name)) {
try {
$property = $clazz->getPropertyByNameInContext($this->code_base, $property_name, $this->context);
} catch (AccessException $exception) {
Log::err(Log::EACCESS, $exception->getMessage(), $this->context->getFile(), $node->lineno);
return '';
}
// Find the first viable property type
foreach ($property->getUnionType()->nonGenericArrayTypes()->getTypeList() as $type) {
$class_fqsen = FullyQualifiedClassName::fromStringInContext((string) $type, $this->context);
if ($this->code_base->hasClassWithFQSEN($class_fqsen)) {
return (string) $class_fqsen;
}
}
}
// No such property was found, or none were classes
// that could be found
return '';
}
return '';
}
if ($node->children['expr']->kind == \ast\AST_METHOD_CALL) {
// Get the type returned by the first method
// call.
$union_type = UnionType::fromNode($this->context, $this->code_base, $node->children['expr']);
// Find the subset of types that are viable
// classes
$viable_class_types = $union_type->nonNativeTypes()->nonGenericArrayTypes();
// If there are no non-native types, give up
if ($viable_class_types->isEmpty()) {
return '';
}
// Return the first non-native type in the
// list and hope its a class
return (string) $viable_class_types->head();
}
return '';
}
作者:ets
项目:pha
/**
* @param string $name
* The name of the property
*
* @param Context $context
* The context of the caller requesting the property
*
* @return Property
* A property with the given name
*
* @throws IssueException
* An exception may be thrown if the caller does not
* have access to the given property from the given
* context
*/
public function getPropertyByNameInContext(CodeBase $code_base, string $name, Context $context) : Property
{
// Get the FQSEN of the property we're looking for
$property_fqsen = FullyQualifiedPropertyName::make($this->getFQSEN(), $name);
$property = null;
// Figure out if we have the property
$has_property = $code_base->hasPropertyWithFQSEN($property_fqsen);
// Figure out if the property is accessible
$is_property_accessible = false;
if ($has_property) {
$property = $code_base->getPropertyByFQSEN($property_fqsen);
$is_remote_access = !$context->isInClassScope() || !$context->getClassInScope($code_base)->getUnionType()->canCastToExpandedUnionType($this->getUnionType(), $code_base);
$is_property_accessible = !$is_remote_access || $property->isPublic();
}
// If the property exists and is accessible, return it
if ($is_property_accessible) {
return $property;
}
// Check to see if we can use a __get magic method
if ($this->hasMethodWithName($code_base, '__get')) {
$method = $this->getMethodByName($code_base, '__get');
// Make sure the magic method is accessible
if ($method->isPrivate()) {
throw new IssueException(Issue::fromType(Issue::AccessPropertyPrivate)($context->getFile(), $context->getLineNumberStart(), [(string) $property_fqsen]));
} else {
if ($method->isProtected()) {
throw new IssueException(Issue::fromType(Issue::AccessPropertyProtected)($context->getFile(), $context->getLineNumberStart(), [(string) $property_fqsen]));
}
}
$property = new Property($context, $name, $method->getUnionType(), 0, $property_fqsen);
$this->addProperty($code_base, $property, new None());
return $property;
} else {
if ($has_property) {
// If we have a property, but its inaccessible, emit
// an issue
if ($property->isPrivate()) {
throw new IssueException(Issue::fromType(Issue::AccessPropertyPrivate)($context->getFile(), $context->getLineNumberStart(), ["{$this->getFQSEN()}::\${$property->getName()}"]));
}
if ($property->isProtected()) {
throw new IssueException(Issue::fromType(Issue::AccessPropertyProtected)($context->getFile(), $context->getLineNumberStart(), ["{$this->getFQSEN()}::\${$property->getName()}"]));
}
}
}
// Check to see if missing properties are allowed
// or we're stdclass
if (Config::get()->allow_missing_properties || $this->getFQSEN() == FullyQualifiedClassName::getStdClassFQSEN()) {
$property = new Property($context, $name, new UnionType(), 0, $property_fqsen);
$this->addProperty($code_base, $property, new None());
return $property;
}
throw new IssueException(Issue::fromType(Issue::UndeclaredProperty)($context->getFile(), $context->getLineNumberStart(), ["{$this->getFQSEN()}::\${$name}}"]));
}
作者:ets
项目:pha
/**
* @return FullyQualifiedGlobalStructuralElement
* The namespace mapped name for the given flags and name
*/
public function getNamespaceMapFor(int $flags, string $name) : FullyQualifiedGlobalStructuralElement
{
$name = strtolower($name);
// Look for the mapping on the part before a
// slash
$name_parts = explode('\\', $name, 2);
$suffix = '';
if (count($name_parts) > 1) {
$name = $name_parts[0];
$suffix = $name_parts[1];
}
assert(!empty($this->namespace_map[$flags][$name]), "No namespace defined for name");
assert($this->namespace_map[$flags][$name] instanceof FQSEN, "Namespace map was not an FQSEN");
$fqsen = $this->namespace_map[$flags][$name];
if (!$suffix) {
return $fqsen;
}
switch ($flags) {
case \ast\flags\USE_NORMAL:
return FullyQualifiedClassName::fromFullyQualifiedString((string) $fqsen . '\\' . $suffix);
case \ast\flags\USE_FUNCTION:
return FullyQualifiedFunctionName::fromFullyQualifiedString((string) $fqsen . '\\' . $suffix);
}
assert(false, "Unknown flag {$flags}");
return $fqsen;
}