public function testFullyQualifiedGlobalConstantName() { $this->assertFQSENEqual(FullyQualifiedGlobalConstantName::make('\\Name\\Space', 'c'), '\\Name\\Space\\c'); $this->assertFQSENEqual(FullyQualifiedGlobalConstantName::make('', 'c'), '\\c'); $this->assertFQSENEqual(FullyQualifiedGlobalConstantName::make('', 'c'), '\\c'); $this->assertFQSENEqual(FullyQualifiedGlobalConstantName::fromFullyQualifiedString('\\c'), '\\c'); $this->assertFQSENEqual(FullyQualifiedGlobalConstantName::fromStringInContext('c', $this->context), '\\c'); }
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 FullyQualifiedClassConstantName::fromFullyQualifiedString($fqsen_string); } else { return FullyQualifiedGlobalConstantName::fromFullyQualifiedString($fqsen_string); } }, $fqsen_string_list)); }, function (File $file) { return array_map(function (FQSEN $fqsen) { return (string) $fqsen; }, $file->getFile()->getConstantFQSENList()); })); return $schema; }
/** * @return GlobalConstant * Get the (non-class) constant associated with this node * in this 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 given * class */ public function getConst() : GlobalConstant { assert($this->node->kind === \ast\AST_CONST, "Node must be of type \\ast\\AST_CONST"); if ($this->node->children['name']->kind !== \ast\AST_NAME) { throw new NodeException($this->node, "Can't determine constant name"); } $constant_name = $this->node->children['name']->children['name']; $fqsen = FullyQualifiedGlobalConstantName::fromStringInContext($constant_name, $this->context); if (!$this->code_base->hasGlobalConstantWithFQSEN($fqsen)) { $fqsen = FullyQualifiedGlobalConstantName::fromFullyQualifiedString($constant_name); if (!$this->code_base->hasGlobalConstantWithFQSEN($fqsen)) { throw new IssueException(Issue::fromType(Issue::UndeclaredConstant)($this->context->getFile(), $this->node->lineno ?? 0, [$fqsen])); } } return $this->code_base->getGlobalConstantByFQSEN($fqsen); }
/** * @param array * A map from column name to value * * @return Constant * An instance of the model derived from row data */ public static function fromRow(array $row) : Constant { list($scope, $name) = explode('|', $row['scope_name']); $constant = new Constant(new ConstantElement(unserialize(base64_decode($row['context'])), $row['name'], UnionType::fromFullyQualifiedString($row['type']), (int) $row['flags']), $scope, $name); if (false !== strpos($row['fqsen'], '::')) { $fqsen = FullyQualifiedClassConstantName::fromFullyQualifiedString($row['fqsen']); } else { $fqsen = FullyQualifiedGlobalConstantName::fromFullyQualifiedString($row['fqsen']); } $constant->getConstant()->setFQSEN($fqsen); return $constant; }