Skip to content

Commit c045609

Browse files
author
roadiz-ci
committed
Merge branch release/v2.7.0
1 parent 61125f9 commit c045609

24 files changed

Lines changed: 136 additions & 146 deletions

composer.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@
3030
"intervention/image": "^3.11",
3131
"league/flysystem": "^3.0",
3232
"monolog/monolog": "^3.9",
33-
"symfony/asset": "7.3.*",
34-
"symfony/console": "7.3.*",
35-
"symfony/event-dispatcher": "7.3.*",
33+
"symfony/asset": "7.4.*",
34+
"symfony/console": "7.4.*",
35+
"symfony/event-dispatcher": "7.4.*",
3636
"symfony/filesystem": ">=7.1",
37-
"symfony/finder": "7.3.*",
38-
"symfony/http-foundation": "7.3.*",
37+
"symfony/finder": "7.4.*",
38+
"symfony/http-foundation": "7.4.*",
3939
"symfony/http-client-contracts": "^3.5",
40-
"symfony/options-resolver": "7.3.*",
41-
"symfony/serializer": "7.3.*",
40+
"symfony/options-resolver": "7.4.*",
41+
"symfony/serializer": "7.4.*",
4242
"twig/twig": "^3.21"
4343
},
4444
"require-dev": {
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",
52-
"symfony/http-client": "7.3.*",
53-
"symfony/process": "7.3.*"
52+
"symfony/http-client": "7.4.*",
53+
"symfony/process": "7.4.*"
5454
},
5555
"autoload": {
5656
"psr-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/AbstractDocumentFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
111111
}
112112

113113
if (null === $file) {
114-
return null;
114+
$document = $this->createDocument();
115+
$this->persistDocument($document);
116+
117+
return $document;
115118
}
116119

117120
if ($file instanceof UploadedFile && !$file->isValid()) {

src/ArrayDocumentFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function findOneByHashAndAlgorithm(string $hash, string $algorithm): ?Doc
5252
/**
5353
* @return $this
5454
*/
55-
public function addDocument(DocumentInterface $document): self
55+
public function addDocument(DocumentInterface $document): static
5656
{
5757
if (!$this->documents->contains($document)) {
5858
$this->documents->add($document);

src/Console/AbstractDocumentCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function getManager(): ObjectManager
3333
/**
3434
* @return DocumentRepositoryInterface<DocumentInterface>&EntityRepository<DocumentInterface>
3535
*/
36-
protected function getDocumentRepository(): DocumentRepositoryInterface
36+
protected function getDocumentRepository(): DocumentRepositoryInterface&EntityRepository
3737
{
3838
$repository = $this->managerRegistry->getRepository(DocumentInterface::class);
3939
if (!$repository instanceof DocumentRepositoryInterface) {

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/DownscaleImageManager.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function processAndOverrideDocument(?DocumentInterface $document = null):
4141
$documentPath = $document->getMountPath();
4242
$processedImage = $this->getProcessedImage($documentPath);
4343

44-
if (null === $processedImage) {
44+
if (null === $documentPath || null === $processedImage) {
4545
return;
4646
}
4747

@@ -69,7 +69,7 @@ public function processDocumentFromExistingRaw(?DocumentInterface $document = nu
6969

7070
$processedImage = $this->getProcessedImage($documentPath);
7171

72-
if (null === $processedImage) {
72+
if (null === $documentPath || null === $processedImage) {
7373
return;
7474
}
7575

@@ -195,8 +195,13 @@ private function storeNewProcessedImage(DocumentInterface $document, ImageInterf
195195
*/
196196
private function writeNewProcessedImage(DocumentInterface $document, ImageInterface $image): void
197197
{
198+
$mountPath = $document->getMountPath();
199+
if (null === $mountPath) {
200+
return;
201+
}
202+
198203
$this->documentsStorage->write(
199-
$document->getMountPath(),
204+
$mountPath,
200205
$image->encode(new AutoEncoder(quality: 100))->toString()
201206
);
202207
}
@@ -247,7 +252,10 @@ private function updateDocumentFileHash(DocumentInterface $document): void
247252
*/
248253
private function overwriteExistingProcessedImage(DocumentInterface $document, ImageInterface $image): DocumentInterface
249254
{
250-
$this->documentsStorage->delete($document->getMountPath());
255+
if (null === $mountPath = $document->getMountPath()) {
256+
return $document;
257+
}
258+
$this->documentsStorage->delete($mountPath);
251259
$this->writeNewProcessedImage($document, $image);
252260
$this->updateDocumentImageSize($document, $image);
253261
$this->updateDocumentFileHash($document);
@@ -269,6 +277,8 @@ private function generateRawFilename(string $filename): string
269277

270278
/**
271279
* Check if a document is valid for processing.
280+
*
281+
* @phpstan-assert-if-true DocumentInterface $document
272282
*/
273283
private function isValidDocument(?DocumentInterface $document): bool
274284
{

src/MediaFinders/AbstractEmbedFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public function getKey(): ?string
368368
*
369369
* @return $this
370370
*/
371-
public function setKey(?string $key): self
371+
public function setKey(?string $key): static
372372
{
373373
$this->key = $key;
374374

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: 20 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,39 +248,36 @@ 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;
283274
}
284275

285276
/**
286277
* Return false if no local file is linked to document. i.e no filename, no folder.
278+
*
279+
* @phpstan-assert-if-true non-empty-string $this->getMountPath()
280+
* @phpstan-assert-if-true non-empty-string $this->getRelativePath()
287281
*/
288282
#[Serializer\Ignore()]
289283
public function isLocal(): bool

0 commit comments

Comments
 (0)