Skip to content

Commit 044f0ce

Browse files
committed
Minor: Format code
1 parent 76fd9bc commit 044f0ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+608
-435
lines changed

src/CoreBundle/Controller/Admin/AdminController.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,10 @@ public function listFilesInfo(Request $request, ResourceFileRepository $resource
9393
#[IsGranted('ROLE_ADMIN')]
9494
#[Route('/resources_info', name: 'admin_resources_info', methods: ['GET'])]
9595
public function listResourcesInfo(
96-
Request $request,
96+
Request $request,
9797
ResourceNodeRepository $resourceNodeRepo,
9898
EntityManagerInterface $em
99-
): Response
100-
{
99+
): Response {
101100
$resourceTypeId = $request->query->getInt('type');
102101
$resourceTypes = $em->getRepository(ResourceType::class)->findAll();
103102

@@ -117,7 +116,8 @@ public function listResourcesInfo(
117116
->where('rn.resourceType = :type')
118117
->setParameter('type', $resourceTypeId)
119118
->getQuery()
120-
->getResult();
119+
->getResult()
120+
;
121121

122122
/** Aggregate by course/session key */
123123
$seen = [];
@@ -140,10 +140,10 @@ public function listResourcesInfo(
140140
'id' => $sid ?: $cid,
141141
'courseId' => $cid,
142142
'sessionId' => $sid,
143-
'title' => $sid ? ($session->getTitle() . ' - ' . $course->getTitle()) : $course->getTitle(),
143+
'title' => $sid ? ($session->getTitle().' - '.$course->getTitle()) : $course->getTitle(),
144144
'url' => $sid
145-
? '/course/' . $cid . '/home?sid=' . $sid
146-
: '/course/' . $cid . '/home',
145+
? '/course/'.$cid.'/home?sid='.$sid
146+
: '/course/'.$cid.'/home',
147147
'count' => 0,
148148
'items' => [],
149149
'users' => [],
@@ -160,7 +160,7 @@ public function listResourcesInfo(
160160
}
161161
}
162162

163-
/** Populate users depending on the resource type */
163+
/* Populate users depending on the resource type */
164164
if (!empty($seen)) {
165165
$usersMap = $this->fetchUsersForType($typeTitle, $em, $keysMeta);
166166
foreach ($usersMap as $key => $names) {
@@ -169,16 +169,17 @@ public function listResourcesInfo(
169169
}
170170
}
171171
// Show the "Users" column only if there's any user to display
172-
$showUsers = array_reduce($seen, fn($acc, $row) => $acc || !empty($row['users']), false);
172+
$showUsers = array_reduce($seen, fn ($acc, $row) => $acc || !empty($row['users']), false);
173173
}
174174

175175
/** Normalize output */
176176
$courses = array_values(array_map(function ($row) {
177177
$row['items'] = array_values(array_unique($row['items']));
178+
178179
return $row;
179180
}, $seen));
180181

181-
usort($courses, fn($a, $b) => strnatcasecmp($a['title'], $b['title']));
182+
usort($courses, fn ($a, $b) => strnatcasecmp($a['title'], $b['title']));
182183
}
183184

184185
return $this->render('@ChamiloCore/Admin/resources_info.html.twig', [
@@ -312,11 +313,12 @@ public function runCleanupTempUploads(
312313
* Returns a map key => [user names...] depending on the selected resource type.
313314
*
314315
* @param array<string,array{cid:int,sid:int}> $keysMeta
316+
*
315317
* @return array<string,string[]>
316318
*/
317319
private function fetchUsersForType(?string $typeTitle, EntityManagerInterface $em, array $keysMeta): array
318320
{
319-
$type = is_string($typeTitle) ? strtolower($typeTitle) : '';
321+
$type = \is_string($typeTitle) ? strtolower($typeTitle) : '';
320322

321323
return match ($type) {
322324
'dropbox' => $this->fetchDropboxRecipients($em, $keysMeta),
@@ -329,6 +331,7 @@ private function fetchUsersForType(?string $typeTitle, EntityManagerInterface $e
329331
* Default behavior: list users tied to ResourceLink.user (user-scoped visibility).
330332
*
331333
* @param array<string,array{cid:int,sid:int}> $keysMeta
334+
*
332335
* @return array<string,string[]>
333336
*/
334337
private function fetchUsersFromResourceLinks(EntityManagerInterface $em, array $keysMeta): array
@@ -346,6 +349,7 @@ private function fetchUsersFromResourceLinks(EntityManagerInterface $em, array $
346349
LEFT JOIN rl.user u
347350
WHERE rl.user IS NOT NULL'
348351
);
352+
349353
/** @var ResourceLink[] $links */
350354
$links = $q->getResult();
351355

@@ -370,13 +374,15 @@ private function fetchUsersFromResourceLinks(EntityManagerInterface $em, array $
370374
foreach ($out as $k => $arr) {
371375
$out[$k] = array_values(array_unique(array_filter($arr)));
372376
}
377+
373378
return $out;
374379
}
375380

376381
/**
377382
* Dropbox-specific: list real recipients from c_dropbox_person (joined with c_dropbox_file and user).
378383
*
379384
* @param array<string,array{cid:int,sid:int}> $keysMeta
385+
*
380386
* @return array<string,string[]>
381387
*/
382388
private function fetchDropboxRecipients(EntityManagerInterface $em, array $keysMeta): array
@@ -385,7 +391,7 @@ private function fetchDropboxRecipients(EntityManagerInterface $em, array $keysM
385391
return [];
386392
}
387393

388-
$cids = array_values(array_unique(array_map(fn($m) => (int) $m['cid'], $keysMeta)));
394+
$cids = array_values(array_unique(array_map(fn ($m) => (int) $m['cid'], $keysMeta)));
389395
if (!$cids) {
390396
return [];
391397
}
@@ -415,20 +421,23 @@ private function fetchDropboxRecipients(EntityManagerInterface $em, array $keysM
415421
continue; // ignore entries not displayed in the table
416422
}
417423
$uname = trim((string) ($r['uname'] ?? ''));
418-
if ($uname !== '') {
424+
if ('' !== $uname) {
419425
$out[$key][] = $uname;
420426
}
421427
}
422428
// Dedupe
423429
foreach ($out as $k => $arr) {
424430
$out[$k] = array_values(array_unique(array_filter($arr)));
425431
}
432+
426433
return $out;
427434
}
428435

429-
/** Helper to build the aggregation key for course/session rows. */
436+
/**
437+
* Helper to build the aggregation key for course/session rows.
438+
*/
430439
private static function makeKey(int $cid, int $sid): string
431440
{
432-
return $sid > 0 ? ('s' . $sid . '-' . $cid) : ('c' . $cid);
441+
return $sid > 0 ? ('s'.$sid.'-'.$cid) : ('c'.$cid);
433442
}
434443
}

src/CoreBundle/Controller/Admin/SessionAdminController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function listCompleted(
126126
$isDownloadAllowed = false;
127127

128128
if (!empty($path)) {
129-
$hash = \pathinfo($path, PATHINFO_FILENAME);
129+
$hash = pathinfo($path, PATHINFO_FILENAME);
130130
$downloadUrl = '/certificates/'.$hash.'.pdf';
131131

132132
$isPlatformAdmin = $user && $user->isAdmin();

src/CoreBundle/Controller/Admin/SettingsController.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Chamilo\CoreBundle\Entity\SettingsValueTemplate;
1212
use Chamilo\CoreBundle\Helpers\AccessUrlHelper;
1313
use Chamilo\CoreBundle\Traits\ControllerTrait;
14+
use Collator;
1415
use Doctrine\ORM\EntityManagerInterface;
1516
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
1617
use Symfony\Component\Form\Extension\Core\Type\TextType;
@@ -195,7 +196,6 @@ public function updateSetting(Request $request, AccessUrlHelper $accessUrlHelper
195196
$schemas = $manager->getSchemas();
196197
[$ordered, $labelMap] = $this->computeOrderedNamespacesByTranslatedLabel($schemas, $request);
197198

198-
199199
$templateMap = [];
200200
$settingsRepo = $this->entityManager->getRepository(SettingsCurrent::class);
201201

@@ -269,38 +269,41 @@ private function getSearchForm()
269269
private function computeOrderedNamespacesByTranslatedLabel(array $schemas, Request $request): array
270270
{
271271
$namespaces = array_map(
272-
static fn($k) => str_replace('chamilo_core.settings.', '', $k),
272+
static fn ($k) => str_replace('chamilo_core.settings.', '', $k),
273273
array_keys($schemas)
274274
);
275275

276276
$labelMap = [];
277277
foreach ($namespaces as $ns) {
278-
if ($ns === 'cas') {
278+
if ('cas' === $ns) {
279279
$labelMap[$ns] = 'CAS';
280+
280281
continue;
281282
}
282-
if ($ns === 'lp') {
283+
if ('lp' === $ns) {
283284
$labelMap[$ns] = $this->translator->trans('Learning path');
285+
284286
continue;
285287
}
286-
if ($ns === 'ai_helpers') {
288+
if ('ai_helpers' === $ns) {
287289
$labelMap[$ns] = $this->translator->trans('AI helpers');
290+
288291
continue;
289292
}
290293

291294
$key = ucfirst(str_replace('_', ' ', $ns));
292295
$labelMap[$ns] = $this->translator->trans($key);
293296
}
294297

295-
$collator = class_exists(\Collator::class) ? new \Collator($request->getLocale()) : null;
298+
$collator = class_exists(Collator::class) ? new Collator($request->getLocale()) : null;
296299
usort($namespaces, function ($a, $b) use ($labelMap, $collator) {
297300
return $collator
298301
? $collator->compare($labelMap[$a], $labelMap[$b])
299302
: strcasecmp($labelMap[$a], $labelMap[$b]);
300303
});
301304

302305
$idx = array_search('ai_helpers', $namespaces, true);
303-
if ($idx !== false) {
306+
if (false !== $idx) {
304307
array_splice($namespaces, $idx, 1);
305308
array_splice($namespaces, 1, 0, ['ai_helpers']);
306309
}

src/CoreBundle/Controller/Api/CreateBlogAttachmentAction.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function __invoke(
3030
UserHelper $userHelper,
3131
CBlogAttachmentRepository $attachRepo,
3232
ResourceNodeRepository $resourceNodeRepo
33-
3433
): JsonResponse {
3534
$user = $userHelper->getCurrent();
3635
if (!$user) {
@@ -41,7 +40,11 @@ public function __invoke(
4140
$file = $request->files->get('uploadFile');
4241
if (!$file) {
4342
foreach ($request->files as $val) {
44-
if ($val instanceof UploadedFile) { $file = $val; break; }
43+
if ($val instanceof UploadedFile) {
44+
$file = $val;
45+
46+
break;
47+
}
4548
}
4649
}
4750
if (!$file) {
@@ -51,12 +54,13 @@ public function __invoke(
5154
// IRIs
5255
$blogIri = (string) $request->request->get('blog', '');
5356
$postIri = (string) $request->request->get('post', '');
54-
if ($blogIri === '' || $postIri === '') {
57+
if ('' === $blogIri || '' === $postIri) {
5558
throw new BadRequestHttpException('Both "blog" and "post" are required IRIs.');
5659
}
5760

5861
/** @var CBlog|null $blog */
5962
$blog = $em->getRepository(CBlog::class)->find(self::idFromIri($blogIri));
63+
6064
/** @var CBlogPost|null $post */
6165
$post = $em->getRepository(CBlogPost::class)->find(self::idFromIri($postIri));
6266
if (!$blog || !$post) {
@@ -68,8 +72,8 @@ public function __invoke(
6872
throw new BadRequestHttpException('Blog has no resource node.');
6973
}
7074

71-
$original = $file->getClientOriginalName() ?: 'upload.bin';
72-
$filename = $this->uniqueFilenameForAttachments($original, $attachRepo);
75+
$original = $file->getClientOriginalName() ?: 'upload.bin';
76+
$filename = $this->uniqueFilenameForAttachments($original, $attachRepo);
7377

7478
$rf = new ResourceFile();
7579
$rf->setResourceNode($node);
@@ -93,11 +97,11 @@ public function __invoke(
9397
$em->flush();
9498

9599
return new JsonResponse([
96-
'ok' => true,
97-
'id' => (int) $att->getIid(),
98-
'filename' => $att->getFilename(),
99-
'size' => $att->getSize(),
100-
'path' => $downloadUrl,
100+
'ok' => true,
101+
'id' => (int) $att->getIid(),
102+
'filename' => $att->getFilename(),
103+
'size' => $att->getSize(),
104+
'path' => $downloadUrl,
101105
'resourceFileId' => (int) $rf->getId(),
102106
], 201);
103107
}
@@ -112,12 +116,13 @@ private function uniqueFilenameForAttachments(string $original, CBlogAttachmentR
112116
$candidate = $original;
113117
$i = 1;
114118
while ($repo->findOneBy(['filename' => $candidate])) {
115-
$pi = pathinfo($original);
119+
$pi = pathinfo($original);
116120
$name = $pi['filename'] ?? 'file';
117-
$ext = isset($pi['extension']) ? '.'.$pi['extension'] : '';
121+
$ext = isset($pi['extension']) ? '.'.$pi['extension'] : '';
118122
$candidate = $name.'_'.$i.$ext;
119123
$i++;
120124
}
125+
121126
return $candidate;
122127
}
123128
}

src/CoreBundle/Controller/Api/CreateCBlogAction.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/* For licensing terms, see /license.txt */
@@ -43,7 +44,8 @@ public function __invoke(
4344

4445
$blog = (new CBlog())
4546
->setTitle($title)
46-
->setBlogSubtitle($subtitle);
47+
->setBlogSubtitle($subtitle)
48+
;
4749

4850
if (!empty($parentResourceNodeId)) {
4951
$blog->setParentResourceNode((int) $parentResourceNodeId);

0 commit comments

Comments
 (0)