diff --git a/config.dist.json b/config.dist.json index cd668528e3..e7d2ead962 100644 --- a/config.dist.json +++ b/config.dist.json @@ -89,5 +89,8 @@ "discord": { "url": "https://chat.change.me" }, - "partner_banner_path": "sites/" + "partner_sites": { + "banner_path": "sites/", + "items": [] + } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3ceb7720a1..9c61ea2e92 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/Module/Index/View/ShowPartnerSites/ShowPartnerSites.php b/src/Module/Index/View/ShowPartnerSites/ShowPartnerSites.php index dbbe657a0b..03c4792ff4 100644 --- a/src/Module/Index/View/ShowPartnerSites/ShowPartnerSites.php +++ b/src/Module/Index/View/ShowPartnerSites/ShowPartnerSites.php @@ -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 + */ + 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', []) + ); } } diff --git a/src/Orm/Entity/PartnerSite.php b/src/Orm/Entity/PartnerSite.php index 830e7d8a0a..21f604f66c 100644 --- a/src/Orm/Entity/PartnerSite.php +++ b/src/Orm/Entity/PartnerSite.php @@ -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") @@ -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() - ); - } } diff --git a/src/Orm/Entity/PartnerSiteInterface.php b/src/Orm/Entity/PartnerSiteInterface.php index 0a3a454c93..5ecf46a397 100644 --- a/src/Orm/Entity/PartnerSiteInterface.php +++ b/src/Orm/Entity/PartnerSiteInterface.php @@ -13,6 +13,4 @@ public function getUrl(): string; public function getText(): string; public function getBanner(): string; - - public function getFullBannerPath(): string; } diff --git a/src/html/index_partner_sites.xhtml b/src/html/index_partner_sites.xhtml index 1ed8210e2a..c1f002838d 100644 --- a/src/html/index_partner_sites.xhtml +++ b/src/html/index_partner_sites.xhtml @@ -7,10 +7,10 @@
-

${site/getName}

- ${site/getText}
- - +

NAME

+
DESCRIPTION
+
+
diff --git a/tests/Module/Index/View/ShowPartnerSites/ShowPartnerSitesTest.php b/tests/Module/Index/View/ShowPartnerSites/ShowPartnerSitesTest.php new file mode 100644 index 0000000000..5da71888ce --- /dev/null +++ b/tests/Module/Index/View/ShowPartnerSites/ShowPartnerSitesTest.php @@ -0,0 +1,81 @@ +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); + } +}