Skip to content

Commit

Permalink
PHPRector
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurujai committed Oct 16, 2023
1 parent 276dd9a commit 17dd3bd
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Command/CaptionDeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$youtubeMultimediaObjects = $this->getYoutubeMultimediaObjects();

$infoLog = '[YouTube] Deleting captions for '.count($youtubeMultimediaObjects).' videos.';
$infoLog = '[YouTube] Deleting captions for '.(is_countable($youtubeMultimediaObjects) ? count($youtubeMultimediaObjects) : 0).' videos.';
$this->logger->info($infoLog);
$this->deleteCaptionsFromYoutube($youtubeMultimediaObjects);

Expand Down Expand Up @@ -123,7 +123,7 @@ private function getDeleteCaptionIds(Youtube $youtube, MultimediaObject $multime
continue;
}
$deleteCaptionIds[] = $caption->getCaptionId();
$infoLog = sprintf('%s [%s] Started deleting caption from Youtube with id %s and Caption with id %s', __CLASS__, __FUNCTION__, $youtube->getId(), $caption->getId());
$infoLog = sprintf('%s [%s] Started deleting caption from Youtube with id %s and Caption with id %s', self::class, __FUNCTION__, $youtube->getId(), $caption->getId());
$this->logger->info($infoLog);
$this->output->writeln($infoLog);
}
Expand Down
4 changes: 2 additions & 2 deletions Command/CaptionUploadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->output = $output;
$youtubeMultimediaObjects = $this->getYoutubeMultimediaObjects();
$infoLog = '[YouTube] Upload captions for '.count($youtubeMultimediaObjects).' videos.';
$infoLog = '[YouTube] Upload captions for '.(is_countable($youtubeMultimediaObjects) ? count($youtubeMultimediaObjects) : 0).' videos.';
$this->logger->info($infoLog);
$this->uploadCaptionsToYoutube($youtubeMultimediaObjects, $output);

Expand Down Expand Up @@ -123,7 +123,7 @@ private function getNewMaterialIds(MultimediaObject $multimediaObject, array $ca
continue;
}
$newMaterialIds[] = $material->getId();
$infoLog = sprintf('%s [%s] Started uploading captions to Youtube of MultimediaObject with id %s and Material with id %s', __CLASS__, __FUNCTION__, $multimediaObject->getId(), $material->getId());
$infoLog = sprintf('%s [%s] Started uploading captions to Youtube of MultimediaObject with id %s and Material with id %s', self::class, __FUNCTION__, $multimediaObject->getId(), $material->getId());
$this->logger->info($infoLog);
$this->output->writeln($infoLog);
}
Expand Down
2 changes: 1 addition & 1 deletion Command/PlaylistUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
->execute()
;

$infoLog = '[YouTube] Updating playlist for '.count($multimediaObjects).' videos.';
$infoLog = '[YouTube] Updating playlist for '.(is_countable($multimediaObjects) ? count($multimediaObjects) : 0).' videos.';
$this->logger->info($infoLog);
foreach ($multimediaObjects as $multimediaObject) {
try {
Expand Down
1 change: 1 addition & 0 deletions Command/PlaylistsErrorNotificationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$result = [];
$elements = $this->getAllPlaylistErrors();
$result['playlistUploadError'] = $elements;
$this->notificationService->notificationVideoErrorResult($result);
Expand Down
8 changes: 4 additions & 4 deletions Command/VideoDeleteCommand.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// Videos with YouTube document on PUBLISHED but status on PuMuKIT not allowed to be published
// Ex: sync_status false and status hidden or blocked.
$notPublishedMms = $this->notPublishedMultimediaObjects();
$infoLog = '[YouTube] Deleting not published videos '.count($notPublishedMms).' on YouTube';
$infoLog = '[YouTube] Deleting not published videos '.(is_countable($notPublishedMms) ? count($notPublishedMms) : 0).' on YouTube';
$this->logger->info($infoLog);
$this->deleteVideosFromYoutube($notPublishedMms, $output);

Expand All @@ -78,14 +78,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);
$publishedYoutubeIds = $this->getStringIds($youtubeMongoIds);
$notCorrectTagMms = $this->getMultimediaObjectsInYoutubeWithoutTagCodes($publishedYoutubeIds, $arrayPubTags);
$infoLog = '[YouTube] Deleting videos published on YouTube but without account/configuration to be on YouTube: '.count($notCorrectTagMms);
$infoLog = '[YouTube] Deleting videos published on YouTube but without account/configuration to be on YouTube: '.(is_countable($notCorrectTagMms) ? count($notCorrectTagMms) : 0);
$this->logger->info($infoLog);
$this->deleteVideosFromYoutube($notCorrectTagMms, $output);

// Use case:
// Videos published on YouTube but with EmbeddedBroadcast distinct of public
$notPublicMms = $this->getMultimediaObjectsInYoutubeWithoutEmbeddedBroadcast($publishedYoutubeIds, 'public');
$infoLog = '[YouTube] Deleting videos with EmbeddedBroadcast not public: '.count($notPublicMms);
$infoLog = '[YouTube] Deleting videos with EmbeddedBroadcast not public: '.(is_countable($notPublicMms) ? count($notPublicMms) : 0);
$this->logger->info($infoLog);
$this->deleteVideosFromYoutube($notPublicMms, $output);

Expand All @@ -94,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$orphanVideos = $this->documentManager->getRepository(Youtube::class)->findBy([
'status' => Youtube::STATUS_TO_DELETE,
]);
$infoLog = '[YouTube] Deleting orphan videos: '.count($notPublicMms);
$infoLog = '[YouTube] Deleting orphan videos: '.(is_countable($notPublicMms) ? count($notPublicMms) : 0);
$this->logger->info($infoLog);
$this->deleteOrphanVideosFromYoutube($orphanVideos, $output);

Expand Down
Empty file modified Command/VideoUpdateMetadataCommand.php
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion Command/VideoUpdatePendingStatusCommand.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$statusArray = [Youtube::STATUS_UPLOADING, Youtube::STATUS_PROCESSING];
$youtubeDocuments = $this->documentManager->getRepository(Youtube::class)->getWithAnyStatus($statusArray);
$infoLog = '[YouTube] Updating (pending) status for '.count($youtubeDocuments).' videos.';
$infoLog = '[YouTube] Updating (pending) status for '.(is_countable($youtubeDocuments) ? count($youtubeDocuments) : 0).' videos.';
$this->logger->info($infoLog);
$this->updateVideoStatusInYoutube($youtubeDocuments, $output);

Expand Down
2 changes: 1 addition & 1 deletion Command/VideoUpdateStatusCommand.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
];
$youtubeDocuments = $this->documentManager->getRepository(Youtube::class)->getWithoutAnyStatus($statusArray);

$infoLog = '[YouTube] Updating status for '.count($youtubeDocuments).' videos.';
$infoLog = '[YouTube] Updating status for '.(is_countable($youtubeDocuments) ? count($youtubeDocuments) : 0).' videos.';
$this->logger->info($infoLog);
$this->updateVideoStatusInYoutube($youtubeDocuments, $output);

Expand Down
6 changes: 3 additions & 3 deletions Command/VideoUploadCommand.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->usePumukit1 = $input->getOption('use-pmk1');

$newMultimediaObjects = $this->getNewMultimediaObjectsToUpload();
$infoLog = '[YouTube] Uploading '.count($newMultimediaObjects).' new videos to YouTube';
$infoLog = '[YouTube] Uploading '.(is_countable($newMultimediaObjects) ? count($newMultimediaObjects) : 0).' new videos to YouTube';
$this->logger->info($infoLog);
$this->uploadVideosToYoutube($newMultimediaObjects, $output);

$failureMultimediaObjects = $this->getUploadsByStatus([Youtube::STATUS_ERROR]);
$infoLog = '[YouTube] Uploading '.count($failureMultimediaObjects).' failure videos to YouTube';
$infoLog = '[YouTube] Uploading '.(is_countable($failureMultimediaObjects) ? count($failureMultimediaObjects) : 0).' failure videos to YouTube';
$this->logger->info($infoLog);
$this->uploadVideosToYoutube($failureMultimediaObjects, $output);

if ($this->youtubeConfigurationService->uploadRemovedVideos()) {
$removedStatus = [Youtube::STATUS_REMOVED];
$removedYoutubeMultimediaObjects = $this->getUploadsByStatus($removedStatus);
$infoLog = '[YouTube] Uploading '.count($removedYoutubeMultimediaObjects).' removed videos to YouTube';
$infoLog = '[YouTube] Uploading '.(is_countable($removedYoutubeMultimediaObjects) ? count($removedYoutubeMultimediaObjects) : 0).' removed videos to YouTube';
$this->logger->info($infoLog);
$this->uploadVideosToYoutube($removedYoutubeMultimediaObjects, $output);
}
Expand Down
2 changes: 1 addition & 1 deletion Services/CaptionsDeleteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function deleteCaption(Tag $account, Youtube $youtube, array $captionsId)
} catch (\Exception $exception) {
$errorLog = sprintf('[YouTube] Remove caption for Youtube document %s failed. Error: %s', $youtube->getId(), $exception->getMessage());
$this->logger->error($errorLog);
$error = json_decode($exception->getMessage(), true);
$error = json_decode($exception->getMessage(), true, 512, JSON_THROW_ON_ERROR);
$error = \Pumukit\YoutubeBundle\Document\Error::create(
$error['error']['errors'][0]['reason'],
$error['error']['errors'][0]['message'],
Expand Down
2 changes: 1 addition & 1 deletion Services/CaptionsInsertService.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function uploadCaption(Youtube $youtube, MultimediaObject $multimediaObje
$youtube->addCaption($caption);
$youtube->removeCaptionUpdateError();
} catch (\Exception $exception) {
$error = json_decode($exception->getMessage(), true);
$error = json_decode($exception->getMessage(), true, 512, JSON_THROW_ON_ERROR);
$error = \Pumukit\YoutubeBundle\Document\Error::create(
$error['error']['errors'][0]['reason'],
$error['error']['errors'][0]['message'],
Expand Down
6 changes: 3 additions & 3 deletions Services/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ public function sendEmail(string $cause = '', array $succeed = [], array $failed
if (0 < $output) {
if (is_array($emailTo)) {
foreach ($emailTo as $email) {
$infoLog = __CLASS__.' ['.__FUNCTION__.'] Sent notification email to "'.$email.'"';
$infoLog = self::class.' ['.__FUNCTION__.'] Sent notification email to "'.$email.'"';
$this->logger->info($infoLog);
}
} else {
$infoLog = __CLASS__.' ['.__FUNCTION__.'] Sent notification email to "'.$emailTo.'"';
$infoLog = self::class.' ['.__FUNCTION__.'] Sent notification email to "'.$emailTo.'"';
$this->logger->info($infoLog);
}
} else {
$infoLog = __CLASS__.' ['.__FUNCTION__.'] Unable to send notification email to "'.$emailTo.'", '.$output.'email(s) were sent.';
$infoLog = self::class.' ['.__FUNCTION__.'] Unable to send notification email to "'.$emailTo.'", '.$output.'email(s) were sent.';
$this->logger->info($infoLog);
}

Expand Down
4 changes: 2 additions & 2 deletions Services/PlaylistItemInsertService.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function fixPlaylistsForMultimediaObject(MultimediaObject $multimediaObj
try {
$response = $this->playlistItemDeleteService->deleteOnePlaylist($account, $playlistRel);
} catch (\Exception $exception) {
$error = json_decode($exception->getMessage(), true);
$error = json_decode($exception->getMessage(), true, 512, JSON_THROW_ON_ERROR);
$error = \Pumukit\YoutubeBundle\Document\Error::create(
$error['error']['errors'][0]['reason'],
$error['error']['errors'][0]['message'],
Expand All @@ -131,7 +131,7 @@ private function fixPlaylistsForMultimediaObject(MultimediaObject $multimediaObj
$youtubeDocument->setPlaylist($playlist, $response->getId());
$youtubeDocument->removePlaylistUpdateError();
} catch (\Exception $exception) {
$error = json_decode($exception->getMessage(), true);
$error = json_decode($exception->getMessage(), true, 512, JSON_THROW_ON_ERROR);
$error = \Pumukit\YoutubeBundle\Document\Error::create(
$error['error']['errors'][0]['reason'],
$error['error']['errors'][0]['message'],
Expand Down
8 changes: 4 additions & 4 deletions Services/VideoDataValidationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public function validateMultimediaObjectTrack(MultimediaObject $multimediaObject

$trackPath = $track->getPath();
if (!file_exists($trackPath)) {
$errorLog = __CLASS__.' ['.__FUNCTION__.'] Error, there is no file '.$trackPath;
$errorLog = self::class.' ['.__FUNCTION__.'] Error, there is no file '.$trackPath;
$this->logger->error($errorLog);

return null;
}

if (str_contains($trackPath, '.m4v')) {
$errorLog = __CLASS__.' ['.__FUNCTION__.'] Youtube not support m4v files. To upload this video to Youtube, convert to mp4.'.$trackPath;
$errorLog = self::class.' ['.__FUNCTION__.'] Youtube not support m4v files. To upload this video to Youtube, convert to mp4.'.$trackPath;
$this->logger->error($errorLog);

return null;
Expand Down Expand Up @@ -228,7 +228,7 @@ protected function generateSbsTrack(MultimediaObject $multimediaObject)
}
$track = $tracks[0];
$path = $track->getPath();
$language = $track->getLanguage() ? $track->getLanguage() : \Locale::getDefault();
$language = $track->getLanguage() ?: \Locale::getDefault();
$job = $this->jobService->addJob($path, $this->youtubeConfigurationService->sbsProfileName(), 2, $multimediaObject, $language, [], [], $track->getDuration());
}

Expand All @@ -250,7 +250,7 @@ private function hasPendingJobs(MultimediaObject $multimediaObject): bool
$multimediaObject->getId()
);

return 0 !== count($jobs);
return 0 !== (is_countable($jobs) ? count($jobs) : 0);
}

private function filterSpecialCharacters(string $value): string
Expand Down
8 changes: 4 additions & 4 deletions Services/VideoDeleteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public function deleteVideoFromYouTubeByMultimediaObject(MultimediaObject $multi
if (!$account) {
$accountLogin = $youtube->getYoutubeAccount();
if (!$accountLogin) {
$errorLog = __CLASS__.' ['.__FUNCTION__.'] Multimedia object '.$multimediaObject->getId().': doesnt have account';
$errorLog = self::class.' ['.__FUNCTION__.'] Multimedia object '.$multimediaObject->getId().': doesnt have account';
$this->logger->error($errorLog);

return false;
}
$account = $this->documentManager->getRepository(Tag::class)->findOneBy(['properties.login' => $accountLogin]);
if (!$account) {
$errorLog = __CLASS__.' ['.__FUNCTION__.'] Youtube account '.$accountLogin.' doesnt exists';
$errorLog = self::class.' ['.__FUNCTION__.'] Youtube account '.$accountLogin.' doesnt exists';
$this->logger->error($errorLog);

return false;
Expand Down Expand Up @@ -79,7 +79,7 @@ public function deleteVideoFromYouTubeByMultimediaObject(MultimediaObject $multi
return false;
}
} catch (\Exception $exception) {
$error = json_decode($exception->getMessage(), true);
$error = json_decode($exception->getMessage(), true, 512, JSON_THROW_ON_ERROR);
$error = \Pumukit\YoutubeBundle\Document\Error::create(
$error['error']['errors'][0]['reason'],
$error['error']['errors'][0]['message'],
Expand Down Expand Up @@ -133,7 +133,7 @@ public function deleteVideoFromYouTubeByYouTubeDocument(Youtube $youtube): bool
return false;
}
} catch (\Exception $exception) {
$error = json_decode($exception->getMessage(), true);
$error = json_decode($exception->getMessage(), true, 512, JSON_THROW_ON_ERROR);
$error = \Pumukit\YoutubeBundle\Document\Error::create(
$error['error']['errors'][0]['reason'],
$error['error']['errors'][0]['message'],
Expand Down
2 changes: 1 addition & 1 deletion Services/VideoInsertService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function uploadVideoToYoutube(MultimediaObject $multimediaObject): bool
} catch (\Exception $exception) {
$this->updateVideoAndYoutubeDocumentByErrorResult(
$youtubeDocument,
json_decode($exception->getMessage(), true)
json_decode($exception->getMessage(), true, 512, JSON_THROW_ON_ERROR)
);

$errorLog = '[YouTube] Multimedia object with ID ('.$multimediaObject->getId().') failed uploading to YouTube. '.$exception->getMessage();
Expand Down
4 changes: 2 additions & 2 deletions Services/VideoListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function updateVideoStatus(Youtube $youtube, MultimediaObject $multimedia
{
$infoLog = sprintf(
'%s [%s] Started update video status on MultimediaObject with id %s',
__CLASS__,
self::class,
__FUNCTION__,
$multimediaObject->getId()
);
Expand All @@ -64,7 +64,7 @@ public function updateVideoStatus(Youtube $youtube, MultimediaObject $multimedia
$response = $this->list($account, $video);
$status = $this->getStatusFromYouTubeResponse($response, $video);
} catch (\Exception $exception) {
$error = json_decode($exception->getMessage(), true);
$error = json_decode($exception->getMessage(), true, 512, JSON_THROW_ON_ERROR);
$error = \Pumukit\YoutubeBundle\Document\Error::create(
$error['error']['errors'][0]['reason'],
$error['error']['errors'][0]['message'],
Expand Down
2 changes: 1 addition & 1 deletion Services/VideoUpdateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function updateVideoOnYoutube(MultimediaObject $multimediaObject): bool
try {
$response = $this->update($account, $video);
} catch (\Exception $exception) {
$error = json_decode($exception->getMessage(), true);
$error = json_decode($exception->getMessage(), true, 512, JSON_THROW_ON_ERROR);
$error = \Pumukit\YoutubeBundle\Document\Error::create(
$error['error']['errors'][0]['reason'],
$error['error']['errors'][0]['message'],
Expand Down
6 changes: 3 additions & 3 deletions Tests/Repository/YoutubeRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function setUp(): void

public function testRepositoryEmpty()
{
$this->assertEquals(0, count($this->repo->findAll()));
$this->assertEquals(0, is_countable($this->repo->findAll()) ? count($this->repo->findAll()) : 0);
}

public function testRepository()
Expand All @@ -42,13 +42,13 @@ public function testRepository()
$this->dm->persist($youtube1);
$this->dm->flush();

$this->assertEquals(1, count($this->repo->findAll()));
$this->assertEquals(1, is_countable($this->repo->findAll()) ? count($this->repo->findAll()) : 0);

$youtube2 = new Youtube();
$this->dm->persist($youtube2);
$this->dm->flush();

$this->assertEquals(2, count($this->repo->findAll()));
$this->assertEquals(2, is_countable($this->repo->findAll()) ? count($this->repo->findAll()) : 0);
}

public function testGetWithAnyStatus()
Expand Down

0 comments on commit 17dd3bd

Please sign in to comment.