Skip to content

Commit 45cd03f

Browse files
author
roadiz-ci
committed
chore: Bumped
1 parent 7bba229 commit 45cd03f

88 files changed

Lines changed: 1062 additions & 1864 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/run-test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
php-version: ['8.1', '8.2', '8.3']
22+
php-version: ['8.2', '8.3']
2323
steps:
2424
- uses: shivammathur/setup-php@v2
2525
with:
@@ -37,7 +37,5 @@ jobs:
3737
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
3838
- name: Run Unit tests
3939
run: vendor/bin/phpunit -v --whitelist ./src tests
40-
- name: Run PHP Code Sniffer
41-
run: vendor/bin/phpcs -p ./src
4240
- name: Run PHPStan
4341
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon

composer.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=8.1",
21+
"php": ">=8.2",
2222
"ext-json": "*",
2323
"ext-gd": "*",
2424
"ext-dom": "*",
2525
"ext-zip": "*",
2626
"ext-simplexml": "*",
2727
"ext-fileinfo": "*",
28-
"doctrine/orm": "~2.19.0",
28+
"doctrine/orm": "~2.20.0",
2929
"enshrined/svg-sanitize": "^0.15",
30-
"guzzlehttp/guzzle": "^7.2.0",
31-
"guzzlehttp/psr7": "^2.0",
3230
"intervention/image": "^2.5",
3331
"league/flysystem": "^3.0",
3432
"monolog/monolog": "^1.24.0 || ^2.1.1",
@@ -38,17 +36,19 @@
3836
"symfony/filesystem": "6.4.*",
3937
"symfony/finder": "6.4.*",
4038
"symfony/http-foundation": "6.4.*",
39+
"symfony/http-client-contracts": "^3.5",
4140
"symfony/options-resolver": "6.4.*",
4241
"symfony/serializer": "6.4.*",
43-
"twig/twig": "^3.1"
42+
"twig/twig": "^3.16"
4443
},
4544
"require-dev": {
45+
"api-platform/metadata": "~3.3.11",
46+
"doctrine/doctrine-bundle": "^2.8.1",
4647
"php-coveralls/php-coveralls": "^2.4",
47-
"phpunit/phpunit": "^9.5",
48-
"api-platform/metadata": "^3.2.12",
49-
"squizlabs/php_codesniffer": "^3.5",
5048
"phpstan/phpstan": "^1.5.3",
51-
"phpstan/phpstan-doctrine": "^1.3"
49+
"phpstan/phpdoc-parser": "<2",
50+
"phpstan/phpstan-doctrine": "^1.3",
51+
"phpunit/phpunit": "^9.5"
5252
},
5353
"autoload": {
5454
"psr-4": {
@@ -68,8 +68,8 @@
6868
},
6969
"extra": {
7070
"branch-alias": {
71-
"dev-master": "2.3.x-dev",
72-
"dev-develop": "2.4.x-dev"
71+
"dev-master": "2.4.x-dev",
72+
"dev-develop": "2.5.x-dev"
7373
}
7474
}
7575
}

phpcs.xml.dist

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/AbstractDocumentFactory.php

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class AbstractDocumentFactory
3232
public function __construct(
3333
FilesystemOperator $documentsStorage,
3434
DocumentFinderInterface $documentFinder,
35-
?LoggerInterface $logger = null
35+
?LoggerInterface $logger = null,
3636
) {
3737
if (!$documentsStorage instanceof MountManager) {
3838
trigger_error('Document Storage must be a MountManager to address public and private files.', E_USER_WARNING);
@@ -42,69 +42,56 @@ public function __construct(
4242
$this->logger = $logger ?? new NullLogger();
4343
}
4444

45-
/**
46-
* @return File
47-
*/
4845
public function getFile(): File
4946
{
5047
if (null === $this->file) {
5148
throw new \BadMethodCallException('File should be defined before using it.');
5249
}
50+
5351
return $this->file;
5452
}
5553

5654
/**
57-
* @param File $file
5855
* @return $this
5956
*/
6057
public function setFile(File $file): static
6158
{
6259
$this->file = $file;
60+
6361
return $this;
6462
}
6563

66-
/**
67-
* @return FolderInterface|null
68-
*/
6964
public function getFolder(): ?FolderInterface
7065
{
7166
return $this->folder;
7267
}
7368

7469
/**
75-
* @param FolderInterface|null $folder
7670
* @return $this
7771
*/
7872
public function setFolder(?FolderInterface $folder = null): static
7973
{
8074
$this->folder = $folder;
75+
8176
return $this;
8277
}
8378

8479
/**
8580
* Special case for SVG without XML statement.
86-
*
87-
* @param DocumentInterface $document
8881
*/
8982
protected function parseSvgMimeType(DocumentInterface $document): void
9083
{
9184
if (
92-
($document->getMimeType() === 'text/plain' || $document->getMimeType() === 'text/html') &&
93-
preg_match('#\.svg$#', $document->getFilename())
85+
('text/plain' === $document->getMimeType() || 'text/html' === $document->getMimeType())
86+
&& preg_match('#\.svg$#', $document->getFilename())
9487
) {
9588
$this->logger->debug('Uploaded a SVG without xml declaration. Presuming it’s a valid SVG file.');
9689
$document->setMimeType('image/svg+xml');
9790
}
9891
}
9992

100-
/**
101-
* @return DocumentInterface
102-
*/
10393
abstract protected function createDocument(): DocumentInterface;
10494

105-
/**
106-
* @param DocumentInterface $document
107-
*/
10895
abstract protected function persistDocument(DocumentInterface $document): void;
10996

11097
protected function getHashAlgorithm(): string
@@ -116,14 +103,14 @@ protected function getHashAlgorithm(): string
116103
* Create a document from UploadedFile, Be careful, this method does not flush, only
117104
* persists current Document.
118105
*
119-
* @param bool $allowEmpty Default false, requires a local file to create new document entity
106+
* @param bool $allowEmpty Default false, requires a local file to create new document entity
120107
* @param bool $allowDuplicates Default false, always import new document even if file already exists
121-
* @return null|DocumentInterface
108+
*
122109
* @throws FilesystemException
123110
*/
124111
public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = false): ?DocumentInterface
125112
{
126-
if ($allowEmpty === false) {
113+
if (false === $allowEmpty) {
127114
// Getter throw exception on null file
128115
$file = $this->getFile();
129116
} else {
@@ -147,8 +134,8 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
147134
$existingDocument = $this->documentFinder->findOneByHashAndAlgorithm($fileHash, $this->getHashAlgorithm());
148135
if (null !== $existingDocument) {
149136
if (
150-
$existingDocument->isRaw() &&
151-
null !== $existingDownscaledDocument = $existingDocument->getDownscaledDocument()
137+
$existingDocument->isRaw()
138+
&& null !== $existingDownscaledDocument = $existingDocument->getDownscaledDocument()
152139
) {
153140
$existingDocument = $existingDownscaledDocument;
154141
}
@@ -160,6 +147,7 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
160147
'File %s already exists with same checksum, do not upload it twice.',
161148
$existingDocument->getFilename()
162149
));
150+
163151
return $existingDocument;
164152
}
165153
}
@@ -175,8 +163,8 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
175163
$this->parseSvgMimeType($document);
176164

177165
if (
178-
$document instanceof FileHashInterface &&
179-
false !== $fileHash
166+
$document instanceof FileHashInterface
167+
&& false !== $fileHash
180168
) {
181169
$document->setFileHash($fileHash);
182170
$document->setFileHashAlgorithm($this->getHashAlgorithm());
@@ -196,8 +184,6 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
196184
/**
197185
* Updates a document from UploadedFile, Be careful, this method does not flush.
198186
*
199-
* @param DocumentInterface $document
200-
* @return DocumentInterface
201187
* @throws FilesystemException
202188
*/
203189
public function updateDocument(DocumentInterface $document): DocumentInterface
@@ -231,7 +217,7 @@ public function updateDocument(DocumentInterface $document): DocumentInterface
231217
}
232218
}
233219

234-
$document->setFolder(\mb_substr(hash("crc32b", date('YmdHi')), 0, 12));
220+
$document->setFolder(\mb_substr(hash('crc32b', date('YmdHi')), 0, 12));
235221
}
236222

237223
$document->setFilename($this->getFileName());
@@ -247,9 +233,6 @@ public function updateDocument(DocumentInterface $document): DocumentInterface
247233
}
248234

249235
/**
250-
* @param File $localFile
251-
* @param DocumentInterface $document
252-
* @return void
253236
* @throws FilesystemException
254237
*/
255238
public function moveFile(File $localFile, DocumentInterface $document): void
@@ -267,9 +250,6 @@ public function moveFile(File $localFile, DocumentInterface $document): void
267250
}
268251
}
269252

270-
/**
271-
* @return string
272-
*/
273253
protected function getFileName(): string
274254
{
275255
$file = $this->getFile();
@@ -278,8 +258,8 @@ protected function getFileName(): string
278258
$fileName = $file->getClientOriginalName();
279259
} elseif (
280260
$file instanceof DownloadedFile
281-
&& $file->getOriginalFilename() !== null
282-
&& $file->getOriginalFilename() !== ''
261+
&& null !== $file->getOriginalFilename()
262+
&& '' !== $file->getOriginalFilename()
283263
) {
284264
$fileName = $file->getOriginalFilename();
285265
} else {
@@ -292,9 +272,6 @@ protected function getFileName(): string
292272
/**
293273
* Create a Document from an external URL.
294274
*
295-
* @param string $downloadUrl
296-
*
297-
* @return DocumentInterface|null
298275
* @throws FilesystemException
299276
*/
300277
public function getDocumentFromUrl(string $downloadUrl): ?DocumentInterface
@@ -303,6 +280,7 @@ public function getDocumentFromUrl(string $downloadUrl): ?DocumentInterface
303280
if (null !== $downloadedFile) {
304281
return $this->setFile($downloadedFile)->getDocument();
305282
}
283+
306284
return null;
307285
}
308286
}

src/AbstractDocumentFinder.php

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,40 @@
66

77
abstract class AbstractDocumentFinder implements DocumentFinderInterface
88
{
9-
/**
10-
* @inheritDoc
11-
*/
129
public function findVideosWithFilename(string $fileName): iterable
1310
{
1411
$basename = pathinfo($fileName);
1512
$basename = $basename['filename'];
1613

1714
$sourcesDocsName = [
18-
$basename . '.ogg',
19-
$basename . '.ogv',
20-
$basename . '.mp4',
21-
$basename . '.mov',
22-
$basename . '.avi',
23-
$basename . '.webm',
24-
$basename . '.mkv',
15+
$basename.'.ogg',
16+
$basename.'.ogv',
17+
$basename.'.mp4',
18+
$basename.'.mov',
19+
$basename.'.avi',
20+
$basename.'.webm',
21+
$basename.'.mkv',
2522
];
2623

2724
return $this->findAllByFilenames($sourcesDocsName);
2825
}
2926

30-
/**
31-
* @inheritDoc
32-
*/
3327
public function findAudiosWithFilename(string $fileName): iterable
3428
{
3529
$basename = pathinfo($fileName);
3630
$basename = $basename['filename'];
3731

3832
$sourcesDocsName = [
39-
$basename . '.mp3',
40-
$basename . '.ogg',
41-
$basename . '.wav',
42-
$basename . '.m4a',
43-
$basename . '.aac',
33+
$basename.'.mp3',
34+
$basename.'.ogg',
35+
$basename.'.wav',
36+
$basename.'.m4a',
37+
$basename.'.aac',
4438
];
4539

4640
return $this->findAllByFilenames($sourcesDocsName);
4741
}
4842

49-
/**
50-
* @inheritDoc
51-
*/
5243
public function findPicturesWithFilename(string $fileName): iterable
5344
{
5445
$pathInfo = pathinfo($fileName);
@@ -70,7 +61,7 @@ public function findPicturesWithFilename(string $fileName): iterable
7061
$extensionsList = array_diff($extensionsList, [$currentExtension]);
7162
// list sources paths for extensions
7263
$sourcesDocsName = array_values(array_map(function ($extension) use ($basename) {
73-
return $basename . '.' . $extension;
64+
return $basename.'.'.$extension;
7465
}, $extensionsList));
7566

7667
return $this->findAllByFilenames($sourcesDocsName);

src/ArrayDocumentFinder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function __construct()
2424

2525
/**
2626
* @param array<string> $fileNames
27+
*
2728
* @return ArrayCollection<int, DocumentInterface>
2829
*/
2930
public function findAllByFilenames(array $fileNames): ArrayCollection
@@ -49,16 +50,15 @@ public function findOneByHashAndAlgorithm(string $hash, string $algorithm): ?Doc
4950
return null;
5051
}
5152

52-
5353
/**
54-
* @param DocumentInterface $document
5554
* @return $this
5655
*/
5756
public function addDocument(DocumentInterface $document): self
5857
{
5958
if (!$this->documents->contains($document)) {
6059
$this->documents->add($document);
6160
}
61+
6262
return $this;
6363
}
6464
}

0 commit comments

Comments
 (0)