Skip to content

Commit

Permalink
Rector
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Dec 7, 2024
1 parent 2b970e8 commit 79525d3
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/Command/AddMassMediaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$readHeaders = false;

while (!feof($fp)) {
$data = fgetcsv($fp, 0, $delimiter, $enclosure, $escape);
$data = fgetcsv($fp, 0, $delimiter, $enclosure, (string) $escape);

if (!\is_array($data)) {
continue;
Expand Down
5 changes: 1 addition & 4 deletions src/Filesystem/Replicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@

final class Replicate implements Adapter, FileFactory, StreamFactory, MetadataSupporter
{
private LoggerInterface $logger;

public function __construct(
private Adapter $primary,
private Adapter $secondary,
?LoggerInterface $logger = null,
private LoggerInterface $logger = new NullLogger()
) {
$this->logger = $logger ?? new NullLogger();
}

public function delete($key): bool
Expand Down
5 changes: 1 addition & 4 deletions src/Metadata/AmazonMetadataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,15 @@ final class AmazonMetadataBuilder implements MetadataBuilderInterface
'reduced' => self::STORAGE_REDUCED,
];

private MimeTypesInterface $mimeTypes;

/**
* @param array<string, mixed> $settings
*
* @phpstan-param AmazonSettings $settings
*/
public function __construct(
private array $settings,
?MimeTypesInterface $mimeTypes = null,
private MimeTypesInterface $mimeTypes = new MimeTypes()
) {
$this->mimeTypes = $mimeTypes ?? new MimeTypes();
}

public function get(MediaInterface $media, string $filename): array
Expand Down
9 changes: 1 addition & 8 deletions src/Model/NoDriverGalleryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,9 @@ public function getTableName(): string
}

/**
* Do not add return typehint to this method, it forces a dependency with
* Doctrine DBAL that we do not want here. This method will probably be
* deprecated on sonata-project/doctrine-extensions because it is only for
* Doctrine ORM.
*
* TODO: Remove this with the drop of sonata-project/doctrine-extensions < 2.
*
* @psalm-suppress MissingReturnType
*/
public function getConnection() // @phpstan-ignore-line
public function getConnection(): never
{
throw new NoDriverException();
}
Expand Down
9 changes: 1 addition & 8 deletions src/Model/NoDriverMediaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,9 @@ public function getTableName(): string
}

/**
* Do not add return typehint to this method, it forces a dependency with
* Doctrine DBAL that we do not want here. This method will probably be
* deprecated on sonata-project/doctrine-extensions because it is only for
* Doctrine ORM.
*
* TODO: Remove this with the drop of sonata-project/doctrine-extensions < 2.
*
* @psalm-suppress MissingReturnType
*/
public function getConnection() // @phpstan-ignore-line
public function getConnection(): never
{
throw new NoDriverException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/DailyMotionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private function fixBinaryContent(MediaInterface $media): void
return;
}

if (1 === preg_match('{^(?:https?://)?www.dailymotion.com/video/(?<video_id>[0-9a-zA-Z]*)}', $media->getBinaryContent(), $matches)) {
if (1 === preg_match('{^(?:https?://)?www.dailymotion.com/video/(?<video_id>[0-9a-zA-Z]*)}', (string) $media->getBinaryContent(), $matches)) {
$media->setBinaryContent($matches['video_id']);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/FileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function validate(ErrorElement $errorElement, MediaInterface $media): voi

if (
'' !== $media->getBinaryContent()->getFilename()
&& !\in_array(strtolower($media->getBinaryContent()->getMimeType()), $this->allowedMimeTypes, true)
&& !\in_array(strtolower((string) $media->getBinaryContent()->getMimeType()), $this->allowedMimeTypes, true)
) {
$errorElement
->with('binaryContent')
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/VimeoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected function fixBinaryContent(MediaInterface $media): void
return;
}

if (1 === preg_match('{vimeo\.com/(?:video/|)(?<video_id>\d+)}', $media->getBinaryContent(), $matches)) {
if (1 === preg_match('{vimeo\.com/(?:video/|)(?<video_id>\d+)}', (string) $media->getBinaryContent(), $matches)) {
$media->setBinaryContent($matches['video_id']);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/YouTubeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ private function fixBinaryContent(MediaInterface $media): void
return;
}

if (11 === \strlen($media->getBinaryContent())) {
if (11 === \strlen((string) $media->getBinaryContent())) {
return;
}

if (1 === preg_match(
'{^(?:https?://)?(?:www\.)?(?:m\.)?(?:youtu\.be/|youtube\.com/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)/))(?<video_id>[^\#\?&\'>]+)}',
$media->getBinaryContent(),
(string) $media->getBinaryContent(),
$matches
)) {
$media->setBinaryContent($matches['video_id']);
Expand Down

0 comments on commit 79525d3

Please sign in to comment.