mirror of
https://github.com/werkraum-media/thuecat.git
synced 2024-12-04 19:16:13 +01:00
parent
20dc69694d
commit
6c119f28af
4 changed files with 31 additions and 28 deletions
|
@ -33,14 +33,15 @@ class Media implements TypeInterface
|
|||
private $serialized;
|
||||
|
||||
/**
|
||||
* @var mixed[]
|
||||
* @var array[]
|
||||
*/
|
||||
private $data;
|
||||
|
||||
public function __construct(string $serialized)
|
||||
{
|
||||
$this->serialized = $serialized;
|
||||
$this->data = json_decode($serialized, true);
|
||||
$data = json_decode($serialized, true);
|
||||
$this->data = is_array($data) ? $data : [];
|
||||
}
|
||||
|
||||
public function getMainImage(): array
|
||||
|
@ -59,11 +60,19 @@ class Media implements TypeInterface
|
|||
|
||||
public function getImages(): array
|
||||
{
|
||||
return array_filter($this->data, function (array $media) {
|
||||
return array_filter($this->data, function (array $media): bool {
|
||||
return $media['type'] === 'image';
|
||||
});
|
||||
}
|
||||
|
||||
public function getExtraImages(): array
|
||||
{
|
||||
return array_filter($this->data, function (array $media): bool {
|
||||
return $media['type'] === 'image'
|
||||
&& $media['mainImage'] === false;
|
||||
});
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->serialized;
|
||||
|
|
|
@ -30,6 +30,9 @@ Features
|
|||
|
||||
* The URL of attractions is now imported and provided to the template.
|
||||
|
||||
* Media has a new method ``getExtraImages()`` which will return everything from
|
||||
``getImages()`` except the ``getMainImage()``.
|
||||
|
||||
Fixes
|
||||
-----
|
||||
|
||||
|
|
|
@ -85,4 +85,20 @@ class MediaTest extends TestCase
|
|||
],
|
||||
], $subject->getImages());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsExtraImagesAsArray(): void
|
||||
{
|
||||
$subject = new Media('[{"mainImage":false,"type":"image","title":"Erfurt-Dom-und-Severikirche.jpg"},{"mainImage":true,"type":"image","title":"Erfurt-Dom und Severikirche-beleuchtet.jpg"}]');
|
||||
|
||||
self::assertSame([
|
||||
[
|
||||
'mainImage' => false,
|
||||
'type' => 'image',
|
||||
'title' => 'Erfurt-Dom-und-Severikirche.jpg',
|
||||
],
|
||||
], $subject->getExtraImages());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -224,31 +224,6 @@ parameters:
|
|||
count: 1
|
||||
path: Classes/Domain/Model/Frontend/Address.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 'mainImage' on mixed\\.$#"
|
||||
count: 1
|
||||
path: Classes/Domain/Model/Frontend/Media.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 'type' on mixed\\.$#"
|
||||
count: 1
|
||||
path: Classes/Domain/Model/Frontend/Media.php
|
||||
|
||||
-
|
||||
message: "#^Method WerkraumMedia\\\\ThueCat\\\\Domain\\\\Model\\\\Frontend\\\\Media\\:\\:getMainImage\\(\\) should return array but returns mixed\\.$#"
|
||||
count: 1
|
||||
path: Classes/Domain/Model/Frontend/Media.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$callback of function array_filter expects callable\\(mixed\\)\\: mixed, Closure\\(array\\)\\: bool given\\.$#"
|
||||
count: 1
|
||||
path: Classes/Domain/Model/Frontend/Media.php
|
||||
|
||||
-
|
||||
message: "#^Property WerkraumMedia\\\\ThueCat\\\\Domain\\\\Model\\\\Frontend\\\\Media\\:\\:\\$data \\(array\\) does not accept mixed\\.$#"
|
||||
count: 1
|
||||
path: Classes/Domain/Model/Frontend/Media.php
|
||||
|
||||
-
|
||||
message: "#^Method WerkraumMedia\\\\ThueCat\\\\Domain\\\\Model\\\\Frontend\\\\Offers\\:\\:current\\(\\) should return WerkraumMedia\\\\ThueCat\\\\Domain\\\\Model\\\\Frontend\\\\Offer but returns mixed\\.$#"
|
||||
count: 1
|
||||
|
|
Loading…
Reference in a new issue