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 8464ba6259
commit 9e38411434
2 changed files with 21 additions and 20 deletions

View file

@ -150,7 +150,7 @@ abstract class element {
$this->width = $element->width; $this->width = $element->width;
$this->refpoint = $element->refpoint; $this->refpoint = $element->refpoint;
$this->showposxy = isset($showposxy) && $showposxy; $this->showposxy = isset($showposxy) && $showposxy;
$this->set_alignment(isset($element->alignment) ? $element->alignment : element::ALIGN_LEFT); $this->set_alignment($element->alignment ?? self::ALIGN_LEFT);
} }
/** /**
@ -258,7 +258,7 @@ abstract class element {
* @return string The current alignment value. * @return string The current alignment value.
*/ */
public function get_alignment() { public function get_alignment() {
return isset($this->alignment) ? $this->alignment : element::ALIGN_LEFT; return $this->alignment ?? self::ALIGN_LEFT;
} }
/** /**
@ -266,12 +266,13 @@ abstract class element {
* *
* @param string $alignment The new 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) { protected function set_alignment(string $alignment) {
$valid_values = array(element::ALIGN_LEFT, element::ALIGN_CENTER, element::ALIGN_RIGHT); $validvalues = array(self::ALIGN_LEFT, self::ALIGN_CENTER, self::ALIGN_RIGHT);
if (!in_array($alignment, $valid_values)) { if (!in_array($alignment, $validvalues)) {
throw new \InvalidArgumentException("'$alignment' is not a valid alignment value. It has to be one of " . implode(', ', $valid_values)); throw new \InvalidArgumentException("'$alignment' is not a valid alignment value. It has to be one of " .
implode(', ', $validvalues));
} }
$this->alignment = $alignment; $this->alignment = $alignment;
} }
@ -358,16 +359,16 @@ abstract class element {
$element = new \stdClass(); $element = new \stdClass();
$element->name = $data->name; $element->name = $data->name;
$element->data = $this->save_unique_data($data); $element->data = $this->save_unique_data($data);
$element->font = (isset($data->font)) ? $data->font : null; $element->font = $data->font ?? null;
$element->fontsize = (isset($data->fontsize)) ? $data->fontsize : null; $element->fontsize = $data->fontsize ?? null;
$element->colour = (isset($data->colour)) ? $data->colour : null; $element->colour = $data->colour ?? null;
if ($this->showposxy) { if ($this->showposxy) {
$element->posx = (isset($data->posx)) ? $data->posx : null; $element->posx = $data->posx ?? null;
$element->posy = (isset($data->posy)) ? $data->posy : null; $element->posy = $data->posy ?? null;
} }
$element->width = (isset($data->width)) ? $data->width : null; $element->width = $data->width ?? null;
$element->refpoint = (isset($data->refpoint)) ? $data->refpoint : null; $element->refpoint = $data->refpoint ?? null;
$element->alignment = (isset($data->alignment)) ? $data->alignment : element::ALIGN_LEFT; $element->alignment = $data->alignment ?? self::ALIGN_LEFT;
$element->timemodified = time(); $element->timemodified = time();
// Check if we are updating, or inserting a new element. // Check if we are updating, or inserting a new element.