Skip to content

Commit

Permalink
docs: Correct return/param types, remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
zooley committed Aug 14, 2023
1 parent cf524fe commit fbd768f
Show file tree
Hide file tree
Showing 34 changed files with 171 additions and 407 deletions.
20 changes: 13 additions & 7 deletions app/Halcyon/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ class Gate
/**
* Array of user roles.
*
* @var array
* @var array<int,Role>
*/
protected static $userRoles = array();

/**
* Array of user role paths.
*
* @var array
* @var array<int,array>
*/
protected static $userRolePaths = array();

/**
* Array of cached roles by user.
*
* @var array
* @var array<int,array>
*/
protected static $rolesByUser = array();

Expand Down Expand Up @@ -119,7 +119,7 @@ public static function check($userId, $action, $asset = null)
* @param int $userId Id of the user for which to check authorisation.
* @param string $action The name of the action to authorise.
* @param mixed $asset Asset ID or the name of the asset as a string. Defaults to the global asset node.
* @return bool
* @return Response
*/
public static function authorize($userId, $action, $asset = null)
{
Expand Down Expand Up @@ -161,14 +161,19 @@ public static function authorize($userId, $action, $asset = null)
}
}

return $result ? self::allow() : self::deny();
if (!$result)
{
self::deny();
}

return self::allow();
}

/**
* Create a new access response.
*
* @param string $message
* @return \Illuminate\Auth\Access\Response
* @return Response
*/
protected static function allow($message = '')
{
Expand Down Expand Up @@ -356,7 +361,8 @@ public static function getAssetRules($asset, $recursive = false): Rules
$query->groupBy('a.lft');
}

$result = $query->get()->pluck('rules')->toArray();
//$result = $query->get()->pluck('rules')->toArray();
$result = [$query->value('rules')];

// Get the root even if the asset is not found and in recursive mode
if (empty($result) && $recursive)
Expand Down
4 changes: 2 additions & 2 deletions app/Halcyon/Access/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Role extends Model
/**
* The table to which the class pertains
*
* @var string
* @var bool
*/
public $timestamps = false;

Expand Down Expand Up @@ -129,7 +129,7 @@ public static function findByTitle($title)
/**
* Perform any actions that are necessary after the model is saved.
*
* @param array $options
* @param array<string,mixed> $options
* @return void
*/
protected function finishSave(array $options): void
Expand Down
6 changes: 3 additions & 3 deletions app/Halcyon/Access/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct($input = '')
/**
* Get the data for the action.
*
* @return array A named array of Rule objects.
* @return array<string,Rule> A named array of Rule objects.
*/
public function getData(): array
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public function merge($actions): void
* Merges an array of identities for an action.
*
* @param string $action The name of the action.
* @param array $identities An array of identities
* @param array<int,int> $identities An array of identities
* @return void
*/
public function mergeAction($action, $identities): void
Expand Down Expand Up @@ -205,7 +205,7 @@ public function toJson($options = 0): string
/**
* Get the instance as an array.
*
* @return array
* @return array<string,array>
*/
public function toArray(): array
{
Expand Down
2 changes: 1 addition & 1 deletion app/Halcyon/Cas/CasServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function register()
/**
* Get the services provided by the provider.
*
* @return array
* @return array<int,string>
*/
public function provides()
{
Expand Down
2 changes: 1 addition & 1 deletion app/Halcyon/Form/Fields/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Country extends Select
/**
* List of countries
*
* @var array<int,array>
* @var array<int,array{string,string}>
*/
public static $countries = array(
array('code' => 'AF', 'name' => 'Afghanistan', 'continent' => 'Asia'),
Expand Down
12 changes: 0 additions & 12 deletions app/Halcyon/Form/Fields/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,4 @@ protected function getEditor()

return $this->editor;
}

/**
* Method to get the Editor output for an onSave event.
*
* @return bool
*/
public function save()
{
$editor = $this->getEditor();

return $editor ? $editor->save($this->id) : false;
}
}
2 changes: 1 addition & 1 deletion app/Halcyon/Form/Fields/Groupedlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Groupedlist extends Field
/**
* Method to get the field option groups.
*
* @return array<string,array> The field option objects as a nested array in groups.
* @return array<string,array{int,\stdClass}> The field option objects as a nested array in groups.
*/
protected function getGroups()
{
Expand Down
2 changes: 1 addition & 1 deletion app/Halcyon/Form/Fields/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function getOptions()
// Build the options array.
for ($i = $first; $i <= $last; $i += $step)
{
$options[] = Dropdown::option($i);
$options[] = Dropdown::option("$i");
}

// Merge any additional options in the XML definition.
Expand Down
3 changes: 2 additions & 1 deletion app/Halcyon/Form/Fields/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected function getInput()
// Get the field options.
$options = $this->getOptions();
$found = false;
$onclick = '';

$html[] = '<ul>';

Expand All @@ -54,7 +55,7 @@ protected function getInput()

// Add data attributes
$dataAttributes = '';
foreach ($option as $field => $value)
foreach (get_object_vars($option) as $field => $value)
{
$dataField = strtolower(substr($field, 0, 4));
if ($dataField == 'data')
Expand Down
2 changes: 1 addition & 1 deletion app/Halcyon/Form/Fields/Timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Timezone extends Groupedlist
/**
* Method to get the time zone field option groups.
*
* @return array<string,array> The field option objects as a nested array in groups.
* @return array<string,array{string,\stdClass}> The field option objects as a nested array in groups.
*/
protected function getGroups()
{
Expand Down
4 changes: 2 additions & 2 deletions app/Halcyon/Form/Rules/Equals.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public function test(&$element, $value, $group = null, &$input = null, &$form =
// Check that a validation field is set.
if (!$field)
{
return new Exception('core::core.error.invalid form rule' . get_class($this));
throw new Exception('core::core.error.invalid form rule' . get_class($this));
}

// Check that a valid Form object is given for retrieving the validation field value.
if (!($form instanceof Form))
{
return new Exception('core::core.error.invalid form object' . get_class($this));
throw new Exception('core::core.error.invalid form object' . get_class($this));
}

// Test the two values against each other.
Expand Down
2 changes: 1 addition & 1 deletion app/Halcyon/Form/Rules/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function test(&$element, $value, $group = null, &$input = null, &$form =
{
return false;
}
if (array_key_exists('port', $urlParts) && !is_int((int) $urlParts['port']))
if (array_key_exists('port', $urlParts) && !is_int($urlParts['port']))
{
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions app/Halcyon/Html/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class Builder
/**
* An array to hold included paths
*
* @var array
* @var array<int,string>
*/
protected static $paths = array();

/**
* An array to hold method references
*
* @var array
* @var array<int,array{int,string}>
*/
protected static $registry = array();

Expand All @@ -30,7 +30,7 @@ class Builder
* Additional include paths are also able to be specified for third-party use
*
* @param string $method
* @param array $parameters
* @param array<int,string> $parameters
* @return mixed
*/
public function __call($method, $parameters)
Expand Down Expand Up @@ -71,7 +71,7 @@ public function __call($method, $parameters)
* Registers a function to be called with a specific key
*
* @param string $key The name of the key
* @param array $callable Function or method
* @param array<int,string> $callable Function or method
* @return bool True if the function is callable
*/
public function register($key, $callable)
Expand Down Expand Up @@ -156,7 +156,7 @@ protected function find($cls)
* either pass a string or an array of directories.
*
* @param string $path A path to search.
* @return array An array with directory elements
* @return array<int,string> An array with directory elements
*/
public function addIncludePath($path = '')
{
Expand Down
44 changes: 25 additions & 19 deletions app/Halcyon/Html/Builder/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Halcyon\Access\Role;
use App\Halcyon\Access\Viewlevel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Collection;
use stdClass;

/**
* Extended Utility class for all HTML drawing classes.
Expand All @@ -16,7 +18,7 @@ class Access
/**
* A cached array of the asset groups
*
* @var array
* @var Collection
*/
protected static $asset_groups = null;

Expand All @@ -26,7 +28,7 @@ class Access
* @param string $name The form field name.
* @param string $selected The name of the selected section.
* @param string $attribs Additional attributes to add to the select field.
* @param mixed $params True to add "All Sections" option or and array of options
* @param mixed $params True to add "All Sections" option or an array of options
* @param string $id The form field id
* @return string The required HTML for the SELECT tag.
*/
Expand Down Expand Up @@ -69,18 +71,26 @@ public static function level($name, $selected, $attribs = '', $params = true, $i
* Displays a list of the available user groups.
*
* @param string $name The form field name.
* @param string|array $selected The name of the selected section.
* @param string|array<int,mixed> $selected The name of the selected section.
* @param string $attribs Additional attributes to add to the select field.
* @param bool $allowAll True to add "All Groups" option.
* @param string $idtag
* @return string The required HTML for the SELECT tag.
*/
public static function usergroup($name, $selected, $attribs = '', $allowAll = true, $idtag = false)
{
$options = array();

// If all usergroups is allowed, push it into the array.
if ($allowAll)
{
$options[] = Select::option('', trans('access.show all groups'));
}

$ug = new Role;

$options = Role::query()
->select(['a.id AS value', 'a.title AS text', DB::raw('COUNT(DISTINCT b.id) AS level')])
$roles = Role::query()
->select(['a.id', 'a.title', DB::raw('COUNT(DISTINCT b.id) AS level')])
->from($ug->getTable() . ' AS a')
->leftJoin($ug->getTable() . ' AS b', function($join)
{
Expand All @@ -91,16 +101,13 @@ public static function usergroup($name, $selected, $attribs = '', $allowAll = tr
->orderBy('a.lft', 'asc')
->get();

$options->transform(function ($item, $key)
foreach ($roles as $role)
{
$item->text = str_repeat('- ', $item->level) . $item->text;
return $item;
});
$opt = new stdClass;
$opt->value = $role->id;
$opt->text = str_repeat('- ', $role->level) . $role->title;

// If all usergroups is allowed, push it into the array.
if ($allowAll)
{
$options->prepend(Select::option('', trans('access.show all groups')));
$options[] = $opt;
}

return Select::genericlist($options, $name, array(
Expand All @@ -114,7 +121,7 @@ public static function usergroup($name, $selected, $attribs = '', $allowAll = tr
* Returns a UL list of user groups with check boxes
*
* @param string $name The name of the checkbox controls array
* @param array $selected An array of the checked boxes
* @param array<int,mixed> $selected An array of the checked boxes
* @param bool $checkSuperAdmin If false only super admins can add to super admin groups
* @return string
*/
Expand Down Expand Up @@ -179,7 +186,7 @@ public static function roles($name, $selected, $checkSuperAdmin = false)
* Returns a UL list of actions with check boxes
*
* @param string $name The name of the checkbox controls array
* @param array $selected An array of the checked boxes
* @param array<int,mixed> $selected An array of the checked boxes
* @param string $component The component the permissions apply to
* @param string $section The section (within a component) the permissions apply to
* @return string
Expand Down Expand Up @@ -227,10 +234,9 @@ public static function actions($name, $selected, $component, $section = 'global'
/**
* Gets a list of the asset groups as an array of options.
*
* @param array $config An array of options for the options
* @return mixed An array or false if an error occurs
* @return Collection An array or false if an error occurs
*/
public static function assetgroups($config = array())
public static function assetgroups()
{
if (empty(self::$asset_groups))
{
Expand All @@ -250,7 +256,7 @@ public static function assetgroups($config = array())
* @param string $name The name of the select element
* @param mixed $selected The selected asset group id
* @param string $attribs Optional attributes for the select field
* @param array $config An array of options for the control
* @param array<string,string> $config An array of options for the control
* @return mixed An HTML string or null if an error occurs
*/
public static function assetgrouplist($name, $selected, $attribs = null, $config = array())
Expand Down
2 changes: 1 addition & 1 deletion app/Halcyon/Html/Builder/Contentlanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Contentlanguage
*
* @param bool $all True to include All (*)
* @param bool $translate True to translate All
* @return string
* @return array<int,object>
*/
public static function existing($all = false, $translate = false)
{
Expand Down
Loading

0 comments on commit fbd768f

Please sign in to comment.