Skip to content

Commit

Permalink
Improve PHP 8 compatibility
Browse files Browse the repository at this point in the history
Trying to access non-existent array fields is a warning in PHP 8.
Though this error is masked by ddeboer/transcoder#5 in the integration tests when mbstring extension is available.

Also, Dice uses `ReflectionParameter::getClass()`, which is deprecated in PHP 8. Since we have not yet set an error handler at that point because it needs a `Logger` class instantiated by Dice, let’s disable deprecation warnings temporarily. Unfortunately, we cannot just re-enable them and log them in the error handler since fatfree’s error handler is extremely inflexible bcosca/fatfree#999.
  • Loading branch information
jtojnar committed Dec 16, 2020
1 parent adaf0e8 commit 71ff3b5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@

$f3 = Base::instance();

// Disable deprecation warnings.
// Dice uses ReflectionParameter::getClass(), which is deprecated in PHP 8
// but we have not set an error handler yet because it needs a Logger instantiated by Dice.
error_reporting(E_ALL & ~E_DEPRECATED);

$f3->set('DEBUG', 0);
$f3->set('version', '2.19-SNAPSHOT');

Expand Down Expand Up @@ -203,6 +208,7 @@

// init logger
$log = $dice->create(Logger::class);

if ($f3->get('logger_level') === 'NONE') {
$handler = new NullHandler();
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ private function loadItems(array $params, array $tags) {
$itemsHtml = '';

$firstPage = $params['offset'] == 0
&& $params['fromId'] == ''
&& $params['fromDatetime'] == '';
&& (!isset($params['fromId']) || $params['fromId'] == '')
&& (!isset($params['fromDatetime']) || $params['fromDatetime'] == '');
if ($params['source'] && $this->authentication->allowedToUpdate() && $firstPage) {
$itemsHtml = '<button type="button" id="refresh-source" class="refresh-source">' . \F3::get('lang_source_refresh') . '</button>';
}
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/Sources/Write.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ public function write(Base $f3, array $params) {
}
$tags = array_map('htmlspecialchars', $data['tags']);
$spout = $data['spout'];
$filter = $data['filter'];
$filter = isset($data['filter']) ? $data['filter'] : null;

unset($data['title']);
unset($data['spout']);
unset($data['filter']);
unset($data['tags']);

// check if source already exists
$id = $params['id'];
$sourceExists = $this->sourcesDao->isValid('id', $id);
$id = isset($params['id']) ? $params['id'] : null;
$sourceExists = $id !== null && $this->sourcesDao->isValid('id', $id);

// load password value if not changed for spouts containing passwords
if ($sourceExists) {
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/ContentLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ public function fetch($source) {
'datetime' => $itemDate->format('Y-m-d H:i:s'),
'uid' => $item->getId(),
'link' => htmLawed($item->getLink(), ['deny_attribute' => '*', 'elements' => '-*']),
'author' => $author
'author' => $author,
'thumbnail' => null,
'icon' => null,
];

$thumbnailUrl = $item->getThumbnail();
Expand Down

0 comments on commit 71ff3b5

Please sign in to comment.