From a413361103af9441796612ae50b62a80b2001880 Mon Sep 17 00:00:00 2001 From: Pablo Ogando Ferreira Date: Mon, 16 Oct 2023 10:42:34 +0200 Subject: [PATCH] PHPRector --- Command/MultipleOpencastHostImportCommand.php | 2 +- ...encastDeleteEmptyPersonalSeriesCommand.php | 5 ++-- Command/OpencastSingleImportCommand.php | 2 +- Command/OpencastStopWorkflowCommand.php | 8 +++---- Command/OpencastSyncSeriesCommand.php | 5 ++-- Controller/ImportController.php | 2 +- .../PumukitOpencastExtension.php | 2 +- Services/ClientService.php | 24 ++++++++++--------- Services/NotificationService.php | 4 ++-- Services/OpencastImportService.php | 6 ++--- Services/SeriesSyncService.php | 2 +- 11 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Command/MultipleOpencastHostImportCommand.php b/Command/MultipleOpencastHostImportCommand.php index b33a14f..1787b11 100644 --- a/Command/MultipleOpencastHostImportCommand.php +++ b/Command/MultipleOpencastHostImportCommand.php @@ -277,7 +277,7 @@ private function showMessage(OutputInterface $output, MultimediaObject $multimed $tracks = $this->opencastImportService->getMediaPackageField($media, 'track'); $tracksCount = 1; if (isset($tracks[0])) { - $tracksCount = count($tracks); + $tracksCount = is_countable($tracks) ? count($tracks) : 0; } $output->writeln(' Multimedia Object: '.$multimediaObject->getId().' - URL: '.$multimediaObject->getProperty('opencasturl').' - Tracks: '.$tracksCount); diff --git a/Command/OpencastDeleteEmptyPersonalSeriesCommand.php b/Command/OpencastDeleteEmptyPersonalSeriesCommand.php index a7203fc..4d31eb3 100644 --- a/Command/OpencastDeleteEmptyPersonalSeriesCommand.php +++ b/Command/OpencastDeleteEmptyPersonalSeriesCommand.php @@ -140,6 +140,7 @@ private function checkOpencastStatus() private function getSeries() { + $criteria = []; $criteria['properties.opencast'] = ['$exists' => true]; if ($this->id) { @@ -161,7 +162,7 @@ private function deleteSeries($series) '', ' **** Sync Series **** ', '', - ' ----- Total: '.count($series), + ' ----- Total: '.(is_countable($series) ? count($series) : 0), ] ); @@ -184,7 +185,7 @@ private function showSeries($series) '', ' **** Finding Series **** ', '', - ' ----- Total: '.count($series), + ' ----- Total: '.(is_countable($series) ? count($series) : 0), ] ); diff --git a/Command/OpencastSingleImportCommand.php b/Command/OpencastSingleImportCommand.php index 54f7568..1e4ebf6 100644 --- a/Command/OpencastSingleImportCommand.php +++ b/Command/OpencastSingleImportCommand.php @@ -93,7 +93,7 @@ protected function completeMultimediaObject(MultimediaObject $multimediaObject, $tracks = $this->opencastImportService->getMediaPackageField($media, 'track'); if (isset($tracks[0])) { // NOTE: Multiple tracks - $limit = count($tracks); + $limit = is_countable($tracks) ? count($tracks) : 0; for ($i = 0; $i < $limit; ++$i) { $this->opencastImportService->createTrackFromMediaPackage($mediaPackage, $multimediaObject, $i, ['display'], $language); } diff --git a/Command/OpencastStopWorkflowCommand.php b/Command/OpencastStopWorkflowCommand.php index dd59037..bffa4da 100644 --- a/Command/OpencastStopWorkflowCommand.php +++ b/Command/OpencastStopWorkflowCommand.php @@ -59,15 +59,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int $result = $this->opencastWorkflowService->stopSucceededWorkflows($mediaPackageId); if (!$result) { $output->writeln('Error on stopping workflows'); - $this->logger->error('['.__CLASS__.']('.__FUNCTION__.') Error on stopping workflows'); + $this->logger->error('['.self::class.']('.__FUNCTION__.') Error on stopping workflows'); return -1; } $output->writeln('Successfully stopped workflows'); - $this->logger->info('['.__CLASS__.']('.__FUNCTION__.') Successfully stopped workflows'); + $this->logger->info('['.self::class.']('.__FUNCTION__.') Successfully stopped workflows'); } else { $output->writeln('Not allowed to stop workflows'); - $this->logger->warning('['.__CLASS__.']('.__FUNCTION__.') Not allowed to stop workflows'); + $this->logger->warning('['.self::class.']('.__FUNCTION__.') Not allowed to stop workflows'); } return 1; @@ -89,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $decode = $this->opencastClientService->getCountedWorkflowInstances('', $total, $workflowName); if (!isset($decode['workflows']['workflow'])) { $output->writeln('Error on getCountedWorkflowInstances'); - $this->logger->error('['.__CLASS__.']('.__FUNCTION__.') Error on getCountedWorkflowInstances'); + $this->logger->error('['.self::class.']('.__FUNCTION__.') Error on getCountedWorkflowInstances'); return 0; } diff --git a/Command/OpencastSyncSeriesCommand.php b/Command/OpencastSyncSeriesCommand.php index 563d4ca..222fa69 100644 --- a/Command/OpencastSyncSeriesCommand.php +++ b/Command/OpencastSyncSeriesCommand.php @@ -144,6 +144,7 @@ private function checkOpencastStatus(): bool private function getSeries() { + $criteria = []; $criteria['properties.opencast'] = ['$exists' => true]; if ($this->id) { @@ -160,7 +161,7 @@ private function syncSeries($series): void '', ' **** Sync Series **** ', '', - ' ----- Total: '.count($series), + ' ----- Total: '.(is_countable($series) ? count($series) : 0), ] ); @@ -180,7 +181,7 @@ private function showSeries($series): void '', ' **** Finding Series **** ', '', - ' ----- Total: '.count($series), + ' ----- Total: '.(is_countable($series) ? count($series) : 0), ] ); diff --git a/Controller/ImportController.php b/Controller/ImportController.php index 037a867..803f47c 100644 --- a/Controller/ImportController.php +++ b/Controller/ImportController.php @@ -31,7 +31,7 @@ public function __construct(DocumentManager $documentManager, OpencastImportServ */ public function eventAction(Request $request): Response { - $mediaPackage = json_decode($request->request->get('mediapackage'), true); + $mediaPackage = json_decode($request->request->get('mediapackage'), true, 512, JSON_THROW_ON_ERROR); if (!isset($mediaPackage['mediapackage']['id'])) { $this->get('logger')->warning('No mediapackage ID, ERROR 400 returned'); diff --git a/DependencyInjection/PumukitOpencastExtension.php b/DependencyInjection/PumukitOpencastExtension.php index eb81a3d..b0fb83c 100644 --- a/DependencyInjection/PumukitOpencastExtension.php +++ b/DependencyInjection/PumukitOpencastExtension.php @@ -24,7 +24,7 @@ public function load(array $configs, ContainerBuilder $container): void $container->setParameter('pumukit_opencast.seconds_to_sleep_on_commands', $config['seconds_to_sleep_on_commands']); $container->setParameter('pumukit_opencast.sbs', $config['sbs']); - $container->setParameter('pumukit_opencast.sbs.generate_sbs', $config['sbs']['generate_sbs'] ? $config['sbs']['generate_sbs'] : false); + $container->setParameter('pumukit_opencast.sbs.generate_sbs', $config['sbs']['generate_sbs'] ?: false); $container->setParameter('pumukit_opencast.sbs.profile', $config['sbs']['generate_sbs'] ? $config['sbs']['profile'] : null); $container->setParameter('pumukit_opencast.sbs.use_flavour', $config['sbs']['generate_sbs'] ? $config['sbs']['use_flavour'] : false); $container->setParameter('pumukit_opencast.sbs.flavour', $config['sbs']['use_flavour'] ? $config['sbs']['flavour'] : null); diff --git a/Services/ClientService.php b/Services/ClientService.php index b324ee2..5979b36 100644 --- a/Services/ClientService.php +++ b/Services/ClientService.php @@ -47,7 +47,7 @@ public function __construct( $this->logger = $logger; if (!function_exists('curl_init')) { - $this->logger->error(__CLASS__.'['.__FUNCTION__.'](line '.__LINE__ + $this->logger->error(self::class.'['.__FUNCTION__.'](line '.__LINE__ .') The function "curl_init" does not exist. ' .'Curl is required to execute remote commands.'); @@ -294,7 +294,8 @@ public function applyWorkflowToMediaPackages(array $mediaPackagesIds = [], strin 'workflow' => $workflowName, 'configuration' => $configurationParameters, 'eventIds' => $mediaPackagesIds, - ] + ], + JSON_THROW_ON_ERROR ), ]; // DEFAULT @@ -308,7 +309,8 @@ public function applyWorkflowToMediaPackages(array $mediaPackagesIds = [], strin [ 'workflow' => $workflowName, 'configuration' => $configurationsById, - ] + ], + JSON_THROW_ON_ERROR ), ]; } @@ -319,7 +321,7 @@ public function applyWorkflowToMediaPackages(array $mediaPackagesIds = [], strin Response::HTTP_CREATED, Response::HTTP_NO_CONTENT, ], true)) { - $this->logger->error(__CLASS__.'['.__FUNCTION__.'](line '.__LINE__.') Opencast error. Status != 204. - error: '.$output['error'].' - var: '.$output['var'].' - status: '.$output['status'].' - params:'.json_encode($parameters)); + $this->logger->error(self::class.'['.__FUNCTION__.'](line '.__LINE__.') Opencast error. Status != 204. - error: '.$output['error'].' - var: '.$output['var'].' - status: '.$output['status'].' - params:'.json_encode($parameters, JSON_THROW_ON_ERROR)); return false; } @@ -577,7 +579,7 @@ public function removeEvent(string $id): void Response::HTTP_ACCEPTED, Response::HTTP_NO_CONTENT, ], true)) { - $this->logger->error(__CLASS__.'['.__FUNCTION__.'](line '.__LINE__.') Opencast error. Status != 204. - error: '.$output['error'].' - var: '.$output['var'].' - status: '.$output['status']); + $this->logger->error(self::class.'['.__FUNCTION__.'](line '.__LINE__.') Opencast error. Status != 204. - error: '.$output['error'].' - var: '.$output['var'].' - status: '.$output['status']); throw new \Exception("Can't access to api/events"); } @@ -638,13 +640,13 @@ private function request(string $path, $params = [], string $method = 'GET', boo $header = ['X-Requested-Auth: Digest', 'X-Opencast-Matterhorn-Authorization: true', ]; - $this->logger->debug(__CLASS__.'['.__FUNCTION__.'](line '.__LINE__ + $this->logger->debug(self::class.'['.__FUNCTION__.'](line '.__LINE__ .') Requested URL "'.$requestUrl.'" ' .'with method "'.$method.'" ' .'and params: '.$fields); if (false === $request = curl_init($requestUrl)) { - $this->logger->error(__CLASS__.'['.__FUNCTION__.'](line '.__LINE__ + $this->logger->error(self::class.'['.__FUNCTION__.'](line '.__LINE__ .') Unable to create a new curl handle with URL: '.$requestUrl.'.'); throw new \RuntimeException('Unable to create a new curl handle with URL: '.$requestUrl.'.'); @@ -701,7 +703,7 @@ private function request(string $path, $params = [], string $method = 'GET', boo curl_close($request); if (('GET' === $method) && Response::HTTP_OK !== (int) $output['status']) { - $this->logger->error(__CLASS__.'['.__FUNCTION__.'](line '.__LINE__.') Error '.$output['error'].' Status '.$output['status'].' Processing Request : '.$requestUrl.'.'); + $this->logger->error(self::class.'['.__FUNCTION__.'](line '.__LINE__.') Error '.$output['error'].' Status '.$output['status'].' Processing Request : '.$requestUrl.'.'); throw new \Exception(sprintf('Error "%s", Status %s, Processing Request "%s"', $output['error'], $output['status'], $requestUrl), 1); } @@ -711,7 +713,7 @@ private function request(string $path, $params = [], string $method = 'GET', boo private function decodeJson(string $jsonString = ''): array { - $decode = json_decode($jsonString, true); + $decode = json_decode($jsonString, true, 512, JSON_THROW_ON_ERROR); if (!is_array($decode)) { throw new \Exception('Opencast communication error'); } @@ -724,8 +726,8 @@ private function decodeXML(array $xmlString = []): array $decode = null; if (is_array($xmlString)) { $xml = simplexml_load_string($xmlString['var'], 'SimpleXMLElement', LIBXML_NOCDATA); - $json = json_encode($xml); - $decode = json_decode($json, true); + $json = json_encode($xml, JSON_THROW_ON_ERROR); + $decode = json_decode($json, true, 512, JSON_THROW_ON_ERROR); } if (!is_array($decode)) { diff --git a/Services/NotificationService.php b/Services/NotificationService.php index 35f135f..0d65b0d 100644 --- a/Services/NotificationService.php +++ b/Services/NotificationService.php @@ -43,7 +43,7 @@ public function onImportSuccess(ImportEvent $event): void foreach ($multimediaObject->getPeopleByRoleCod('owner', true) as $person) { $owner = $this->dm->getRepository(User::class)->findOneBy(['person' => $person->getId()]); if (!$owner) { - $this->logger->error(__CLASS__.'['.__FUNCTION__.'] Person ('.$person->getId().') assigned as owner of multimediaObject ('.$multimediaObject->getId().') does NOT have an associated USER!'); + $this->logger->error(self::class.'['.__FUNCTION__.'] Person ('.$person->getId().') assigned as owner of multimediaObject ('.$multimediaObject->getId().') does NOT have an associated USER!'); continue; } @@ -65,7 +65,7 @@ public function onImportSuccess(ImportEvent $event): void UrlGeneratorInterface::ABSOLUTE_URL ); } catch (RouteNotFoundException $e) { - $this->logger->info(__CLASS__.'['.__FUNCTION__.'] Route name "'.$backofficeUrl.'" not found. Using as route literally.'); + $this->logger->info(self::class.'['.__FUNCTION__.'] Route name "'.$backofficeUrl.'" not found. Using as route literally.'); } $parameters = [ 'url' => $backofficeUrl, diff --git a/Services/OpencastImportService.php b/Services/OpencastImportService.php index e81336f..3fb446e 100644 --- a/Services/OpencastImportService.php +++ b/Services/OpencastImportService.php @@ -158,7 +158,7 @@ public function importRecordingFromMediaPackage(array $mediaPackage, ?bool $inve foreach ($this->otherLocales as $locale) { $multimediaObject->setTitle($title, $locale); } - } elseif (count($multimediaObject->getTracks()) > 0) { + } elseif ((is_countable($multimediaObject->getTracks()) ? count($multimediaObject->getTracks()) : 0) > 0) { $newMultimediaObject = $this->factoryService->cloneMultimediaObject($multimediaObject, $multimediaObject->getSeries(), false); $newMultimediaObject->setStatus($multimediaObject->getStatus()); @@ -261,7 +261,7 @@ public function getOpencastUrls($opencastId = ''): array $tracks = $this->getMediaPackageField($media, 'track'); if (!isset($tracks['id'])) { // NOTE: Multiple tracks - $limit = count($tracks); + $limit = is_countable($tracks) ? count($tracks) : 0; for ($i = 0; $i < $limit; ++$i) { $track = $tracks[$i]; $opencastUrls = $this->addOpencastUrl($opencastUrls, $track); @@ -482,7 +482,7 @@ private function addPicFromAttachment(MultimediaObject $multimediaObject, $attac $type = $this->getMediaPackageField($attachment, 'type'); $url = $this->getMediaPackageField($attachment, 'url'); if (!$url) { - $this->logger->error(__CLASS__.'['.__FUNCTION__.'] No url on pic attachment '.json_encode($attachment)); + $this->logger->error(self::class.'['.__FUNCTION__.'] No url on pic attachment '.json_encode($attachment, JSON_THROW_ON_ERROR)); return $multimediaObject; } diff --git a/Services/SeriesSyncService.php b/Services/SeriesSyncService.php index 71cf391..7bad1e4 100644 --- a/Services/SeriesSyncService.php +++ b/Services/SeriesSyncService.php @@ -37,7 +37,7 @@ public function createSeries(Series $series): void return; } - $seriesOpencastId = json_decode($output['var'], true)['identifier']; + $seriesOpencastId = json_decode($output['var'], true, 512, JSON_THROW_ON_ERROR)['identifier']; $series->setProperty('opencast', $seriesOpencastId); $this->dm->persist($series); $this->dm->flush();