Type aliases could be defined either globally (https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases) or just for a class.
I prefer having them at the place where they are created.
}
/** Connect to the database
- * @param array [$server, $username, $password]
+ * @param array{string, string, string} [$server, $username, $password]
* @return mixed Db or string for error
*/
function connect($credentials) {
/** Get table status
* @param string
* @param bool return only "Name", "Engine" and "Comment" fields
- * @return array{Name:string, Engine:string, Comment:string, Oid:int, Rows:int, Collation:string, Auto_increment:int, Data_length:int, Index_length:int, Data_free:int}[]
+ * @return TableStatus[]
+ * @phpstan-type TableStatus array{Name:string, Engine:string, Comment:string, Oid:int, Rows:int, Collation:string, Auto_increment:int, Data_length:int, Index_length:int, Data_free:int}
*/
function table_status($name = "", $fast = false) {
$return = array();
}
/** Find out whether the identifier is view
- * @param array
+ * @param TableStatus
* @return bool
*/
function is_view($table_status) {
}
/** Check if table supports foreign keys
- * @param array result of table_status
+ * @param TableStatus result of table_status1()
* @return bool
*/
function fk_support($table_status) {
/** Get information about fields
* @param string
- * @return array{field:string, full_type:string, type:string, length:int, unsigned:string, default:string, null:bool, auto_increment:bool, on_update:string, collation:string, privileges:int[], comment:string, primary:bool, generated:string}[]
+ * @return Field[]
+ * @phpstan-type Field array{field:string, full_type:string, type:string, length:int, unsigned:string, default:string, null:bool, auto_increment:bool, on_update:string, collation:string, privileges:int[], comment:string, primary:bool, generated:string}
*/
function fields($table) {
global $connection;
/** Get table indexes
* @param string
* @param string Db to use
- * @return array{type:string, columns:list<string>, lengths:list<int>, descs:list<bool>}[]
+ * @return Index[]
+ * @phpstan-type Index array{type:string, columns:list<string>, lengths:list<int>, descs:list<bool>}
*/
function indexes($table, $connection2 = null) {
$return = array();
/** Get foreign keys in table
* @param string
- * @return array{db:string, ns:string, table:string, source:list<string>, target:list<string>, on_delete:string, on_update:string}[]
+ * @return ForeignKey[]
+ * @phpstan-type ForeignKey array{db:string, ns:string, table:string, source:list<string>, target:list<string>, on_delete:string, on_update:string}
*/
function foreign_keys($table) {
global $driver;
/** Run commands to create or alter table
* @param string "" to create
* @param string new name
- * @param array of [$orig, $process_field, $after]
+ * @param list<array{string, list<string>, string}> of [$orig, $process_field, $after]
* @param list<string>
* @param string
* @param string
/** Run commands to alter indexes
* @param string escaped table name
- * @param array[] of ["index type", "name", ["column definition", ...]] or ["index type", "name", "DROP"]
+ * @param array{string, string, 'DROP'|list<string>} of ["index type", "name", ["column definition", ...]] or ["index type", "name", "DROP"]
* @return bool
*/
function alter_indexes($table, $alter) {
/** Get information about trigger
* @param string trigger name
- * @return array{Trigger:string, Timing:string, Event:string, Of:string, Type:string, Statement:string}
+ * @return Trigger
+ * @phpstan-type Trigger array{Trigger:string, Timing:string, Event:string, Of:string, Type:string, Statement:string}
*/
function trigger($name) {
if ($name == "") {
/** Get defined triggers
* @param string
- * @return array{string, string}[]4
+ * @return array{string, string}[]
*/
function triggers($table) {
$return = array();
/** Get information about stored routine
* @param string
* @param string "FUNCTION" or "PROCEDURE"
- * @return array{fields:list<array{field:string, type:string, length:string, unsigned:string, null:bool, full_type:string, inout:string, collation:string}>, comment:string, returns:array, definition:string, language:string}
+ * @return Routine
+ * @phpstan-type Routine array{fields:list<array{field:string, type:string, length:string, unsigned:string, null:bool, full_type:string, inout:string, collation:string}>, comment:string, returns:array, definition:string, language:string}
*/
function routine($name, $type) {
global $driver;
/** Get routine signature
* @param string
- * @param array result of routine()
+ * @param Routine result of routine()
* @return string
*/
function routine_id($name, $row) {
}
/** Get approximate number of rows
- * @param array
+ * @param TableStatus
* @param list<string>
* @return int or null if approximate number can't be retrieved
*/
}
/** Convert field in select and edit
- * @param array one element from fields()
+ * @param Field one element from fields()
* @return string
*/
function convert_field($field) {
}
/** Convert value in edit after applying functions back
- * @param array one element from fields()
+ * @param Field one element from fields()
* @param string SQL expression
* @return string
*/
* @param string[] [$original => idf_escape($new_column)], empty to preserve
* @param string [format_foreign_key()], empty to preserve
* @param int set auto_increment to this value, 0 to preserve
- * @param array[] [[$type, $name, $columns]], empty to preserve
+ * @param list<array{string, string, list<string>|'DROP'}> [[$type, $name, $columns]], empty to preserve
* @param string CHECK constraint to drop
* @param string CHECK constraint to add
* @return bool
}
/** Table caption used in navigation and headings
- * @param array result of SHOW TABLE STATUS
+ * @param TableStatus result of table_status1()
* @return string HTML code, "" to ignore table
*/
function tableName($tableStatus) {
}
/** Field caption used in select and edit
- * @param array single field returned from fields()
+ * @param Field single field returned from fields()
* @param int order of column in select
* @return string HTML code, "" to ignore field
*/
}
/** Print links after select heading
- * @param array result of SHOW TABLE STATUS
+ * @param TableStatus result of table_status1()
* @param string new item options, NULL for no new item
* @return null
*/
/** Get foreign keys for table
* @param string
- * @return array[] same format as foreign_keys()
+ * @return ForeignKey[] same format as foreign_keys()
*/
function foreignKeys($table) {
return foreign_keys($table);
/** Find backward keys for table
* @param string
* @param string
- * @return array{keys:string[][], name:string}[]
+ * @return BackwardKey[]
+ * @phpstan-type BackwardKey array{name:string, keys:string[][]}
*/
function backwardKeys($table, $tableName) {
return array();
}
/** Print backward keys for row
- * @param array[] result of $this->backwardKeys()
+ * @param BackwardKey[] result of $this->backwardKeys()
* @param string[]
* @return null
*/
/** Get descriptions of selected data
* @param list<string[]> all data to print
- * @param array[]
+ * @param ForeignKey[]
* @return list<string[]>
*/
function rowDescriptions($rows, $foreignKeys) {
/** Get a link to use in select table
* @param string raw value of the field
- * @param array single field returned from fields()
+ * @param Field single field returned from fields()
* @return string or null to create the default link
*/
function selectLink($val, $field) {
/** Value printed in select table
* @param string HTML-escaped value to print
* @param string link to foreign key
- * @param array single field returned from fields()
+ * @param Field single field returned from fields()
* @param string original value before applying editVal() and escaping
* @return string
*/
/** Value conversion used in select and edit
* @param string
- * @param array single field returned from fields()
+ * @param Field single field returned from fields()
* @return string
*/
function editVal($val, $field) {
}
/** Print table structure in tabular format
- * @param array[] data about individual fields
- * @param array
+ * @param Field[] data about individual fields
+ * @param TableStatus
* @return null
*/
function tableStructurePrint($fields, $tableStatus = null) {
}
/** Print list of indexes on table in tabular format
- * @param array[] data about all indexes on a table
+ * @param Index[] data about all indexes on a table
* @return null
*/
function tableIndexesPrint($indexes) {
/** Print search box in select
* @param list<string> result of selectSearchProcess()
* @param string[] selectable columns
- * @param array[]
+ * @param Index[]
* @return null
*/
function selectSearchPrint($where, $columns, $indexes) {
/** Print order box in select
* @param list<string> result of selectOrderProcess()
* @param string[] selectable columns
- * @param array[]
+ * @param Index[]
* @return null
*/
function selectOrderPrint($order, $columns, $indexes) {
}
/** Print action box in select
- * @param array[]
+ * @param Index[]
* @return null
*/
function selectActionPrint($indexes) {
/** Process columns box in select
* @param string[] selectable columns
- * @param array[]
+ * @param Index[]
* @return list<list<string>> [[select_expressions], [group_expressions]]
*/
function selectColumnsProcess($columns, $indexes) {
}
/** Process search box in select
- * @param array[]
- * @param array[]
+ * @param Field[]
+ * @param Index[]
* @return list<string> expressions to join by AND
*/
function selectSearchProcess($fields, $indexes) {
}
/** Process order box in select
- * @param array[]
- * @param array[]
+ * @param Field[]
+ * @param Index[]
* @return list<string> expressions to join by comma
*/
function selectOrderProcess($fields, $indexes) {
/** Process extras in select form
* @param string[] AND conditions
- * @param array[]
+ * @param ForeignKey[]
* @return bool true if processed, false to process other parts of form
*/
function selectEmailProcess($where, $foreignKeys) {
}
/** Functions displayed in edit form
- * @param array single field from fields()
+ * @param Field single field from fields()
* @return list<string>
*/
function editFunctions($field) {
/** Get options to display edit field
* @param string table name
- * @param array single field from fields()
+ * @param Field single field from fields()
* @param string attributes to use inside the tag
* @param string
* @return string custom input field or empty string for default
/** Get hint for edit field
* @param string table name
- * @param array single field from fields()
+ * @param Field single field from fields()
* @param string
* @return string
*/
}
/** Process sent input
- * @param array single field from fields()
+ * @param Field single field from fields()
* @param string
* @param string
* @return string expression to use in a query
}
/** Set up syntax highlight for code and <textarea>
- * @param array[] result of table_status('', true)
+ * @param TableStatus[] result of table_status('', true)
*/
function syntaxHighlighting($tables) {
global $connection;
}
/** Print table list in menu
- * @param array result of table_status('', true)
+ * @param TableStatus[] result of table_status('', true)
* @return null
*/
function tablesPrint($tables) {
}
/** Get enum values
- * @param array
+ * @param Field
* @return string or null
*/
function enumLength($field) {
}
/** Function used to convert the value inputted by user
- * @param array
+ * @param Field
* @return string or null
*/
function unconvertFunction($field) {
/** Convert column to be searchable
* @param string escaped column name
- * @param array ["op" => , "val" => ]
- * @param array
+ * @param array{op:string, val:string}
+ * @param Field
* @return string
*/
function convertSearch($idf, $val, $field) {
/** Convert value returned by database to actual value
* @param string
- * @param array
+ * @param Field
* @return string
*/
function value($val, $field) {
}
/** Check whether table supports indexes
- * @param array result of table_status1()
+ * @param TableStatus result of table_status1()
* @return bool
*/
function supportsIndex($table_status) {
/** Get referencable tables with single column primary key except self
* @param string
-* @return array[] [$table_name => $field]
+* @return Field[] [$table_name => $field]
*/
function referencable_primary($self) {
$return = array(); // table_name => field
/** Print table columns for type edit
* @param string
-* @param list<string>[]
-* @param array[]
-* @param array[] returned by referencable_primary()
+* @param Field
+* @param list<string>
+* @param Field[] returned by referencable_primary()
* @param list<string> extra types to prepend
* @return null
*/
}
/** Create SQL string from field type
-* @param array
+* @param Field
* @param string
* @return string
*/
}
/** Create SQL string from field
-* @param array basic field information
-* @param array information about field type
+* @param Field basic field information
+* @param Field information about field type
* @return list<string> ["field", "type", "NULL", "DEFAULT", "ON UPDATE", "COMMENT", "AUTO_INCREMENT"]
*/
function process_field($field, $type_field) {
}
/** Get default value clause
-* @param array
+* @param Field
* @return string
*/
function default_value($field) {
}
/** Print table interior for fields editing
-* @param array[]
+* @param Field[]
* @param list<string>[]
* @param string TABLE or PROCEDURE
-* @param array[] returned by referencable_primary()
+* @param Field[] returned by referencable_primary()
* @return null
*/
function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = array()) {
}
/** Move fields up and down or add field
-* @param array[]
+* @param Field[]
* @return bool
*/
function process_fields(&$fields) {
/** Generate SQL query for creating trigger
* @param string
-* @param array result of trigger()
+* @param Trigger result of trigger()
* @return string
*/
function create_trigger($on, $row) {
}
/** Format foreign key to use in SQL query
-* @param array ["db" => string, "ns" => string, "table" => string, "source" => array, "target" => array, "on_delete" => one of $on_actions, "on_update" => one of $on_actions]
+* @param ForeignKey
* @return string
*/
function format_foreign_key($foreign_key) {
/** Find unique identifier of a row
* @param string[]
-* @param array[] result of indexes()
+* @param Index[] result of indexes()
* @return string[] or null if there is no unique identifier
*/
function unique_array($row, $indexes) {
}
/** Create SQL condition from parsed query string
-* @param array parsed query string
-* @param array[]
+* @param array{where:string[], null:list<string>} parsed query string
+* @param Field[]
* @return string
*/
function where($where, $fields = array()) {
/** Create SQL condition from query string
* @param string
-* @param array[]
+* @param Field[]
* @return string
*/
function where_check($val, $fields = array()) {
/** Get select clause for convertible fields
* @param string[]
-* @param array[]
+* @param Field[]
* @param list<string>
* @return string
*/
/** Get status of a single table and fall back to name on error
* @param string
* @param bool
-* @return array one element from table_status()
+* @return TableStatus one element from table_status()
*/
function table_status1($table, $fast = false) {
$return = table_status($table, $fast);
}
/** Compute fields() from $_POST edit data
-* @return array[] same as fields()
+* @return Field[] same as fields()
*/
function fields_from_edit() {
global $driver;
/** Format value to use in select
* @param string
* @param string
-* @param array
+* @param Field
* @param int
* @return string HTML
*/
}
/** Check if field should be shortened
-* @param array
+* @param Field
* @return bool
*/
function is_shortable($field) {
/** Print enum or set input field
* @param string "radio"|"checkbox"
* @param string
-* @param array
+* @param Field
* @param mixed string|array
* @param string
* @return null
}
/** Print edit input field
-* @param array one field from fields()
+* @param Field one field from fields()
* @param mixed
* @param string
* @param bool
/** Print edit data form
* @param string
-* @param array[]
+* @param Field[]
* @param mixed
* @param bool
* @return null
* @param string
* @param string
* @param string
-* @param array[]
+* @param array{error:list<int>, type:list<string>, name:list<string>}
* @return bool
*/
function send_mail($email, $subject, $message, $from = "", $files = array()) {
}
/** Check whether the column looks like boolean
-* @param array single field returned from fields()
+* @param Field single field returned from fields()
* @return bool
*/
function like_bool($field) {
}
/** Drop types
- * @param array
+ * @param list<string>
* @return bool
*/
function drop_tables($tables) {
protected $servers;
/** Set supported servers
- * @param array[] [$description => ["server" => , "driver" => "server|pgsql|sqlite|..."]]
+ * @param array{server:string, driver:string}[] [$description => ["server" => , "driver" => "server|pgsql|sqlite|..."]]
*/
function __construct($servers) {
$this->servers = $servers;
class AdminerTableIndexesStructure {
/** Print table structure in tabular format
- * @param array[] data about all indexes on a table
+ * @param Index[] data about all indexes on a table
* @return bool
*/
function tableIndexesPrint($indexes) {
class AdminerTableStructure {
/** Print table structure in tabular format
- * @param array[] data about individual fields
+ * @param Field[] data about individual fields
* @return bool
*/
function tableStructurePrint($fields, $tableStatus = null) {