]> git.joonet.de Git - adminer.git/commitdiff
Doc-comment: Use type aliases for arrays
authorJakub Vrana <jakub@vrana.cz>
Wed, 26 Mar 2025 01:23:29 +0000 (02:23 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 26 Mar 2025 01:43:08 +0000 (02:43 +0100)
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.

12 files changed:
adminer/drivers/mysql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/adminer.inc.php
adminer/include/driver.inc.php
adminer/include/editing.inc.php
adminer/include/functions.inc.php
adminer/include/html.inc.php
editor/include/editing.inc.php
plugins/drivers/elastic.php
plugins/login-servers.php
plugins/table-indexes-structure.php
plugins/table-structure.php

index 58c544d852afc7723fe2eaa9e091f32c594e2ba6..7f72044f2ab452ee89f37d882f85faffe6b800a9 100644 (file)
@@ -443,7 +443,7 @@ if (!defined('Adminer\DRIVER')) {
        }
 
        /** 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) {
@@ -549,7 +549,8 @@ if (!defined('Adminer\DRIVER')) {
        /** 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();
@@ -577,7 +578,7 @@ if (!defined('Adminer\DRIVER')) {
        }
 
        /** Find out whether the identifier is view
-       * @param array
+       * @param TableStatus
        * @return bool
        */
        function is_view($table_status) {
@@ -585,7 +586,7 @@ if (!defined('Adminer\DRIVER')) {
        }
 
        /** 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) {
@@ -595,7 +596,8 @@ if (!defined('Adminer\DRIVER')) {
 
        /** 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;
@@ -651,7 +653,8 @@ if (!defined('Adminer\DRIVER')) {
        /** 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();
@@ -667,7 +670,8 @@ if (!defined('Adminer\DRIVER')) {
 
        /** 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;
@@ -807,7 +811,7 @@ if (!defined('Adminer\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
@@ -852,7 +856,7 @@ if (!defined('Adminer\DRIVER')) {
 
        /** 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) {
@@ -958,7 +962,8 @@ if (!defined('Adminer\DRIVER')) {
 
        /** 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 == "") {
@@ -970,7 +975,7 @@ if (!defined('Adminer\DRIVER')) {
 
        /** Get defined triggers
        * @param string
-       * @return array{string, string}[]4
+       * @return array{string, string}[]
        */
        function triggers($table) {
                $return = array();
@@ -994,7 +999,8 @@ if (!defined('Adminer\DRIVER')) {
        /** 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;
@@ -1046,7 +1052,7 @@ if (!defined('Adminer\DRIVER')) {
 
        /** Get routine signature
        * @param string
-       * @param array result of routine()
+       * @param Routine result of routine()
        * @return string
        */
        function routine_id($name, $row) {
@@ -1071,7 +1077,7 @@ if (!defined('Adminer\DRIVER')) {
        }
 
        /** Get approximate number of rows
-       * @param array
+       * @param TableStatus
        * @param list<string>
        * @return int or null if approximate number can't be retrieved
        */
@@ -1178,7 +1184,7 @@ if (!defined('Adminer\DRIVER')) {
        }
 
        /** Convert field in select and edit
-       * @param array one element from fields()
+       * @param Field one element from fields()
        * @return string
        */
        function convert_field($field) {
@@ -1194,7 +1200,7 @@ if (!defined('Adminer\DRIVER')) {
        }
 
        /** 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
        */
index 756644ac3df9a5d96d16ab8eb81c6ed4bc88c1bc..98df1641c557bbd4842318b1c877344a69052601 100644 (file)
@@ -471,7 +471,7 @@ if (isset($_GET["sqlite"])) {
        * @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
index b3745f629359021e3fc50cc8505df1c3826b3e99..d79a50025d382384db2d47be73f7547d19071bb7 100644 (file)
@@ -159,7 +159,7 @@ class Adminer {
        }
 
        /** 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) {
@@ -167,7 +167,7 @@ class Adminer {
        }
 
        /** 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
        */
@@ -178,7 +178,7 @@ class Adminer {
        }
 
        /** 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
        */
@@ -211,7 +211,7 @@ class Adminer {
 
        /** 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);
@@ -220,14 +220,15 @@ class Adminer {
        /** 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
        */
@@ -278,7 +279,7 @@ class Adminer {
 
        /** Get descriptions of selected data
        * @param list<string[]> all data to print
-       * @param array[]
+       * @param ForeignKey[]
        * @return list<string[]>
        */
        function rowDescriptions($rows, $foreignKeys) {
@@ -287,7 +288,7 @@ class Adminer {
 
        /** 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) {
@@ -296,7 +297,7 @@ class Adminer {
        /** 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
        */
@@ -314,7 +315,7 @@ class Adminer {
 
        /** 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) {
@@ -322,8 +323,8 @@ class Adminer {
        }
 
        /** 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) {
@@ -354,7 +355,7 @@ class Adminer {
        }
 
        /** 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) {
@@ -403,7 +404,7 @@ class Adminer {
        /** 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) {
@@ -439,7 +440,7 @@ class Adminer {
        /** 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) {
@@ -481,7 +482,7 @@ class Adminer {
        }
 
        /** Print action box in select
-       * @param array[]
+       * @param Index[]
        * @return null
        */
        function selectActionPrint($indexes) {
@@ -531,7 +532,7 @@ class Adminer {
 
        /** 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) {
@@ -550,8 +551,8 @@ class Adminer {
        }
 
        /** 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) {
@@ -604,8 +605,8 @@ class Adminer {
        }
 
        /** 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) {
@@ -636,7 +637,7 @@ class Adminer {
 
        /** 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) {
@@ -698,7 +699,7 @@ class Adminer {
        }
 
        /** Functions displayed in edit form
-       * @param array single field from fields()
+       * @param Field single field from fields()
        * @return list<string>
        */
        function editFunctions($field) {
@@ -725,7 +726,7 @@ class Adminer {
 
        /** 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
@@ -742,7 +743,7 @@ class Adminer {
 
        /** 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
        */
@@ -751,7 +752,7 @@ class Adminer {
        }
 
        /** 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
@@ -1051,7 +1052,7 @@ class Adminer {
        }
 
        /** 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;
@@ -1116,7 +1117,7 @@ class Adminer {
        }
 
        /** Print table list in menu
-       * @param array result of table_status('', true)
+       * @param TableStatus[] result of table_status('', true)
        * @return null
        */
        function tablesPrint($tables) {
index 92aa2b9d662b08ffac3de345bfe8a791be78ea2b..1ea97a6a677d4ce13613cbcb12b4b1bc06f9d30e 100644 (file)
@@ -60,14 +60,14 @@ abstract class SqlDriver {
        }
 
        /** 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) {
@@ -194,8 +194,8 @@ abstract class SqlDriver {
 
        /** 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) {
@@ -212,7 +212,7 @@ abstract class SqlDriver {
 
        /** Convert value returned by database to actual value
        * @param string
-       * @param array
+       * @param Field
        * @return string
        */
        function value($val, $field) {
@@ -260,7 +260,7 @@ abstract class SqlDriver {
        }
 
        /** Check whether table supports indexes
-       * @param array result of table_status1()
+       * @param TableStatus result of table_status1()
        * @return bool
        */
        function supportsIndex($table_status) {
index e84b355d941f0b3a78639f4eede6d987ed7290d5..9e067d879e8abce885b8fb816de5168da4d7d62f 100644 (file)
@@ -102,7 +102,7 @@ function select($result, $connection2 = null, $orgtables = array(), $limit = 0)
 
 /** 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
@@ -178,9 +178,9 @@ function json_row($key, $val = null) {
 
 /** 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
 */
@@ -246,7 +246,7 @@ function process_length($length) {
 }
 
 /** Create SQL string from field type
-* @param array
+* @param Field
 * @param string
 * @return string
 */
@@ -260,8 +260,8 @@ function process_type($field, $collate = "COLLATE") {
 }
 
 /** 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) {
@@ -281,7 +281,7 @@ function process_field($field, $type_field) {
 }
 
 /** Get default value clause
-* @param array
+* @param Field
 * @return string
 */
 function default_value($field) {
@@ -317,10 +317,10 @@ function type_class($type) {
 }
 
 /** 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()) {
@@ -382,7 +382,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = arra
 }
 
 /** Move fields up and down or add field
-* @param array[]
+* @param Field[]
 * @return bool
 */
 function process_fields(&$fields) {
@@ -487,7 +487,7 @@ function drop_create($drop, $create, $drop_created, $test, $drop_test, $location
 
 /** 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) {
@@ -534,7 +534,7 @@ function remove_definer($query) {
 }
 
 /** 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) {
index 0428d4f6125f7c3dd8d97828c9b5fb947c5edc15..adec2ef9e0b0c941e599566838e79d652af04866 100644 (file)
@@ -262,7 +262,7 @@ function get_rows($query, $connection2 = null, $error = "<p class='error'>") {
 
 /** 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) {
@@ -292,8 +292,8 @@ function escape_key($key) {
 }
 
 /** 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()) {
@@ -321,7 +321,7 @@ 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()) {
@@ -343,7 +343,7 @@ function where_link($i, $column, $value, $operator = "=") {
 
 /** Get select clause for convertible fields
 * @param string[]
-* @param array[]
+* @param Field[]
 * @param list<string>
 * @return string
 */
@@ -701,7 +701,7 @@ function friendly_url($val) {
 /** 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);
@@ -724,7 +724,7 @@ function column_foreign_keys($table) {
 }
 
 /** Compute fields() from $_POST edit data
-* @return array[] same as fields()
+* @return Field[] same as fields()
 */
 function fields_from_edit() {
        global $driver;
@@ -892,7 +892,7 @@ function rand_string() {
 /** Format value to use in select
 * @param string
 * @param string
-* @param array
+* @param Field
 * @param int
 * @return string HTML
 */
@@ -953,7 +953,7 @@ function is_url($string) {
 }
 
 /** Check if field should be shortened
-* @param array
+* @param Field
 * @return bool
 */
 function is_shortable($field) {
index 33f5b6e10fca96a580d242155a95f9f9145bd039..97cf771b6871c4e8fcd1403cdb570bb598b99341 100644 (file)
@@ -229,7 +229,7 @@ function hidden_fields_get() {
 /** Print enum or set input field
 * @param string "radio"|"checkbox"
 * @param string
-* @param array
+* @param Field
 * @param mixed string|array
 * @param string
 * @return null
@@ -247,7 +247,7 @@ function enum_input($type, $attrs, $field, $value, $empty = null) {
 }
 
 /** Print edit input field
-* @param array one field from fields()
+* @param Field one field from fields()
 * @param mixed
 * @param string
 * @param bool
@@ -426,7 +426,7 @@ function on_help($command, $side = 0) {
 
 /** Print edit data form
 * @param string
-* @param array[]
+* @param Field[]
 * @param mixed
 * @param bool
 * @return null
index 540c2e704bbda284a6feac369c147e0030aa0f1a..529a0be697cf805086cfffcfbc737afa54815434 100644 (file)
@@ -15,7 +15,7 @@ function email_header($header) {
 * @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()) {
@@ -47,7 +47,7 @@ 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) {
index 4899d87977c652187897f40548ebbeccd6546202..4b9f1cc133a8249b43531592fd191d3936667e7c 100644 (file)
@@ -555,7 +555,7 @@ if (isset($_GET["elastic"])) {
        }
 
        /** Drop types
-        * @param array
+        * @param list<string>
         * @return bool
         */
        function drop_tables($tables) {
index a692be5c53cb27c18a690dbc60bb347fecc337bc..558e78b3d78723a96838b42ab8778f2647e61f9d 100644 (file)
@@ -10,7 +10,7 @@ class AdminerLoginServers {
        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;
index 85d9fa8c1fa540c1a98e50d37296ff107b8d5976..b6a1c0f7ad3edc35a729778900c99d6a5efd6688 100644 (file)
@@ -9,7 +9,7 @@
 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) {
index a07445e36325e19755273a2148dc8bb319ed2f3f..24359deb49fa0ce49d02a054309a19945c933726 100644 (file)
@@ -9,7 +9,7 @@
 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) {