Skip to content

Commit

Permalink
docs: Fix param, return types
Browse files Browse the repository at this point in the history
  • Loading branch information
zooley committed Aug 9, 2023
1 parent debae40 commit ad8e457
Show file tree
Hide file tree
Showing 53 changed files with 218 additions and 261 deletions.
2 changes: 1 addition & 1 deletion app/Halcyon/Access/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Asset extends Nested
/**
* Generates automatic rules field value
*
* @param object|string $rules
* @param Rules|string $rules
* @return void
*/
public function setRulesAttribute($rules): void
Expand Down
2 changes: 1 addition & 1 deletion app/Halcyon/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected static function deny($message = 'This action is unauthorized.')
* @param int $roleId The path to the role 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 True if authorised.
* @return bool|null True if authorised.
*/
public static function checkRole($roleId, $action, $asset = null)
{
Expand Down
16 changes: 8 additions & 8 deletions app/Halcyon/Access/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public function role(): BelongsTo
/**
* Delete the specified record
*
* @return bool
* @return bool|null
*/
public function delete(): bool
public function delete()
{
return self::query()
->where('role_id', '=', $this->role_id)
Expand All @@ -78,9 +78,9 @@ public function delete(): bool
* Delete objects of this type by Role ID
*
* @param mixed $role_id Integer or array of integers
* @return bool
* @return bool|null
*/
public static function destroyByRole($role_id): bool
public static function destroyByRole($role_id)
{
$role_id = (is_array($role_id) ? $role_id : array($role_id));

Expand All @@ -93,9 +93,9 @@ public static function destroyByRole($role_id): bool
* Delete objects of this type by User ID
*
* @param mixed $user_id Integer or array of integers
* @return bool
* @return bool|null
*/
public static function destroyByUser($user_id): bool
public static function destroyByUser($user_id)
{
$user_id = (is_array($user_id) ? $user_id : array($user_id));

Expand Down Expand Up @@ -160,9 +160,9 @@ public static function addUserToRole($user_id, $role_id): bool
*
* @param mixed $user_id Integer
* @param mixed $role_id Integer or array of integers
* @return bool
* @return bool|null
*/
public static function removeUserFromRole($user_id, $role_id): bool
public static function removeUserFromRole($user_id, $role_id)
{
$role_id = (is_array($role_id) ? $role_id : array($role_id));

Expand Down
5 changes: 4 additions & 1 deletion app/Halcyon/Access/Middleware/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class Authorize
*/
public function handle(Request $request, Closure $next, $ability)
{
Gate::authorize(auth()->id(), $ability);
$id = auth()->id();
$id = $id ?: 0;

Gate::authorize($id, $ability);

return $next($request);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Halcyon/Access/Viewlevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function incrementOrdering(): int
/**
* Saves the current model to the database
*
* @param array $options
* @param array<string,mixed> $options
* @return bool
*/
public function save(array $options = []): bool
Expand Down
2 changes: 1 addition & 1 deletion app/Halcyon/Cas/CasManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public function logoutWithUrl($url)
* Get the attributes for for the currently connected user. This method
* can only be called after authenticate() or an error wil be thrown.
*
* @return mixed
* @return array
*/
public function getAttributes()
{
Expand Down
5 changes: 3 additions & 2 deletions app/Halcyon/Cas/CasServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public function register()
{
$this->app->singleton('cas', function ()
{
$config = config('cas');
$config = config('cas', []);

if (!strstr($config['cas_redirect_path'], 'authenticator='))
if (isset($config['cas_redirect_path'])
&& !strstr($config['cas_redirect_path'], 'authenticator='))
{
$config['cas_redirect_path'] .= strstr($config['cas_redirect_path'], '?') ? '&' : '?';
$config['cas_redirect_path'] .= 'authenticator=cas';
Expand Down
4 changes: 3 additions & 1 deletion app/Halcyon/Cas/Middleware/RedirectCASAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function handle($request, Closure $next)
{
if ($this->cas->checkAuthentication())
{
$route = (string)config('cas.cas_redirect_path');
$config = config('cas.cas_redirect_path', []);

$route = isset($config['cas_redirect_path']) ? (string)$config['cas_redirect_path'] : '';
$route = $route ?: route('callback');

return redirect($route);
Expand Down
12 changes: 3 additions & 9 deletions app/Halcyon/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,7 @@ public function __construct($form = null)
//$parts = Str::splitCamel(get_class($this));
$parts = preg_split('/(?<=[^A-Z_])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][^A-Z_])/x', get_class($this));

if ($parts[0] == 'J')
{
$this->type = ucfirst($parts[count($parts) - 1], '_');
}
else
{
$this->type = ucfirst($parts[0], '_') . ucfirst($parts[count($parts) - 1], '_');
}
$this->type = ucfirst($parts[0]) . ucfirst($parts[count($parts) - 1]);
}
}
}
Expand Down Expand Up @@ -255,6 +248,7 @@ public function __get($name)

return $this->label;
break;

case 'title':
return $this->getTitle();
break;
Expand Down Expand Up @@ -584,7 +578,7 @@ public function getAttribute($name, $default = null)
$attributes = $this->element->attributes();

// Ensure that the attribute exists
if (property_exists($attributes, $name))
if ($attributes && property_exists($attributes, $name))
{
$value = $attributes->$name;

Expand Down
4 changes: 2 additions & 2 deletions app/Halcyon/Form/Fields/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ protected function getInput()
}

// Handle the special case for "now".
if (strtoupper($this->value) == 'NOW')
if (is_string($this->value) && strtoupper($this->value) == 'NOW')
{
$this->value = strftime($format);
$this->value = date($format);
}

if ($this->value)
Expand Down
6 changes: 3 additions & 3 deletions app/Halcyon/Form/Fields/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class Color extends Field
*/
protected function getInput()
{
if (empty($this->value))
$this->value = is_string($this->value) ? '#' . ltrim((string)$this->value, '#') : '';

if (!$this->value)
{
// A color field can't be empty, we default to black. This is the same as the HTML5 spec.
$this->value = '#000000';
}

$this->value = '#' . ltrim((string)$this->value, '#');

// Initialize some field attributes.
$attributes = array(
'type' => 'text',
Expand Down
3 changes: 2 additions & 1 deletion app/Halcyon/Form/Fields/Combo.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected function getInput()
// Initialize variables.
$html = array();
$attr = '';
$value = is_string($this->value) ? $this->value : '';

// Initialize some field attributes.
$attr .= $this->element['class'] ? ' class="form-control combobox ' . (string) $this->element['class'] . '"' : ' class="form-control combobox"';
Expand All @@ -41,7 +42,7 @@ protected function getInput()
$options = $this->getOptions();

// Build the input for the combo box.
$html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '" list="' . $this->id . 'list" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $attr . '/>';
$html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '" list="' . $this->id . 'list" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' . $attr . '/>';

// Build the list for the combo box.
$html[] = '<datalist id="' . $this->id . 'list">';
Expand Down
4 changes: 1 addition & 3 deletions app/Halcyon/Form/Fields/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ class Country extends Select
);

/**
* Method to get the field options.
*
* @return array<int,stdClass> The field option objects.
* @inheritdoc
*/
protected function getOptions()
{
Expand Down
16 changes: 9 additions & 7 deletions app/Halcyon/Form/Fields/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Halcyon\Form\Fields;

//use App\Halcyon\Form\Field;
//use App\Halcyon\Html\Editor as Wysiwyg;
use App\Halcyon\Models\Extension;
use App\Modules\Core\Events\EditorIsRendering;

/**
Expand All @@ -21,7 +21,7 @@ class Editor extends Textarea
/**
* The Editor object.
*
* @var object
* @var Extension|null
*/
protected $editor;

Expand Down Expand Up @@ -80,7 +80,7 @@ protected function getInput()
/**
* Method to get a Editor object based on the form field.
*
* @return object The Editor object.
* @return Extension|null The Editor object.
*/
protected function getEditor()
{
Expand All @@ -105,7 +105,7 @@ protected function getEditor()
foreach ($types as $element)
{
// Build the query.
$editor = $db->table('extensions')
$editor = Extension::query()
->select('element')
->where('element', '=', $element)
->where('folder', '=', 'editors')
Expand All @@ -122,7 +122,7 @@ protected function getEditor()
}

// Create the Editor instance based on the given editor.
$this->editor = $editor; //Wysiwyg::getInstance($editor);
$this->editor = $editor;
}

return $this->editor;
Expand All @@ -131,10 +131,12 @@ protected function getEditor()
/**
* Method to get the Editor output for an onSave event.
*
* @return string The Editor object output.
* @return bool
*/
public function save()
{
return $this->getEditor()->save($this->id);
$editor = $this->getEditor();

return $editor ? $editor->save($this->id) : false;
}
}
4 changes: 4 additions & 0 deletions app/Halcyon/Form/Fields/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ protected function getInput()
$attr = array();
foreach ($attributes as $key => $value)
{
if (!$value)
{
continue;
}
$attr[] = $key . '="' . e($value) . '"';
}
$attr = implode(' ', $attr);
Expand Down
4 changes: 3 additions & 1 deletion app/Halcyon/Form/Fields/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class Number extends Field
*/
protected function getInput()
{
$value = is_numeric($this->value) ? (int)$this->value : 0;

// Initialize some field attributes.
$attributes = array(
'type' => 'number',
'value' => htmlspecialchars((string)$this->value, ENT_COMPAT, 'UTF-8'),
'value' => $value,
'name' => $this->name,
'id' => $this->id,
'min' => (!is_null($this->element['min']) ? (int) $this->element['min'] : null),
Expand Down
8 changes: 7 additions & 1 deletion app/Halcyon/Form/Fields/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ protected function getInput()
$required = ((string) $this->element['required'] == 'true' ? ' required="required"' : '');
$threshold = $this->element['threshold'] ? (int) $this->element['threshold'] : 66;

$value = '';
if ($this->value && is_string($this->value))
{
$value = $this->value;
}

return '<input type="password" name="' . $this->name . '" id="' . $this->id . '"' .
' value="' . htmlspecialchars((string)$this->value, ENT_COMPAT, 'UTF-8') . '"' .
' value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' .
$auto . $class . $readonly . $disabled . $size . $maxLength . $meter . $required . ' autocomplete="off" />';
}
}
2 changes: 1 addition & 1 deletion app/Halcyon/Form/Fields/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function getInput()
$html[] = '</li>';
}

$i = is_null($i) ? 0 : $i;
$i = empty($i) ? 0 : $i;

if ($this->element['option_other'])
{
Expand Down
2 changes: 1 addition & 1 deletion app/Halcyon/Form/Fields/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function getInput()
/**
* Method to get the field options.
*
* @return array<int,\stdClass> The field option objects.
* @return array<int,\stdClass|\Illuminate\Support\Fluent> The field option objects.
*/
protected function getOptions()
{
Expand Down
9 changes: 8 additions & 1 deletion app/Halcyon/Form/Fields/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ class Text extends Field
*/
protected function getInput()
{
$value = $this->value;
$value = is_null($value) ? '' : $value;
if (is_string($value))
{
$value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
}

// Initialize some field attributes.
$attributes = array(
'type' => 'text',
'value' => htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'),
'value' => $value,
'name' => $this->name,
'id' => $this->id,
'size' => ($this->element['size'] ? (int) $this->element['size'] : ''),
Expand Down
10 changes: 5 additions & 5 deletions app/Halcyon/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class Form
/**
* The Repository data store for form fields during display.
*
* @var object
* @var Repository
*/
protected $data;

/**
* The form object errors array.
*
* @var array
* @var array<string,Exception>
*/
protected $errors = array();

Expand All @@ -46,7 +46,7 @@ class Form
/**
* The form object options for use in rendering and validation.
*
* @var array
* @var array<string,mixed>
*/
protected $options = array();

Expand All @@ -60,7 +60,7 @@ class Form
/**
* Form instances.
*
* @var array
* @var array<string,Form>
*/
protected static $forms = array();

Expand Down Expand Up @@ -254,7 +254,7 @@ public function filter($data, $group = null)
/**
* Return all errors, if any.
*
* @return array Array of error messages or Exception objects.
* @return array<string,Exception> Array of error messages or Exception objects.
*/
public function getErrors()
{
Expand Down
Loading

0 comments on commit ad8e457

Please sign in to comment.