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 e64ece7 commit a413361
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Command/MultipleOpencastHostImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions Command/OpencastDeleteEmptyPersonalSeriesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private function checkOpencastStatus()

private function getSeries()
{
$criteria = [];
$criteria['properties.opencast'] = ['$exists' => true];

if ($this->id) {
Expand All @@ -161,7 +162,7 @@ private function deleteSeries($series)
'',
'<info> **** Sync Series **** </info>',
'',
'<comment> ----- Total: </comment>'.count($series),
'<comment> ----- Total: </comment>'.(is_countable($series) ? count($series) : 0),
]
);

Expand All @@ -184,7 +185,7 @@ private function showSeries($series)
'',
'<info> **** Finding Series **** </info>',
'',
'<comment> ----- Total: </comment>'.count($series),
'<comment> ----- Total: </comment>'.(is_countable($series) ? count($series) : 0),
]
);

Expand Down
2 changes: 1 addition & 1 deletion Command/OpencastSingleImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions Command/OpencastStopWorkflowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$result = $this->opencastWorkflowService->stopSucceededWorkflows($mediaPackageId);
if (!$result) {
$output->writeln('<error>Error on stopping workflows</error>');
$this->logger->error('['.__CLASS__.']('.__FUNCTION__.') Error on stopping workflows');
$this->logger->error('['.self::class.']('.__FUNCTION__.') Error on stopping workflows');

return -1;
}
$output->writeln('<info>Successfully stopped workflows</info>');
$this->logger->info('['.__CLASS__.']('.__FUNCTION__.') Successfully stopped workflows');
$this->logger->info('['.self::class.']('.__FUNCTION__.') Successfully stopped workflows');
} else {
$output->writeln('<info>Not allowed to stop workflows</info>');
$this->logger->warning('['.__CLASS__.']('.__FUNCTION__.') Not allowed to stop workflows');
$this->logger->warning('['.self::class.']('.__FUNCTION__.') Not allowed to stop workflows');
}

return 1;
Expand All @@ -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>Error on getCountedWorkflowInstances</error>');
$this->logger->error('['.__CLASS__.']('.__FUNCTION__.') Error on getCountedWorkflowInstances');
$this->logger->error('['.self::class.']('.__FUNCTION__.') Error on getCountedWorkflowInstances');

return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions Command/OpencastSyncSeriesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private function checkOpencastStatus(): bool

private function getSeries()
{
$criteria = [];
$criteria['properties.opencast'] = ['$exists' => true];

if ($this->id) {
Expand All @@ -160,7 +161,7 @@ private function syncSeries($series): void
'',
'<info> **** Sync Series **** </info>',
'',
'<comment> ----- Total: </comment>'.count($series),
'<comment> ----- Total: </comment>'.(is_countable($series) ? count($series) : 0),
]
);

Expand All @@ -180,7 +181,7 @@ private function showSeries($series): void
'',
'<info> **** Finding Series **** </info>',
'',
'<comment> ----- Total: </comment>'.count($series),
'<comment> ----- Total: </comment>'.(is_countable($series) ? count($series) : 0),
]
);

Expand Down
2 changes: 1 addition & 1 deletion Controller/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/PumukitOpencastExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 13 additions & 11 deletions Services/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');

Expand Down Expand Up @@ -294,7 +294,8 @@ public function applyWorkflowToMediaPackages(array $mediaPackagesIds = [], strin
'workflow' => $workflowName,
'configuration' => $configurationParameters,
'eventIds' => $mediaPackagesIds,
]
],
JSON_THROW_ON_ERROR
),
];
// DEFAULT
Expand All @@ -308,7 +309,8 @@ public function applyWorkflowToMediaPackages(array $mediaPackagesIds = [], strin
[
'workflow' => $workflowName,
'configuration' => $configurationsById,
]
],
JSON_THROW_ON_ERROR
),
];
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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.'.');
Expand Down Expand Up @@ -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);
}
Expand All @@ -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');
}
Expand All @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions Services/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions Services/OpencastImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Services/SeriesSyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a413361

Please sign in to comment.