More PHP 8.1 fixes to be compatible

This commit is contained in:
Igor Scheller 2021-12-01 00:27:46 +01:00 committed by msquare
parent 643c4c8da7
commit 8d436d988a
16 changed files with 34 additions and 25 deletions

View File

@ -93,7 +93,7 @@ class CreateUsersTables extends Migration
'password' => $data->Passwort, 'password' => $data->Passwort,
'email' => $data->email, 'email' => $data->email,
'api_key' => $data->api_key, 'api_key' => $data->api_key,
'last_login_at' => Carbon::createFromTimestamp($data->lastLogIn), 'last_login_at' => $data->lastLogIn ? Carbon::createFromTimestamp($data->lastLogIn) : null,
]); ]);
$user->setAttribute('id', $data->UID); $user->setAttribute('id', $data->UID);
if (!in_array($data->CreateDate, $emptyDates)) { if (!in_array($data->CreateDate, $emptyDates)) {

View File

@ -28,7 +28,7 @@ COPY --from=composer /app/composer.lock /app/
RUN find /app/storage/ -type f -not -name VERSION -exec rm {} \; RUN find /app/storage/ -type f -not -name VERSION -exec rm {} \;
# Build the PHP container # Build the PHP container
FROM php:8.0-fpm-alpine FROM php:8-fpm-alpine
WORKDIR /var/www WORKDIR /var/www
RUN apk add --no-cache icu-dev && \ RUN apk add --no-cache icu-dev && \
docker-php-ext-install intl pdo_mysql docker-php-ext-install intl pdo_mysql

View File

@ -1,5 +1,5 @@
# Engelsystem PHP FPM development image including Xdebug # Engelsystem PHP FPM development image including Xdebug
FROM php:8.0-fpm-alpine AS es_php_fpm FROM php:8-fpm-alpine AS es_php_fpm
WORKDIR /var/www WORKDIR /var/www
RUN apk add --no-cache icu-dev $PHPIZE_DEPS && \ RUN apk add --no-cache icu-dev $PHPIZE_DEPS && \
pecl install pcov xdebug && \ pecl install pcov xdebug && \

View File

@ -11,7 +11,7 @@ use Carbon\Carbon;
*/ */
function form_hidden($name, $value) function form_hidden($name, $value)
{ {
return '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />'; return '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars((string)$value) . '" />';
} }
/** /**
@ -24,7 +24,7 @@ function form_hidden($name, $value)
*/ */
function form_spinner($name, $label, $value) function form_spinner($name, $label, $value)
{ {
$value = htmlspecialchars($value); $value = htmlspecialchars((string)$value);
return form_element($label, ' return form_element($label, '
<div class="input-group"> <div class="input-group">
@ -69,7 +69,7 @@ function form_date($name, $label, $value, $start_date = '', $end_date = '')
return form_element($label, ' return form_element($label, '
<div class="input-group date" id="' . $dom_id . '" data-min-date="' . $start_date . '" data-max-date="' . $end_date . '" data-target-input="nearest"> <div class="input-group date" id="' . $dom_id . '" data-min-date="' . $start_date . '" data-max-date="' . $end_date . '" data-target-input="nearest">
<input type="date" placeholder="YYYY-MM-DD" name="' . $name . '" class="form-control" value="' . htmlspecialchars($value) . '" autocomplete="off">' <input type="date" placeholder="YYYY-MM-DD" name="' . $name . '" class="form-control" value="' . htmlspecialchars((string)$value) . '" autocomplete="off">'
. '<span class="input-group-text">' . icon('grid-3x3-gap-fill') . '</span> . '<span class="input-group-text">' . icon('grid-3x3-gap-fill') . '</span>
</div> </div>
', $dom_id); ', $dom_id);
@ -178,7 +178,7 @@ function form_checkbox($name, $label, $selected, $value = 'checked', $html_id =
} }
return '<div class="checkbox"><label>' return '<div class="checkbox"><label>'
. '<input type="checkbox" id="' . $html_id . '" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . '<input type="checkbox" id="' . $html_id . '" name="' . $name . '" value="' . htmlspecialchars((string)$value) . '" '
. ($selected ? ' checked="checked"' : '') . ' /> ' . ($selected ? ' checked="checked"' : '') . ' /> '
. $label . $label
. '</label></div>'; . '</label></div>';
@ -196,7 +196,7 @@ function form_checkbox($name, $label, $selected, $value = 'checked', $html_id =
function form_radio($name, $label, $selected, $value) function form_radio($name, $label, $selected, $value)
{ {
return '<div class="radio">' return '<div class="radio">'
. '<label><input type="radio" id="' . $name . '" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . '<label><input type="radio" id="' . $name . '" name="' . $name . '" value="' . htmlspecialchars((string)$value) . '" '
. ($selected ? ' checked="checked"' : '') . ' /> ' . ($selected ? ' checked="checked"' : '') . ' /> '
. $label . $label
. '</label></div>'; . '</label></div>';
@ -268,7 +268,7 @@ function form_text($name, $label, $value, $disabled = false, $maxlength = null,
return form_element( return form_element(
$label, $label,
'<input class="form-control" id="form_' . $name . '" type="text" name="' . $name '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name
. '" value="' . htmlspecialchars($value) . '"' . $maxlength . $disabled . $autocomplete . '/>', . '" value="' . htmlspecialchars((string)$value) . '"' . $maxlength . $disabled . $autocomplete . '/>',
'form_' . $name, 'form_' . $name,
$class $class
); );
@ -288,7 +288,7 @@ function form_text_placeholder($name, $placeholder, $value, $disabled = false)
$disabled = $disabled ? ' disabled="disabled"' : ''; $disabled = $disabled ? ' disabled="disabled"' : '';
return form_element('', return form_element('',
'<input class="form-control" id="form_' . $name . '" type="text" name="' . $name '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name
. '" value="' . htmlspecialchars($value) . '" placeholder="' . $placeholder . '" value="' . htmlspecialchars((string)$value) . '" placeholder="' . $placeholder
. '" ' . $disabled . '/>' . '" ' . $disabled . '/>'
); );
} }
@ -313,7 +313,7 @@ function form_email($name, $label, $value, $disabled = false, $autocomplete = nu
return form_element( return form_element(
$label, $label,
'<input class="form-control" id="form_' . $name . '" type="email" name="' . $name . '" value="' '<input class="form-control" id="form_' . $name . '" type="email" name="' . $name . '" value="'
. htmlspecialchars($value) . '" ' . $disabled . $autocomplete . $maxlength . '/>', . htmlspecialchars((string)$value) . '" ' . $disabled . $autocomplete . $maxlength . '/>',
'form_' . $name 'form_' . $name
); );
} }
@ -391,7 +391,7 @@ function form_textarea($name, $label, $value, $disabled = false)
return form_element( return form_element(
$label, $label,
'<textarea rows="5" class="form-control" id="form_' . $name . '" name="' '<textarea rows="5" class="form-control" id="form_' . $name . '" name="'
. $name . '" ' . $disabled . '>' . htmlspecialchars($value) . '</textarea>', . $name . '" ' . $disabled . '>' . htmlspecialchars((string)$value) . '</textarea>',
'form_' . $name 'form_' . $name
); );
} }

View File

@ -403,7 +403,7 @@ function AngelType_view_info(
$info[] = '<h3>' . __('Description') . '</h3>'; $info[] = '<h3>' . __('Description') . '</h3>';
$parsedown = new Parsedown(); $parsedown = new Parsedown();
if ($angeltype['description'] != '') { if ($angeltype['description'] != '') {
$info[] = $parsedown->parse($angeltype['description']); $info[] = $parsedown->parse((string)$angeltype['description']);
} }
list($supporters, $members_confirmed, $members_unconfirmed) = AngelType_view_members( list($supporters, $members_confirmed, $members_unconfirmed) = AngelType_view_members(
@ -561,7 +561,7 @@ function AngelTypes_about_view_angeltype($angeltype)
); );
} }
if ($angeltype['description'] != '') { if ($angeltype['description'] != '') {
$html .= $parsedown->parse($angeltype['description']); $html .= $parsedown->parse((string)$angeltype['description']);
} }
$html .= '<hr />'; $html .= '<hr />';

View File

@ -24,7 +24,7 @@ function Room_view(Room $room, ShiftsFilterRenderer $shiftsFilterRenderer, Shift
if ($room->description) { if ($room->description) {
$description = '<h3>' . __('Description') . '</h3>'; $description = '<h3>' . __('Description') . '</h3>';
$parsedown = new Parsedown(); $parsedown = new Parsedown();
$description .= $parsedown->parse($room->description); $description .= $parsedown->parse((string)$room->description);
} }
$tabs = []; $tabs = [];

View File

@ -98,7 +98,7 @@ function ShiftType_view($shifttype, $angeltype)
) )
]), ]),
heading(__('Description'), 2), heading(__('Description'), 2),
$parsedown->parse($shifttype['description']) $parsedown->parse((string)$shifttype['description'])
], true); ], true);
} }

View File

@ -176,8 +176,8 @@ function Shift_view($shift, $shifttype, Room $room, $angeltypes_source, ShiftSig
]), ]),
div('col-sm-6', [ div('col-sm-6', [
'<h2>' . __('Description') . '</h2>', '<h2>' . __('Description') . '</h2>',
$parsedown->parse($shifttype['description']), $parsedown->parse((string)$shifttype['description']),
$parsedown->parse($shift['description']), $parsedown->parse((string)$shift['description']),
]) ])
]); ]);

View File

@ -32,7 +32,7 @@ class ConfigureEnvironmentServiceProvider extends ServiceProvider
*/ */
protected function setTimeZone(CarbonTimeZone $timeZone) protected function setTimeZone(CarbonTimeZone $timeZone)
{ {
ini_set('date.timezone', $timeZone); ini_set('date.timezone', (string)$timeZone);
date_default_timezone_set($timeZone); date_default_timezone_set($timeZone);
} }

View File

@ -43,7 +43,8 @@ abstract class AbstractHandler implements SessionHandlerInterface
* @param int $maxLifetime * @param int $maxLifetime
* @return bool * @return bool
*/ */
public function gc($maxLifetime): bool #[\ReturnTypeWillChange]
public function gc($maxLifetime)
{ {
return true; return true;
} }

View File

@ -74,7 +74,7 @@ class DatabaseHandler extends AbstractHandler
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function gc($maxLifetime): bool public function gc($maxLifetime)
{ {
$timestamp = $this->getCurrentTimestamp(-$maxLifetime); $timestamp = $this->getCurrentTimestamp(-$maxLifetime);

View File

@ -72,7 +72,7 @@ class Logger extends AbstractLogger
} }
// replace the values of the message // replace the values of the message
$message = str_replace('{' . $key . '}', $val, $message); $message = str_replace('{' . $key . '}', (string)$val, $message);
} }
return $message; return $message;

View File

@ -77,7 +77,7 @@ class ErrorHandler implements MiddlewareInterface
$statusCode = $response->getStatusCode(); $statusCode = $response->getStatusCode();
$contentType = $response->getHeader('content-type'); $contentType = $response->getHeader('content-type');
$contentType = array_shift($contentType); $contentType = array_shift($contentType);
if (!$contentType && strpos($response->getBody(), '<html') !== false) { if (!$contentType && strpos($response->getBody() ?? '', '<html') !== false) {
$contentType = 'text/html'; $contentType = 'text/html';
} }

View File

@ -64,6 +64,10 @@ class SendResponseHandler implements MiddlewareInterface
*/ */
protected function sendHeader($content, $replace = true, $code = null) protected function sendHeader($content, $replace = true, $code = null)
{ {
if (is_null($code)) {
header($content, $replace);
} else {
header($content, $replace, $code); header($content, $replace, $code);
} }
}
} }

View File

@ -50,7 +50,7 @@ class EventConfig extends BaseModel
*/ */
public function getValueAttribute($value) public function getValueAttribute($value)
{ {
$value = $this->fromJson($value); $value = $value ? $this->fromJson($value) : null;
/** @see \Illuminate\Database\Eloquent\Concerns\HasAttributes::castAttribute */ /** @see \Illuminate\Database\Eloquent\Concerns\HasAttributes::castAttribute */
if (!empty($value)) { if (!empty($value)) {

View File

@ -78,6 +78,10 @@ class EventConfigTest extends ModelTest
->value ->value
->format('Y-m-d H:i') ->format('Y-m-d H:i')
); );
$this->assertEquals(
null,
($this->getEventConfig())->getValueAttribute(null)
);
} }
/** /**