Skip to content

Commit

Permalink
Types
Browse files Browse the repository at this point in the history
  • Loading branch information
evrifaessa committed May 1, 2023
1 parent 50b6a7d commit 3dbbb9b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Api/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Admin extends \Api_Abstract
*
* @return string[]
*/
public function get_something($data)
public function get_something($data): array
{
$result = [
'apple',
Expand Down
2 changes: 1 addition & 1 deletion Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Client extends \Api_Abstract
*
* Be careful not to expose sensitive data from the Admin API.
*/
public function get_info($data)
public function get_info($data): array
{
// call custom event hook. All active modules will be notified
$this->di['events_manager']->fire(['event' => 'onAfterClientCalledExampleModule', 'params' => ['key' => 'value']]);
Expand Down
8 changes: 3 additions & 5 deletions Api/Guest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,21 @@ class Guest extends \Api_Abstract
*
* @return string
*/
public function readme($data)
public function readme(): string
{
// We'll be using the file_get_contents to fetch the full content of the README file
// Our example admin and client area pages will use this function to fetch the README data
// Then, we'll tell Twig to parse and display the markdown output

$readme = file_get_contents(PATH_MODS . '/Example/README.md');

return $readme;
return file_get_contents(PATH_MODS . '/Example/README.md');
}

/**
* Return a random number between 1 and 100.
*
* @return int
*/
public function random_number()
public function random_number(): int
{
return random_int(1, 100);
}
Expand Down
4 changes: 2 additions & 2 deletions Controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getDi()
*
* @return array
*/
public function fetchNavigation()
public function fetchNavigation(): array
{
return [
'group' => [
Expand Down Expand Up @@ -77,7 +77,7 @@ public function fetchNavigation()
* @example $app->get('/example/test', 'get_test', null, get_class($this)); // calls get_test method on this class
* @example $app->get('/example/:id', 'get_index', array('id'=>'[0-9]+'), get_class($this));
*/
public function register(\Box_App &$app)
public function register(\Box_App &$app): void
{
$app->get('/example', 'get_index', [], static::class);
$app->get('/example/test', 'get_test', [], static::class);
Expand Down
2 changes: 1 addition & 1 deletion Controller/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getDi()
*
* @param \Box_App $app - returned by reference
*/
public function register(\Box_App &$app)
public function register(\Box_App &$app): void
{
$app->get('/example', 'get_index', [], static::class);
$app->get('/example/protected', 'get_protected', [], static::class);
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Example module README file

This module provides a starting point for the developers on creating their FOSSBilling module.
Expand Down
22 changes: 11 additions & 11 deletions Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function setDi(mixed $di)
*
* @throws \Box_Exception
*/
public function install()
public function install(): bool
{
// Execute SQL script if needed
$db = $this->di['db'];
Expand All @@ -56,15 +56,15 @@ public function install()
/**
* Method to uninstall module. In most cases you will use this
* to remove database tables for your module.
*
*
* You also can opt to keep the data in the database if you want
* to keep the data for future use.
*
* @return bool
*
* @throws \Box_Exception
*/
public function uninstall()
public function uninstall(): bool
{
// throw new \Box_Exception("Throw exception to terminate module uninstallation process with a message", array(), 124);
return true;
Expand All @@ -81,7 +81,7 @@ public function uninstall()
*
* @throws \Box_Exception
*/
public function update($manifest)
public function update(array $manifest): bool
{
// throw new \Box_Exception("Throw exception to terminate module update process with a message", array(), 125);
return true;
Expand All @@ -95,12 +95,12 @@ public function update($manifest)
*
* @return array() = list of 2 parameters: array($sql, $params)
*/
public function getSearchQuery($data)
public function getSearchQuery(array $data): array
{
$params = [];
$sql = "SELECT meta_key, meta_value
FROM extension_meta
WHERE extension = 'example' ";
WHERE extension = 'example'";

$client_id = $data['client_id'] ?? null;

Expand All @@ -117,13 +117,13 @@ public function getSearchQuery($data)
/**
* Methods is a delegate for one database row.
*
* @param array $row - array representing one database row
* @param array $row - array representing one database row
* @param string $role - guest|client|admin who is calling this method
* @param bool $deep - true|false deep or light version of result to return to API
* @param bool $deep - true|false deep or light version of result to return to API
*
* @return array
*/
public function toApiArray($row, $role = 'guest', $deep = true)
public function toApiArray(array $row, string $role = 'guest', bool $deep = true): array
{
return $row;
}
Expand All @@ -144,7 +144,7 @@ public function toApiArray($row, $role = 'guest', $deep = true)
*
* @throws \Box_Exception
*/
public static function onEventClientLoginFailed(\Box_Event $event)
public static function onEventClientLoginFailed(\Box_Event $event): void
{
// getting Dependency Injector
$di = $event->getDi();
Expand Down Expand Up @@ -199,7 +199,7 @@ public static function onEventClientLoginFailed(\Box_Event $event)
/**
* This event hook is registered in example module client API call.
*/
public static function onAfterClientCalledExampleModule(\Box_Event $event)
public static function onAfterClientCalledExampleModule(\Box_Event $event): void
{
// error_log('Called event from example module');

Expand Down

0 comments on commit 3dbbb9b

Please sign in to comment.