Skip to content

Commit 42ceefc

Browse files
author
roadiz-ci
committed
Merge tag v2.7.0 into develop
1 parent c8cec80 commit 42ceefc

14 files changed

Lines changed: 86 additions & 99 deletions

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
"api-platform/metadata": "^4.1.18",
4646
"doctrine/doctrine-bundle": "^2.8.1",
4747
"php-coveralls/php-coveralls": "^2.4",
48-
"phpstan/phpstan": "^1.5.3",
48+
"phpstan/phpstan": "^2.1.36",
4949
"phpstan/phpdoc-parser": "<2",
50-
"phpstan/phpstan-doctrine": "^1.3",
50+
"phpstan/phpstan-doctrine": "^2.0.13",
5151
"phpunit/phpunit": "^9.6",
5252
"symfony/http-client": "7.4.*",
5353
"symfony/process": "7.4.*"
@@ -70,8 +70,8 @@
7070
},
7171
"extra": {
7272
"branch-alias": {
73-
"dev-master": "2.6.x-dev",
74-
"dev-develop": "2.7.x-dev"
73+
"dev-master": "2.7.x-dev",
74+
"dev-develop": "2.8.x-dev"
7575
}
7676
}
7777
}

src/Console/DocumentSizeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3939

4040
private function updateDocumentSize(DocumentInterface $document): void
4141
{
42-
if (!($document instanceof SizeableInterface)) {
42+
if (!$document instanceof SizeableInterface) {
4343
return;
4444
}
4545
$mountPath = $document->getMountPath();

src/MediaFinders/AbstractYoutubeEmbedFinder.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ public function getSearchFeed(string $searchTerm, ?string $author = null, int $m
157157
}
158158

159159
return $this->downloadFeedFromAPI($url);
160-
} else {
161-
throw new APINeedsAuthentificationException('YoutubeEmbedFinder needs a Google server key, create a “google_server_id” setting.', 1);
162160
}
161+
throw new APINeedsAuthentificationException('YoutubeEmbedFinder needs a Google server key, create a “google_server_id” setting.', 1);
163162
}
164163

165164
/**

src/MediaFinders/EmbedFinderFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727

2828
public function createForPlatform(?string $mediaPlatform, ?string $embedId): ?EmbedFinderInterface
2929
{
30-
if (null !== $embedId && $this->supports($mediaPlatform)) {
30+
if (null !== $embedId && null !== $mediaPlatform && $this->supports($mediaPlatform)) {
3131
/**
3232
* @var class-string<EmbedFinderInterface> $class
3333
*/
@@ -44,10 +44,6 @@ public function createForUrl(?string $embedUrl): ?EmbedFinderInterface
4444
if (null === $embedUrl) {
4545
throw new \InvalidArgumentException('"embedUrl" is required');
4646
}
47-
// Throws a BadRequestHttpException if the embedUrl is not a string
48-
if (!is_string($embedUrl)) {
49-
throw new \InvalidArgumentException('"embedUrl" must be a string');
50-
}
5147
// Throws a BadRequestHttpException if the embedUrl is not a valid URL
5248
if (!filter_var($embedUrl, FILTER_VALIDATE_URL)) {
5349
throw new \InvalidArgumentException('"embedUrl" is not a valid URL');

src/Models/BaseDocumentTrait.php

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -153,36 +153,33 @@ trait BaseDocumentTrait
153153
'image/heif',
154154
];
155155

156-
#[
157-
Serializer\Groups(['document_mount']),
158-
Serializer\SerializedName('mountPath'),
159-
]
156+
#[Serializer\Groups(['document_mount']),
157+
Serializer\SerializedName('mountPath'),]
160158
public function getMountPath(): ?string
161159
{
162160
if (null === $relativePath = $this->getRelativePath()) {
163161
return null;
164162
}
165163
if ($this->isPrivate()) {
166164
return 'private://'.$relativePath;
167-
} else {
168-
return 'public://'.$relativePath;
169165
}
166+
167+
return 'public://'.$relativePath;
170168
}
171169

172170
/**
173171
* Get short type name for current document Mime type.
174172
*/
175-
#[
176-
Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
177-
Serializer\SerializedName('type'),
178-
]
173+
#[Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
174+
Serializer\SerializedName('type'),]
179175
public function getShortType(): string
180176
{
181-
if (null !== $this->getMimeType() && isset(static::$mimeToIcon[$this->getMimeType()])) {
182-
return static::$mimeToIcon[$this->getMimeType()];
183-
} else {
184-
return 'unknown';
177+
$mimeType = (string) $this->getMimeType();
178+
if ('' !== $mimeType && isset(static::$mimeToIcon[$mimeType])) {
179+
return static::$mimeToIcon[$mimeType];
185180
}
181+
182+
return 'unknown';
186183
}
187184

188185
/**
@@ -251,32 +248,26 @@ public function isWebp(): bool
251248
return 'image/webp' === $this->getMimeType();
252249
}
253250

254-
#[
255-
Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
256-
Serializer\SerializedName('relativePath'),
257-
]
251+
#[Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
252+
Serializer\SerializedName('relativePath'),]
258253
public function getRelativePath(): ?string
259254
{
260255
return $this->isLocal() ? $this->getFolder().'/'.$this->getFilename() : null;
261256
}
262257

263-
#[
264-
Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
258+
#[Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
265259
Serializer\SerializedName('processable'),
266260
ApiProperty(
267261
description: 'Document can be processed as an image for resampling and other image operations.',
268262
writable: false,
269-
)
270-
]
263+
)]
271264
public function isProcessable(): bool
272265
{
273266
return !$this->isPrivate() && $this->isImage() && in_array($this->getMimeType(), static::$processableMimeTypes, true);
274267
}
275268

276-
#[
277-
Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
278-
Serializer\SerializedName('alt'),
279-
]
269+
#[Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
270+
Serializer\SerializedName('alt'),]
280271
public function getAlternativeText(): ?string
281272
{
282273
return null;

src/Models/DocumentTrait.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
trait DocumentTrait
1111
{
12-
#[
13-
Serializer\Ignore
14-
]
12+
#[Serializer\Ignore]
1513
public function getMountFolderPath(): ?string
1614
{
1715
$folder = $this->getFolder();
@@ -20,9 +18,9 @@ public function getMountFolderPath(): ?string
2018
}
2119
if ($this->isPrivate()) {
2220
return 'private://'.$folder;
23-
} else {
24-
return 'public://'.$folder;
2521
}
22+
23+
return 'public://'.$folder;
2624
}
2725

2826
protected function initDocumentTrait(): void

src/Renderer/AbstractImageRenderer.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,18 @@ protected function createTransparentDataURI(string $hexColor, int $width = 1, in
105105
throw new \RuntimeException('Color is not a valid hexadecimal RGB format');
106106
}
107107
[$r, $g, $b] = $hexColorArray;
108+
$width = max(1, $width);
109+
$height = max(1, $height);
110+
$red = max(0, min(255, $r ?? 0));
111+
$green = max(0, min(255, $g ?? 0));
112+
$blue = max(0, min(255, $b ?? 0));
108113
$im = \imagecreatetruecolor($width, $height);
109114
if ($im) {
110115
\imagefill(
111116
$im,
112117
0,
113118
0,
114-
\imagecolorallocate($im, $r ?? 0, $g ?? 0, $b ?? 0) ?: 0
119+
\imagecolorallocate($im, $red, $green, $blue) ?: 0
115120
);
116121
\ob_start();
117122
\imagejpeg($im, null, 30);
@@ -126,9 +131,9 @@ protected function createTransparentDataURI(string $hexColor, int $width = 1, in
126131

127132
protected function getImageRatio(array &$options): ?float
128133
{
129-
/** @var \ArrayAccess<string, string|null> $options */
134+
/** @var array<string, string|int|float|null> $options */
130135
$compositing = $options['crop'] ?? $options['fit'] ?? '';
131-
if (1 === preg_match(static::WIDTH_HEIGHT_PATTERN, $compositing, $matches)) {
136+
if (1 === preg_match(static::WIDTH_HEIGHT_PATTERN, (string) $compositing, $matches)) {
132137
return ((float) $matches['width']) / ((float) $matches['height']);
133138
}
134139

@@ -137,9 +142,9 @@ protected function getImageRatio(array &$options): ?float
137142

138143
protected function getImageWidth(array &$options): int
139144
{
140-
/** @var \ArrayAccess<string, string|null> $options */
145+
/** @var array<string, string|int|float|null> $options */
141146
$compositing = $options['fit'] ?? '';
142-
if (1 === preg_match(static::WIDTH_HEIGHT_PATTERN, $compositing, $matches)) {
147+
if (1 === preg_match(static::WIDTH_HEIGHT_PATTERN, (string) $compositing, $matches)) {
143148
return (int) $matches['width'];
144149
} elseif (null !== $options['ratio'] && 0 !== $options['height'] && 0 !== $options['ratio']) {
145150
return (int) (intval($options['height']) * floatval($options['ratio']));
@@ -150,9 +155,9 @@ protected function getImageWidth(array &$options): int
150155

151156
protected function getImageHeight(array &$options): int
152157
{
153-
/** @var \ArrayAccess<string, string|null> $options */
158+
/** @var array<string, string|int|float|null> $options */
154159
$compositing = $options['fit'] ?? '';
155-
if (1 === preg_match(static::WIDTH_HEIGHT_PATTERN, $compositing, $matches)) {
160+
if (1 === preg_match(static::WIDTH_HEIGHT_PATTERN, (string) $compositing, $matches)) {
156161
return (int) $matches['height'];
157162
} elseif (null !== $options['ratio'] && 0 !== $options['width'] && 0 !== $options['ratio']) {
158163
return (int) (intval($options['width']) / floatval($options['ratio']));
@@ -176,7 +181,7 @@ protected function additionalAssignation(BaseDocumentInterface $document, array
176181
$assignation['height'] = $options['height'] = $this->getImageHeight($options);
177182
}
178183

179-
if (!($document instanceof AdvancedDocumentInterface)) {
184+
if (!$document instanceof AdvancedDocumentInterface) {
180185
return;
181186
}
182187

src/Renderer/AbstractRenderer.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ protected function getSourcesFilesArray(BaseDocumentInterface $document, iterabl
5757

5858
foreach ($sourcesDocs as $source) {
5959
$sourceMountPath = $source->getMountPath();
60-
if (null !== $sourceMountPath) {
61-
$sources[$source->getMimeType()] = [
62-
'mime' => $source->getMimeType(),
60+
$sourceMimeType = $source->getMimeType();
61+
if (null !== $sourceMountPath && null !== $sourceMimeType) {
62+
$sources[$sourceMimeType] = [
63+
'mime' => $sourceMimeType,
6364
'url' => $this->documentsStorage->publicUrl($sourceMountPath),
6465
];
6566
}
@@ -69,9 +70,10 @@ protected function getSourcesFilesArray(BaseDocumentInterface $document, iterabl
6970
if (0 === count($sources)) {
7071
// If exotic extension, fallbacks using original file
7172
$documentMountPath = $document->getMountPath();
72-
if (null !== $documentMountPath) {
73-
$sources[$document->getMimeType()] = [
74-
'mime' => $document->getMimeType(),
73+
$documentMimeType = $document->getMimeType();
74+
if (null !== $documentMountPath && null !== $documentMimeType) {
75+
$sources[$documentMimeType] = [
76+
'mime' => $documentMimeType,
7577
'url' => $this->documentsStorage->publicUrl($documentMountPath),
7678
];
7779
}

src/Renderer/ChainRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(array $renderers)
1919
* @var RendererInterface $renderer
2020
*/
2121
foreach ($renderers as $renderer) {
22-
if (!($renderer instanceof RendererInterface)) {
22+
if (!$renderer instanceof RendererInterface) {
2323
throw new \InvalidArgumentException('Document Renderer must implement RendererInterface');
2424
}
2525
}

src/Renderer/EmbedRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public function supports(BaseDocumentInterface $document, array $options): bool
2424
&& true === $options['embed']
2525
) {
2626
return true;
27-
} else {
28-
return false;
2927
}
28+
29+
return false;
3030
}
3131

3232
#[\Override]

0 commit comments

Comments
 (0)