Example #1
0
 public static function createSchema() : Schema
 {
     $schema = new Schema('Parameter', [new Column('id', Column::TYPE_INT, true, true), new Column('method_fqsen', Column::TYPE_STRING), new Column('name', Column::TYPE_STRING), new Column('type', Column::TYPE_STRING), new Column('flags', Column::TYPE_INT), new Column('context', Column::TYPE_STRING), new Column('is_deprecated', Column::TYPE_BOOL)]);
     // Enforce that we only save one reference per line. Its OK
     // if we overwrite on things like `[C::f(1), C::f(2)]`.
     $schema->addCreateQuery("CREATE INDEX IF NOT EXISTS Parameter_Method_FQSEN" . " ON `Parameter` " . " (method_fqsen)");
     return $schema;
 }
Example #2
0
 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;
 }
Example #3
0
 public static function createSchema() : Schema
 {
     $schema = new Schema('CalledBy', [new Column('id', Column::TYPE_INT, true, true), new Column('fqsen_string', Column::TYPE_STRING), new Column('file_path', Column::TYPE_STRING), new Column('line_number', Column::TYPE_INT)]);
     // Enforce that we only save one reference per line. Its OK
     // if we overwrite on things like `[C::f(1), C::f(2)]`.
     $schema->addCreateQuery("CREATE UNIQUE INDEX IF NOT EXISTS CalledBy_fqsen_file_line" . " ON `CalledBy` " . " (fqsen_string, file_path, line_number)");
     // Find all callers by FQSEN
     $schema->addCreateQuery("CREATE INDEX IF NOT EXISTS CalledBy_fqsen" . " ON `CalledBy` " . " (fqsen_string)");
     // Find all references by File (so we can delete 'em
     // when the file changes).
     $schema->addCreateQuery("CREATE INDEX IF NOT EXISTS CalledBy_file" . " ON `CalledBy` " . " (file_path)");
     return $schema;
 }
Example #4
0
 /**
  * @return Schema
  * The schema for this model
  */
 public static function createSchema() : Schema
 {
     $schema = new Schema('Method', [new Column('scope_name', Column::TYPE_STRING, true), new Column('fqsen', Column::TYPE_STRING), new Column('name', Column::TYPE_STRING), new Column('type', Column::TYPE_STRING), new Column('flags', Column::TYPE_INT), new Column('context', Column::TYPE_STRING), new Column('is_deprecated', Column::TYPE_BOOL), new Column('number_of_required_parameters', Column::TYPE_INT), new Column('number_of_optional_parameters', Column::TYPE_INT)]);
     $parameter_association = new ModelListAssociation('MethodParameter', '\\Phan\\Model\\Parameter', function (Method $method, array $parameter_list) {
         $method->getMethod()->setParameterList(array_map(function (Parameter $parameter) {
             return $parameter->getParameter();
         }, $parameter_list));
     }, function (Method $method) {
         return array_map(function (ParameterElement $parameter_element) use($method) : Parameter {
             return new Parameter($parameter_element, $method->getMethod()->getFQSEN());
         }, $method->getMethod()->getParameterList());
     });
     // TODO: Add a custom select query
     $schema->addAssociation($parameter_association);
     return $schema;
 }
Example #5
0
 /**
  * @param string $table_name
  * The table we'll be interacting with
  *
  * @param string $item_sql_type
  * The type of items being stored
  *
  * @param \Closure $read_closure
  * A closure that accepts a map from keys to models
  * that are to be handled by the source model
  *
  * @param \Closure $write_closure
  * A closure that returns an array mapping string keys
  * to model objects that will be written.
  */
 public function __construct(string $table_name, string $item_sql_type, \Closure $read_closure, \Closure $write_closure)
 {
     $schema = new Schema($table_name, [new Column('id', Column::TYPE_INT, true, true), new Column('source_pk', 'STRING'), new Column('value', $item_sql_type)]);
     $schema->addCreateQuery("CREATE UNIQUE INDEX IF NOT EXISTS {$table_name}_source_pk_value ON `{$table_name}` " . " (source_pk, value)");
     parent::__construct($schema, $read_closure, $write_closure);
 }