The route is retrieved from the request, so it makes sense to move the
method to the Http\ServerRequest class.
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Now, it returns last error message or an empty string instead of false
if no errors occurred.
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
* Use str_starts_with()
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Remove redundant !empty()
!empty() on a declared variable is redundant.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Replace loop with array_column()
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Simpify assignment by removing temporary variable
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Remove redundant if statements and array_merge
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Remove temporary variable
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Unindent code
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Add helper method fetchByMode()
This is done to avoid calling methods through variables. It is the same
in terms of performance.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Move if statements to where they are relevant
I had a choice to either move the while loop out of the if statements
or move the if statements inside. I decided it made more sense to move
them inside.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Add NULL to phpdoc for the two parameters that can be null
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Simplify return statement
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Improve performance and simplify code
Since we are always using STORE mode then we can use data_seek() method.
This will allow us to get rid of the loop and use fetchByMode() method.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Inline value defaulting
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Remove redundant check
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* [bugfix] getColumnNames() should return an array of strings
There were multiple issues here. If we are selecting only a certain
column from the SQL then let's use the handy function instead of
array_keys. We will never get anything other than an array so checking
if it is not an array makes no sense. Returning null only to cast it to
an array is pointless. If really necessary, we could still check for an
empty array. The ColumnController returned the value without even
casting it to an array. I am not sure how jQuery/JavaScript dealt with it.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Refactor getColumnMapFromSql and add type hint
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Refactor getVirtualTables
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Remove redundant loop
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Remove redundant usage of freeResult()
If there was no chance for the object to leak the scope and it is the
end of the scope then there's no reason to call this method.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Replace dynamic variable with declare one
It's always the same name. If we were creating more than one, we could
use associative array, but in this case there seems to be absolutely no
need for any of this. Dynamic variables make it harder to debug the code.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Update psalm-baseline.xml
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Widen the condition per williamdes suggestion
This will allow value such as '' and '0' to pass through. Previously
`if(! empty($database))` and `if($database)` dissallowed them.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* fetchResult() should return only arrays
Tests fixed to return arrays. Non-empty in case of true, empty in case
of false.
Fixed a lot of Psalm issues where the condition was always true.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Remove redundant conditions
They were always true. First, the variable is set to -1.
If the variable is -1, then set it to Message.
If the variable is Message then set the JSON array. All of this is
redundant.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* $sqlQuery is not used anywhere
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Enforce $selected to be an array
I can't remove it as it is a global. Previously, it was set to a POST
variable. Since we validate that the variable is set and is not null,
we can use the value from $params. If we validate that it's also an
array we can replace for loop with foreach.
There is no passing by reference, so this change should be safe.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Replace $rebuildDatabaseList with input validation
The validation message says 'No databases selected.' so I assume that
we should check that we actually got at least one entry in the list.
If that is true, then the $rebuildDatabaseList is not needed and the
condition redundant.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* drop_selected_dbs is always set and is redundant
I am not sure if this is necessary. The AJAX request sends a value of "1"
but the code doesn't really do anything with it other than checking if
it is actually set. Is there some other path possible?
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Flatten the array with a single element
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Remove redundant isset
The variable is set, so !isset === is_null. Why check for null if we can
check just for !is_array.
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Update psalm-baseline.xml
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
* Adhere to the coding standard
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
Extracts the getDefault method from the getChoice method and adds a
getName method to the Plugin interface.
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>