Skip to content

Commit

Permalink
refactor: fix phpstan & phpcs issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tbreuss committed Jul 1, 2023
1 parent cf223e5 commit d7c51ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions widgets/Banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

final class Banner extends Widget
{
/** @var string[][] */
public array $items = [
[
'url' => 'https://www.amazon.de/music/unlimited?tag=electricbas03-21&linkCode=ur1',
Expand Down Expand Up @@ -36,14 +37,23 @@ final class Banner extends Widget
'url' => 'https://www.amazon.de/gp/video/offers/?tag=electricbas03-21&linkCode=ur1&benefitId=starzplay',
'img' => '@app/widgets/images/amazon_prime_video_300x250.jpg',
'alt' => 'Amazon prime video: Onlinevideothek und Video-on-Demand-Angebot',
],
],
];

public function run()
public function run(): string
{
$item = $this->getRandomItem();

$imgPath = \Yii::getAlias($item['img']);
if ($imgPath === false) {
return '';
}

$imgContent = file_get_contents($imgPath);
if ($imgContent === false) {
return '';
}

$imgType = pathinfo($imgPath, PATHINFO_EXTENSION);
return $this->render('banner', [
'url' => $item['url'],
Expand Down
9 changes: 9 additions & 0 deletions widgets/views/banner.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<?php

/**
* @var string $imgAlt
* @var string $imgContent
* @var string $imgType
* @var string $url
*/
?>
<a href="<?= $url ?>" target="_blank">
<img class="img-fluid" src="data:image/<?= $imgType ?>;base64,<?= base64_encode($imgContent) ?>" width="300" height="250" alt="<?= $imgAlt ?>">
</a>

0 comments on commit d7c51ec

Please sign in to comment.