Skip to content

Commit f42c701

Browse files
committed
fix: PHP 7.3 compatibility and yarn format
1 parent 96de887 commit f42c701

4 files changed

Lines changed: 37 additions & 20 deletions

File tree

framework/core/js/src/admin/components/AnnouncementItem.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ export default class AnnouncementItem extends Component<IAnnouncementItemAttrs>
4040
{a.avatarUrl ? (
4141
<img className="AnnouncementItem-avatar" src={a.avatarUrl} alt={a.authorName ?? ''} loading="lazy" />
4242
) : (
43-
<span className="AnnouncementItem-avatarFallback">
44-
{icon('fas fa-user')}
45-
</span>
43+
<span className="AnnouncementItem-avatarFallback">{icon('fas fa-user')}</span>
4644
)}
4745
<div className="AnnouncementItem-bylineText">
4846
{a.authorName && <span className="AnnouncementItem-authorName">{a.authorName}</span>}

framework/core/js/src/admin/components/AnnouncementWidget.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ export default class AnnouncementsWidget extends DashboardWidget {
6969
{icon('fas fa-bullhorn')}
7070
{app.translator.trans('core.admin.announcements.title')}
7171
<Tooltip text={app.translator.trans('core.admin.announcements.about')}>
72-
<span className="AnnouncementsWidget-info">
73-
{icon('fas fa-info-circle')}
74-
</span>
72+
<span className="AnnouncementsWidget-info">{icon('fas fa-info-circle')}</span>
7573
</Tooltip>
7674
</h2>
7775
<div className="AnnouncementsWidget-controls">

framework/core/src/Announcements/AnnouncementsFetcher.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,28 @@
1818

1919
class AnnouncementsFetcher
2020
{
21-
private Client $client;
22-
23-
public function __construct(
24-
protected ApplicationInfoProvider $appInfo
25-
) {
26-
$this->client = new Client(['timeout' => 10]);
27-
}
2821
protected const API_BASE_URL = 'https://discuss.flarum.org/api/discussions';
2922
protected const TAG = 'blog';
3023
protected const LIMIT = 8;
3124
protected const FETCH_LIMIT = 20;
3225
protected const EXCERPT_LENGTH = 200;
3326

27+
/**
28+
* @var ApplicationInfoProvider
29+
*/
30+
protected $appInfo;
31+
32+
/**
33+
* @var Client
34+
*/
35+
private $client;
36+
37+
public function __construct(ApplicationInfoProvider $appInfo)
38+
{
39+
$this->appInfo = $appInfo;
40+
$this->client = new Client(['timeout' => 10]);
41+
}
42+
3443
public function fetch(): array
3544
{
3645
$url = self::API_BASE_URL.'?'.http_build_query([
@@ -101,7 +110,9 @@ public function fetch(): array
101110
];
102111
}
103112

104-
usort($items, fn (array $a, array $b) => $b['isSticky'] <=> $a['isSticky']);
113+
usort($items, function (array $a, array $b) {
114+
return $b['isSticky'] <=> $a['isSticky'];
115+
});
105116

106117
return array_slice($items, 0, self::LIMIT);
107118
}

framework/core/src/Api/Controller/ListAnnouncementsController.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,20 @@ class ListAnnouncementsController implements RequestHandlerInterface
2222
public const CACHE_KEY = 'flarum.announcements';
2323
public const CACHE_TTL = 14 * 24 * 3600; // 14 days
2424

25-
public function __construct(
26-
protected CacheRepository $cache,
27-
protected AnnouncementsFetcher $fetcher
28-
) {
25+
/**
26+
* @var CacheRepository
27+
*/
28+
protected $cache;
29+
30+
/**
31+
* @var AnnouncementsFetcher
32+
*/
33+
protected $fetcher;
34+
35+
public function __construct(CacheRepository $cache, AnnouncementsFetcher $fetcher)
36+
{
37+
$this->cache = $cache;
38+
$this->fetcher = $fetcher;
2939
}
3040

3141
public function handle(ServerRequestInterface $request): ResponseInterface
@@ -36,7 +46,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
3646
try {
3747
$announcements = $this->fetcher->fetch();
3848
$this->cache->put(self::CACHE_KEY, $announcements, self::CACHE_TTL);
39-
} catch (\RuntimeException) {
49+
} catch (\RuntimeException $_e) {
4050
$announcements = $this->cache->get(self::CACHE_KEY, []);
4151
}
4252

@@ -49,7 +59,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4959
function () {
5060
try {
5161
return $this->fetcher->fetch();
52-
} catch (\RuntimeException) {
62+
} catch (\RuntimeException $_e) {
5363
return null; // keep existing cached value
5464
}
5565
}

0 commit comments

Comments
 (0)