Skip to content

Commit

Permalink
Merge pull request #80 from creative-commoners/pulls/5/php81
Browse files Browse the repository at this point in the history
ENH PHP 8.1 compatibility
  • Loading branch information
emteknetnz authored Apr 26, 2022
2 parents 0b03d57 + 3d60d78 commit 156080f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/Fields/KeyValueField.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected function createSelectList($number, $name, $values, $selected = '', $pl
$options .= HTML::createTag('option', $attrs, Convert::raw2xml($title));
}

if (count($values)) {
if (count($values ?? [])) {
$attrs = [
'class' => 'text mventryfield mvdropdown '.($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id().MultiValueTextField::KEY_SEP.$number,
Expand Down Expand Up @@ -189,7 +189,7 @@ public function setValue($v, $data = null)
$newVal = [];

for ($i = 0, $c = count($v['key']); $i < $c; $i++) {
if (strlen($v['key'][$i]) && strlen($v['val'][$i])) {
if (strlen($v['key'][$i] ?? '') && strlen($v['val'][$i] ?? '')) {
$newVal[$v['key'][$i]] = $v['val'][$i];
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/Fields/MultiValueCheckboxField.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function Field($properties = [])

if ($this->storeKeys && is_array($values)) {
// use the keys instead, as that's how we've stored things
$values = array_keys($values);
$values = array_keys($values ?? []);
}
}

Expand Down Expand Up @@ -77,17 +77,17 @@ public function Field($properties = [])
}
}
} elseif ($values && is_string($values)) {
$items = explode(',', $values);
$items = str_replace('{comma}', ',', $items);
$items = explode(',', $values ?? '');
$items = str_replace('{comma}', ',', $items ?? '');
}
}
} else {
// Sometimes we pass a singluar default value thats ! an array && !DataObjectSet
if (is_a($values, 'DataObjectSet') || is_array($values)) {
$items = $values;
} else {
$items = explode(',', $values);
$items = str_replace('{comma}', ',', $items);
$items = explode(',', $values ?? '');
$items = str_replace('{comma}', ',', $items ?? '');
}
}

Expand Down Expand Up @@ -117,15 +117,15 @@ public function Field($properties = [])

$odd = ($odd + 1) % 2;
$extraClass = $odd ? 'odd' : 'even';
$extraClass .= ' val'.str_replace(' ', '', $key);
$itemID = $this->id().'_'.preg_replace('/[^a-zA-Z0-9]+/', '', $key);
$extraClass .= ' val'.str_replace(' ', '', $key ?? '');
$itemID = $this->id().'_'.preg_replace('/[^a-zA-Z0-9]+/', '', $key ?? '');
$checked = '';
if (isset($items)) {
$checked = (in_array($key, $items) || in_array($key, $this->defaultItems))
$checked = (in_array($key, $items ?? []) || in_array($key, $this->defaultItems ?? []))
? ' checked="checked"' : '';
}

$disabled = ($this->disabled || in_array($key, $this->disabledItems))
$disabled = ($this->disabled || in_array($key, $this->disabledItems ?? []))
? $disabled = ' disabled="disabled"'
: '';
$options .= "<li class=\"$extraClass\"><input id=\"$itemID\" name=\"$this->name[$key]\""
Expand Down Expand Up @@ -220,7 +220,7 @@ public function dataValue()
$filtered = [];
foreach ($this->value as $item) {
if ($item) {
$filtered[] = str_replace(",", "{comma}", $item);
$filtered[] = str_replace(",", "{comma}", $item ?? '');
}
}

Expand Down Expand Up @@ -271,7 +271,7 @@ public function performReadonlyTransformation()
// Items is an array or single piece of string (including comma seperated string)
} else {
if (!is_array($items)) {
$items = preg_split('/ *, */', trim($items));
$items = preg_split('/ *, */', trim($items ?? ''));
}

foreach ($items as $item) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/MultiValueListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function Field($properties = [])

foreach ($this->source as $index => $title) {
$attrs = ['value' => $index];
if (in_array($index, $this->value)) {
if (in_array($index, $this->value ?? [])) {
$attrs['selected'] = 'selected';
}
$options .= HTML::createTag('option', $attrs, Convert::raw2xml($title));
Expand Down
6 changes: 3 additions & 3 deletions src/Fields/MultiValueTextField.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public function Field($properties = [])
// add an empty row
if (!$this->readonly) {
// assume next pos equals to the number of existing fields which gives index+1 in a zero-indexed list
$attributes['id'] = $this->id().MultiValueTextField::KEY_SEP.count($fields);
$attributes['id'] = $this->id().MultiValueTextField::KEY_SEP.count($fields ?? []);
$fields[] = $this->createInput($attributes);
}

if (count($fields)) {
if (count($fields ?? [])) {
return '<ul id="'.$this->id().'" class="multivaluefieldlist '.$this->extraClass().'"><li>'.implode(
'</li><li>',
$fields
Expand Down Expand Up @@ -99,7 +99,7 @@ public function setValue($v, $data = null)
if (is_array($v)) {
// we've been set directly via the post - lets prune any empty values
foreach ($v as $key => $val) {
if (!strlen($val)) {
if (!strlen($val ?? '')) {
unset($v[$key]);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/ORM/FieldType/MultiValueField.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ protected function unserializeData($data)
{
$value = null;
// if we're not deserialised yet, do so
if (is_string($data) && strlen($data) > 1) {
if (is_string($data) && strlen($data ?? '') > 1) {
// are we json encoded?
if ($data[1] === ':') {
$value = \unserialize($data);
$value = \unserialize($data ?? '');
} else {
$value = \json_decode($data, true);
$value = \json_decode($data ?? '', true);
}
}
return $value;
Expand Down Expand Up @@ -155,7 +155,7 @@ public function csv()
*/
public function Implode($separator = ', ')
{
return implode($separator, $this->getValue());
return implode($separator ?? '', $this->getValue());
}

public function __toString()
Expand All @@ -170,7 +170,7 @@ public function __toString()
public function ItemByKey()
{
$values = $this->getValue();
if (array_keys($values) == range(0, count($values) - 1)) {
if (array_keys($values ?? []) == range(0, count($values ?? []) - 1)) {
$values = [];
}
return new ArrayData($values);
Expand Down

0 comments on commit 156080f

Please sign in to comment.