Skip to content

Commit 8bca58d

Browse files
committed
Minor: Format code
1 parent b716ac0 commit 8bca58d

17 files changed

Lines changed: 138 additions & 109 deletions

src/CoreBundle/AiProvider/OpenAiProvider.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,10 @@ public function generateImage(string $prompt, string $toolName, ?array $options
686686

687687
$data = json_decode((string) $raw, true);
688688
if (!\is_array($data)) {
689-
690689
return 'Error: Invalid JSON response from OpenAI.';
691690
}
692691

693692
if (!isset($data['data'][0]) || !\is_array($data['data'][0])) {
694-
695693
return 'Error: OpenAI response missing image data.';
696694
}
697695

@@ -712,7 +710,6 @@ public function generateImage(string $prompt, string $toolName, ?array $options
712710
$result['url'] = $item['url'];
713711
$result['is_base64'] = false;
714712
} else {
715-
716713
return 'Error: OpenAI response did not include image content.';
717714
}
718715

@@ -826,12 +823,10 @@ public function generateVideo(string $prompt, string $toolName, ?array $options
826823

827824
$data = json_decode($raw, true);
828825
if (!\is_array($data)) {
829-
830826
return 'Error: Invalid JSON response from OpenAI.';
831827
}
832828

833829
if (!isset($data['id']) || !\is_string($data['id']) || '' === trim($data['id'])) {
834-
835830
return 'Error: OpenAI response missing "id".';
836831
}
837832

src/CoreBundle/Controller/AbstractCourseMaintenanceController.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@
77
namespace Chamilo\CoreBundle\Controller;
88

99
use __PHP_Incomplete_Class;
10-
use Chamilo\CourseBundle\Component\CourseCopy\CommonCartridge\Builder\Cc13Capabilities;
11-
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
12-
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
1310
use Chamilo\CourseBundle\Component\CourseCopy\Course;
14-
use DateTimeInterface;
11+
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
12+
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
1513
use stdClass;
1614
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1715
use Symfony\Component\HttpFoundation\Request;
1816
use Throwable;
1917
use ZipArchive;
2018

21-
use const ARRAY_FILTER_USE_BOTH;
22-
use const DIRECTORY_SEPARATOR;
2319
use const JSON_PARTIAL_OUTPUT_ON_ERROR;
2420

2521
/**
@@ -30,7 +26,7 @@
3026
abstract class AbstractCourseMaintenanceController extends AbstractController
3127
{
3228
/**
33-
* Debug flag (true by default). Toggle via ?debug=0|1 or X-Debug: 0|1
29+
* Debug flag (true by default). Toggle via ?debug=0|1 or X-Debug: 0|1.
3430
*/
3531
protected bool $debug = true;
3632

@@ -61,7 +57,7 @@ protected function logDebug(string $message, array $context = []): void
6157
// Avoid dumping huge objects
6258
foreach ($ctx as $k => $v) {
6359
if (\is_object($v)) {
64-
$ctx[$k] = ['_object' => get_class($v)];
60+
$ctx[$k] = ['_object' => $v::class];
6561
}
6662
if (\is_array($v) && \count($v) > 2000) {
6763
$ctx[$k] = ['_array_count' => \count($v)];
@@ -94,8 +90,8 @@ protected static function getPhpUploadLimitBytes(): int
9490
};
9591
};
9692

97-
$u1 = $toBytes(ini_get('upload_max_filesize') ?: null);
98-
$u2 = $toBytes(ini_get('post_max_size') ?: null);
93+
$u1 = $toBytes(\ini_get('upload_max_filesize') ?: null);
94+
$u2 = $toBytes(\ini_get('post_max_size') ?: null);
9995

10096
if ($u1 <= 0 && $u2 <= 0) {
10197
return 0;

src/CoreBundle/Controller/Api/BaseResourceFileAction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ protected function handleCreateFileRequestUncompress(
427427

428428
if (empty($resourceLinkList) || !\is_array($resourceLinkList)) {
429429
$message = 'resourceLinkList is not a valid json. Use for example: [{"cid":1, "visibility":1}]';
430+
430431
throw new InvalidArgumentException($message);
431432
}
432433
}

src/CoreBundle/Controller/Api/ExportCLinksAction.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Chamilo\CourseBundle\Repository\CLinkCategoryRepository;
1414
use Chamilo\CourseBundle\Repository\CLinkRepository;
1515
use Doctrine\ORM\EntityManager;
16-
use Export;
1716
use PDF;
1817
use Symfony\Component\HttpFoundation\BinaryFileResponse;
1918
use Symfony\Component\HttpFoundation\File\File;
@@ -23,6 +22,8 @@
2322
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
2423
use Symfony\Contracts\Translation\TranslatorInterface;
2524

25+
use const ENT_QUOTES;
26+
2627
readonly class ExportCLinksAction
2728
{
2829
public function __construct(
@@ -60,11 +61,13 @@ public function __invoke(
6061
// Links without category
6162
$qbNoCat = $repo->getResourcesByCourse($course, $session, null, null, true, true);
6263
$qbNoCat->andWhere('resource.category = 0 OR resource.category IS NULL');
64+
6365
/** @var CLink[] $linksWithoutCategory */
6466
$linksWithoutCategory = $qbNoCat->getQuery()->getResult();
6567

6668
// Categories
6769
$qbCat = $repoCategory->getResourcesByCourse($course, $session, null, null, true, true);
70+
6871
/** @var CLinkCategory[] $categories */
6972
$categories = $qbCat->getQuery()->getResult();
7073

@@ -155,7 +158,8 @@ private function generatePdfFile(
155158
null,
156159
false,
157160
true
158-
);
161+
)
162+
;
159163
}
160164

161165
/**

src/CoreBundle/Controller/Api/UpdatePositionLink.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\HttpKernel\Attribute\AsController;
1717
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1818

19+
use const PHP_INT_MAX;
20+
1921
#[AsController]
2022
class UpdatePositionLink extends AbstractController
2123
{
@@ -149,14 +151,16 @@ private function reindexBucket(
149151

150152
if ($parentNode) {
151153
$qb->andWhere('rn.parent = :parent')
152-
->setParameter('parent', $parentNode);
154+
->setParameter('parent', $parentNode)
155+
;
153156
} else {
154157
$qb->andWhere('rn.parent IS NULL');
155158
}
156159

157160
if ($categoryId > 0) {
158161
$qb->andWhere('l.category = :cat')
159-
->setParameter('cat', $em->getReference(CLinkCategory::class, $categoryId));
162+
->setParameter('cat', $em->getReference(CLinkCategory::class, $categoryId))
163+
;
160164
} else {
161165
$qb->andWhere('l.category IS NULL');
162166
}
@@ -180,7 +184,7 @@ private function reindexBucket(
180184
});
181185

182186
// If we are handling the moved link, place it at insertAt
183-
if ($movedLink && $insertAt !== null) {
187+
if ($movedLink && null !== $insertAt) {
184188
$movedId = (int) $movedLink->getIid();
185189

186190
$links = array_values(array_filter($links, static fn (CLink $x): bool => (int) $x->getIid() !== $movedId));
@@ -189,8 +193,8 @@ private function reindexBucket(
189193
if ($pos < 0) {
190194
$pos = 0;
191195
}
192-
if ($pos > count($links)) {
193-
$pos = count($links);
196+
if ($pos > \count($links)) {
197+
$pos = \count($links);
194198
}
195199

196200
array_splice($links, $pos, 0, [$movedLink]);

src/CoreBundle/Controller/CourseMaintenanceController.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
3030
use Symfony\Component\Security\Http\Attribute\IsGranted;
3131
use Throwable;
32+
use UnserializeApi;
3233
use ZipArchive;
3334

3435
use const DIRECTORY_SEPARATOR;
@@ -947,10 +948,10 @@ public function cc13ExportExecute(int $node, Request $req): JsonResponse
947948

948949
$fileName = basename($imsccPath);
949950
$downloadUrl = $this->generateUrl(
950-
'cm_cc13_export_download',
951-
['node' => $node],
952-
UrlGeneratorInterface::ABSOLUTE_URL
953-
).'?file='.rawurlencode($fileName);
951+
'cm_cc13_export_download',
952+
['node' => $node],
953+
UrlGeneratorInterface::ABSOLUTE_URL
954+
).'?file='.rawurlencode($fileName);
954955

955956
return $this->json([
956957
'ok' => true,
@@ -1172,7 +1173,7 @@ private function jsonError(string $message, int $status = 400, array $extra = []
11721173
private function getJsonPayload(Request $req): array
11731174
{
11741175
$raw = (string) ($req->getContent() ?? '');
1175-
$data = json_decode($raw !== '' ? $raw : '{}', true);
1176+
$data = json_decode('' !== $raw ? $raw : '{}', true);
11761177

11771178
return \is_array($data) ? $data : [];
11781179
}
@@ -1204,7 +1205,8 @@ private function validateBackupFilename(string $filename): string
12041205
* Ensure selection map exists; if only types were selected, build the map from types.
12051206
*
12061207
* @param array<string,array> $selectedResources
1207-
* @param string[] $selectedTypes
1208+
* @param string[] $selectedTypes
1209+
*
12081210
* @return array<string,array>
12091211
*/
12101212
private function ensureSelectionMap(object $course, array $selectedResources, array $selectedTypes): array
@@ -1217,6 +1219,7 @@ private function ensureSelectionMap(object $course, array $selectedResources, ar
12171219
foreach ($selectedResources as $ids) {
12181220
if (\is_array($ids) && !empty($ids)) {
12191221
$hasAny = true;
1222+
12201223
break;
12211224
}
12221225
}
@@ -1309,8 +1312,8 @@ private function loadLegacyCourseForAnyBackup(string $backupId, string $force =
13091312
set_error_handler(static function (): void {});
13101313

13111314
try {
1312-
if (class_exists(\UnserializeApi::class)) {
1313-
$c = \UnserializeApi::unserialize('course', $payload);
1315+
if (class_exists(UnserializeApi::class)) {
1316+
$c = UnserializeApi::unserialize('course', $payload);
13141317
} else {
13151318
$c = @unserialize($payload, ['allowed_classes' => true]);
13161319
}
@@ -1593,15 +1596,19 @@ private static function iniSizeToBytes(string $val): int
15931596
switch ($unit) {
15941597
case 't':
15951598
$num *= 1024;
1596-
// no break
1599+
1600+
// no break
15971601
case 'g':
15981602
$num *= 1024;
1599-
// no break
1603+
1604+
// no break
16001605
case 'm':
16011606
$num *= 1024;
1602-
// no break
1607+
1608+
// no break
16031609
case 'k':
16041610
$num *= 1024;
1611+
16051612
break;
16061613
}
16071614

src/CoreBundle/Controller/DropboxController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ private function buildAsciiFilenameFallback(string $filename): string
766766
// Force strict ASCII-only fallback
767767
$baseAscii = preg_replace('/[^A-Za-z0-9._-]+/', '_', $baseAscii) ?? '';
768768
$baseAscii = preg_replace('/_+/', '_', $baseAscii) ?? '';
769-
$baseAscii = trim($baseAscii, "._-");
769+
$baseAscii = trim($baseAscii, '._-');
770770

771771
if ('' === $baseAscii) {
772772
$baseAscii = 'download';

0 commit comments

Comments
 (0)