Changes to make GHA happy and added usages of the coalescing operator (#121)

This commit is contained in:
Mark Nelson 2021-10-27 13:09:10 +08:00
parent 62d1bbdedc
commit fae09fbadf
2 changed files with 21 additions and 20 deletions

View file

@ -51,7 +51,7 @@ abstract class element {
* @var string The right alignment constant.
*/
const ALIGN_RIGHT = 'R';
/**
* @var \stdClass $element The data for the element we are adding - do not use, kept for legacy reasons.
*/
@ -150,7 +150,7 @@ abstract class element {
$this->width = $element->width;
$this->refpoint = $element->refpoint;
$this->showposxy = isset($showposxy) && $showposxy;
$this->set_alignment(isset($element->alignment) ? $element->alignment : element::ALIGN_LEFT);
$this->set_alignment($element->alignment ?? self::ALIGN_LEFT);
}
/**
@ -254,24 +254,25 @@ abstract class element {
/**
* Returns the alignment.
*
*
* @return string The current alignment value.
*/
public function get_alignment() {
return isset($this->alignment) ? $this->alignment : element::ALIGN_LEFT;
return $this->alignment ?? self::ALIGN_LEFT;
}
/**
* Sets the alignment.
*
*
* @param string $alignment The new alignment.
*
* @throws InvalidArgumentException if the provided new alignment is not valid.
*
* @throws \InvalidArgumentException if the provided new alignment is not valid.
*/
protected function set_alignment($alignment) {
$valid_values = array(element::ALIGN_LEFT, element::ALIGN_CENTER, element::ALIGN_RIGHT);
if (!in_array($alignment, $valid_values)) {
throw new \InvalidArgumentException("'$alignment' is not a valid alignment value. It has to be one of " . implode(', ', $valid_values));
protected function set_alignment(string $alignment) {
$validvalues = array(self::ALIGN_LEFT, self::ALIGN_CENTER, self::ALIGN_RIGHT);
if (!in_array($alignment, $validvalues)) {
throw new \InvalidArgumentException("'$alignment' is not a valid alignment value. It has to be one of " .
implode(', ', $validvalues));
}
$this->alignment = $alignment;
}
@ -358,16 +359,16 @@ abstract class element {
$element = new \stdClass();
$element->name = $data->name;
$element->data = $this->save_unique_data($data);
$element->font = (isset($data->font)) ? $data->font : null;
$element->fontsize = (isset($data->fontsize)) ? $data->fontsize : null;
$element->colour = (isset($data->colour)) ? $data->colour : null;
$element->font = $data->font ?? null;
$element->fontsize = $data->fontsize ?? null;
$element->colour = $data->colour ?? null;
if ($this->showposxy) {
$element->posx = (isset($data->posx)) ? $data->posx : null;
$element->posy = (isset($data->posy)) ? $data->posy : null;
$element->posx = $data->posx ?? null;
$element->posy = $data->posy ?? null;
}
$element->width = (isset($data->width)) ? $data->width : null;
$element->refpoint = (isset($data->refpoint)) ? $data->refpoint : null;
$element->alignment = (isset($data->alignment)) ? $data->alignment : element::ALIGN_LEFT;
$element->width = $data->width ?? null;
$element->refpoint = $data->refpoint ?? null;
$element->alignment = $data->alignment ?? self::ALIGN_LEFT;
$element->timemodified = time();
// Check if we are updating, or inserting a new element.

View file

@ -216,7 +216,7 @@ class element_helper {
$alignmentoptions[element::ALIGN_LEFT] = get_string('alignleft', 'customcert');
$alignmentoptions[element::ALIGN_CENTER] = get_string('aligncenter', 'customcert');
$alignmentoptions[element::ALIGN_RIGHT] = get_string('alignright', 'customcert');
$mform->addElement('select', 'alignment', get_string('alignment', 'customcert'), $alignmentoptions);
$mform->setType('alignment', PARAM_ALPHA);
$mform->setDefault('alignment', element::ALIGN_LEFT);