Skip to content

Move partner sites into config #1489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config.dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,8 @@
"discord": {
"url": "https://chat.change.me"
},
"partner_banner_path": "sites/"
"partner_sites": {
"banner_path": "sites/",
"items": []
}
}
45 changes: 0 additions & 45 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5365,16 +5365,6 @@ parameters:
count: 1
path: src/Module/Control/GameController.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameController\\:\\:executeCallback\\(\\) has parameter \\$actions with no value type specified in iterable type array\\.$#"
count: 1
path: src/Module/Control/GameController.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameController\\:\\:executeView\\(\\) has parameter \\$views with no value type specified in iterable type array\\.$#"
count: 1
path: src/Module/Control/GameController.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameController\\:\\:getAchievements\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -5415,16 +5405,6 @@ parameters:
count: 1
path: src/Module/Control/GameController.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameController\\:\\:main\\(\\) has parameter \\$actions with no value type specified in iterable type array\\.$#"
count: 1
path: src/Module/Control/GameController.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameController\\:\\:main\\(\\) has parameter \\$views with no value type specified in iterable type array\\.$#"
count: 1
path: src/Module/Control/GameController.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameController\\:\\:sendInformation\\(\\) has parameter \\$category_id with no type specified\\.$#"
count: 1
Expand Down Expand Up @@ -5555,16 +5535,6 @@ parameters:
count: 1
path: src/Module/Control/GameControllerInterface.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameControllerInterface\\:\\:main\\(\\) has parameter \\$actions with no value type specified in iterable type array\\.$#"
count: 1
path: src/Module/Control/GameControllerInterface.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameControllerInterface\\:\\:main\\(\\) has parameter \\$views with no value type specified in iterable type array\\.$#"
count: 1
path: src/Module/Control/GameControllerInterface.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameControllerInterface\\:\\:sendInformation\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -11040,26 +11010,11 @@ parameters:
count: 1
path: src/Module/Ship/View/ShowShip/ShowShip.php

-
message: "#^Strict comparison using \\=\\=\\= between Stu\\\\Orm\\\\Entity\\\\ShipInterface and null will always evaluate to false\\.$#"
count: 1
path: src/Module/Ship/View/ShowShip/ShowShip.php

-
message: "#^Ternary operator condition is always true\\.$#"
count: 1
path: src/Module/Ship/View/ShowShip/ShowShip.php

-
message: "#^Variable \\$astroEntry might not be defined\\.$#"
count: 1
path: src/Module/Ship/View/ShowShip/ShowShip.php

-
message: "#^Variable \\$firstOrbitShip might not be defined\\.$#"
count: 2
path: src/Module/Ship/View/ShowShip/ShowShip.php

-
message: "#^Variable \\$startTime might not be defined\\.$#"
count: 5
Expand Down
35 changes: 29 additions & 6 deletions src/Module/Index/View/ShowPartnerSites/ShowPartnerSites.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,50 @@

namespace Stu\Module\Index\View\ShowPartnerSites;

use Noodlehaus\ConfigInterface;
use Stu\Module\Control\GameControllerInterface;
use Stu\Module\Control\ViewControllerInterface;
use Stu\Orm\Repository\PartnerSiteRepositoryInterface;

/**
* Shows all partner site items from the config
*/
final class ShowPartnerSites implements ViewControllerInterface
{
public const VIEW_IDENTIFIER = 'SHOW_PARTNER_SITES';

private PartnerSiteRepositoryInterface $partnerSiteRepository;
private ConfigInterface $config;

public function __construct(
PartnerSiteRepositoryInterface $partnerSiteRepository
ConfigInterface $config
) {
$this->partnerSiteRepository = $partnerSiteRepository;
$this->config = $config;
}

public function handle(GameControllerInterface $game): void
{
$game->setPageTitle(_('Partnerseiten - Star Trek Universe'));
$game->setPageTitle('Partnerseiten - Star Trek Universe');
$game->setTemplateFile('html/index_partner_sites.xhtml');

$game->setTemplateVar('PARTNERSITES', $this->partnerSiteRepository->getOrdered());
$game->setTemplateVar('PARTNERSITES', $this->getPartnerSites());
}

/**
* @return array<array{name: string, description: string, url: string, banner_path: string}>
*/
private function getPartnerSites(): array {
$baseBannerPath = $this->config->get('partner_sites.banner_path');

return array_map(
function (array $item) use ($baseBannerPath): array {
/** @var array{name: string, description: string, url: string, banner_path: string} $item */
$item['banner_path'] = sprintf(
'/%s/%s.png',
$baseBannerPath,
$item['banner_path']
);
return $item;
},
$this->config->get('partner_sites.items', [])
);
}
}
15 changes: 0 additions & 15 deletions src/Orm/Entity/PartnerSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Table;
use Noodlehaus\ConfigInterface;

/**
* @Entity(repositoryClass="Stu\Orm\Repository\PartnerSiteRepository")
Expand Down Expand Up @@ -82,18 +81,4 @@ public function getBanner(): string
{
return $this->banner;
}

public function getFullBannerPath(): string
{
// @todo refactor
global $container;

$config = $container->get(ConfigInterface::class);

return sprintf(
'/%s/%s.png',
$config->get('partner_banner_path'),
$this->getBanner()
);
}
}
2 changes: 0 additions & 2 deletions src/Orm/Entity/PartnerSiteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ public function getUrl(): string;
public function getText(): string;

public function getBanner(): string;

public function getFullBannerPath(): string;
}
8 changes: 4 additions & 4 deletions src/html/index_partner_sites.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</div>
<tal:block tal:repeat="site PARTNERSITES">
<div style="width: 100%;">
<h4>${site/getName}</h4>
${site/getText}<br />
<a href="${site/getUrl}">
<img tal:attributes="src site/getFullBannerPath" />
<h4 tal:content="site/name">NAME</h4>
<div tal:content="site/description">DESCRIPTION</div>
<a tal:attributes="href site/url">
<img tal:attributes="src site/banner_path; alt site/name; title site/name" />
</a>
<br />
</div>
Expand Down
81 changes: 81 additions & 0 deletions tests/Module/Index/View/ShowPartnerSites/ShowPartnerSitesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);

namespace Stu\Module\Index\View\ShowPartnerSites;

use Generator;
use Mockery;
use Mockery\MockInterface;
use Noodlehaus\ConfigInterface;
use Stu\Module\Control\GameControllerInterface;
use Stu\StuTestCase;

class ShowPartnerSitesTest extends StuTestCase
{
/** @var MockInterface&ConfigInterface */
private MockInterface $config;

private ShowPartnerSites $subject;

protected function setUp(): void
{
$this->config = $this->mock(ConfigInterface::class);

$this->subject = new ShowPartnerSites(
$this->config
);
}

public function testHandleShowsSites(): void
{
$game = $this->mock(GameControllerInterface::class);

$baseBannerPath = 'some-base-banner-path';
$siteName = 'some-site';
$siteDescription = 'some-fancy-site';
$siteUrl = 'some-url';
$siteBannerPath = 'some-banner-path';
$computedBannerPath = sprintf(
'/%s/%s.png',
$baseBannerPath,
$siteBannerPath
);

$game->shouldReceive('setPageTitle')
->with('Partnerseiten - Star Trek Universe')
->once();
$game->shouldReceive('setTemplateFile')
->with('html/index_partner_sites.xhtml')
->once();
$game->shouldReceive('setTemplateVar')
->with(
'PARTNERSITES',
Mockery::on(fn (array $items): bool =>
$items === [[
'name' => $siteName,
'description' => $siteDescription,
'url' => $siteUrl,
'banner_path' => $computedBannerPath,
]]
)
)
->once();

$this->config->shouldReceive('get')
->with('partner_sites.items', [])
->once()
->andReturn([[
'name' => $siteName,
'description' => $siteDescription,
'url' => $siteUrl,
'banner_path' => $siteBannerPath,
]]);
$this->config->shouldReceive('get')
->with('partner_sites.banner_path')
->once()
->andReturn($baseBannerPath);

$this->subject->handle($game);
}
}