Skip to content

Commit

Permalink
Add some typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed May 12, 2024
1 parent 8cd424b commit 43c9a39
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/midgard/admin/asgard/schemadb/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function detect_schema(string $key, $value) : array
/**
* Ensure the configuration is valid (form validation callback)
*/
public function check_config(array $values)
public function check_config(array $values) : array|true
{
$current = $this->config->get_all();
$result = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/calendar/validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(org_openpsa_calendar_event_dba $event, midcom_servic
*
* @return mixed Array with error message or true on success
*/
public function validate(array $input)
public function validate(array $input) : array|true
{
$this->event->busy = $input['busy'];
$this->event->participants = array_flip($input['participants']);
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/products/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class org_openpsa_products_validation
*
* @param array $fields The form's data
*/
public function is_code_available(array $fields)
public function is_code_available(array $fields) : array|true
{
$result = [];
if (!empty($fields['id'])) {
Expand Down
9 changes: 3 additions & 6 deletions lib/org/openpsa/sales/validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
class org_openpsa_sales_validator
{
public function validate_subscription(array $fields)
public function validate_subscription(array $fields) : array|true
{
$result = $this->validate_units($fields);

Expand All @@ -24,13 +24,10 @@ public function validate_subscription(array $fields)
&& empty($fields['continuous'])) {
$result['end'] = midcom::get()->i18n->get_string('select either end date or continuous', 'org.openpsa.sales');
}
if (empty($result)) {
return true;
}
return $result;
return $result ?: true;
}

public function validate_units(array $fields)
public function validate_units(array $fields) : array|true
{
$result = [];
if ( empty($fields['invoiceByActualUnits'])
Expand Down
6 changes: 3 additions & 3 deletions lib/org/openpsa/user/accounthelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,11 @@ public function is_blocked() : bool
return !empty($this->person->get_parameter("org_openpsa_user_blocked_account", "account_password"));
}

public static function get_person_by_formdata(array $data)
public static function get_person_by_formdata(array $data) : ?midcom_db_person
{
if ( empty($data['username'])
|| empty($data['password'])) {
return false;
return null;
}

midcom::get()->auth->request_sudo('org.openpsa.user');
Expand All @@ -444,7 +444,7 @@ public static function get_person_by_formdata(array $data)
midcom::get()->auth->drop_sudo();

if (count($results) != 1) {
return false;
return null;
}
return $results[0];
}
Expand Down
14 changes: 7 additions & 7 deletions lib/org/openpsa/user/validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function get_accounthelper(midcom_db_person $person = null) : org_open
* @param array $fields The form's data
* @return mixed True on success, array of error messages otherwise
*/
public function validate_edit_form(array $fields)
public function validate_edit_form(array $fields) : array|true
{
$result = $this->is_username_available($fields);

Expand All @@ -54,7 +54,7 @@ public function validate_edit_form(array $fields)
* @param array $fields The form's data
* @return mixed True on success, array of error messages otherwise
*/
public function validate_create_form(array $fields)
public function validate_create_form(array $fields) : array|true
{
$result = $this->is_username_available($fields);

Expand All @@ -75,7 +75,7 @@ public function validate_create_form(array $fields)
* @param array $fields The form's data
* @return mixed True on success, array of error messages otherwise
*/
public function verify_existing_password(array $fields)
public function verify_existing_password(array $fields) : array|true
{
if (midcom::get()->auth->can_user_do('org.openpsa.user:manage', class: org_openpsa_user_interface::class)) {
//User has the necessary rights, so we're good
Expand All @@ -99,7 +99,7 @@ public function verify_existing_password(array $fields)
* @param array $fields The form's data
* @return mixed True on success, array of error messages otherwise
*/
public function username_exists(array $fields)
public function username_exists(array $fields) : array|true
{
if ($this->is_username_available(['username' => $fields['username']]) === true) {
return ["username" => $this->l10n->get("unknown username")];
Expand All @@ -113,7 +113,7 @@ public function username_exists(array $fields)
* @param array $fields The form's data
* @return mixed True on success, array of error messages otherwise
*/
public function email_exists(array $fields)
public function email_exists(array $fields) : array|true
{
$result = [];
$qb = new midgard_query_builder(midcom::get()->config->get('person_class'));
Expand All @@ -134,7 +134,7 @@ public function email_exists(array $fields)
* @param array $fields The form's data
* @return mixed True on success, array of error messages otherwise
*/
public function email_and_username_exist(array $fields)
public function email_and_username_exist(array $fields) : array|true
{
$result = [];
$user = midcom::get()->auth->get_user_by_name($fields["username"]);
Expand All @@ -157,7 +157,7 @@ public function email_and_username_exist(array $fields)
* @param array $fields The form's data
* @return mixed True on success, array of error messages otherwise
*/
public function password_check(array $fields)
public function password_check(array $fields) : array|true
{
$result = [];

Expand Down
6 changes: 2 additions & 4 deletions src/midcom/grid/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ class provider
*/
private array $_search = [];

public function __construct($source, string $datatype = 'json')
public function __construct(array|client $source, string $datatype = 'json')
{
$this->_datatype = $datatype;
if ($source instanceof client) {
$this->_client = $source;
} elseif (is_array($source)) {
$this->set_rows($source);
} else {
throw new midcom_error('Unknown source type');
$this->set_rows($source);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/org/openpsa/user/accounthelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ public function testReopen_account()
midcom::get()->auth->drop_sudo();
}

private function _get_person_by_formdata($data, $expected_result)
private function _get_person_by_formdata(array $data, bool $expected_result)
{
$person = org_openpsa_user_accounthelper::get_person_by_formdata($data);
if ($expected_result) {
$this->assertInstanceOf(midcom_db_person::class, $person);
} else {
$this->assertFalse($person);
$this->assertNull($person);
}
$this->reset_server_vars();
}
Expand Down

0 comments on commit 43c9a39

Please sign in to comment.