Skip to content

Commit 09a1a76

Browse files
committed
Minor: Format code
1 parent 535acc2 commit 09a1a76

35 files changed

+526
-450
lines changed

src/CoreBundle/Controller/Admin/AdminController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Chamilo\CourseBundle\Entity\CDocument;
2828
use Doctrine\DBAL\Connection;
2929
use Doctrine\ORM\EntityManagerInterface;
30+
use RuntimeException;
3031
use Symfony\Component\HttpFoundation\JsonResponse;
3132
use Symfony\Component\HttpFoundation\Request;
3233
use Symfony\Component\HttpFoundation\Response;
@@ -263,6 +264,7 @@ public function attachOrphanFileToCourse(
263264

264265
// Try to reuse an existing visible document for this node.
265266
$documentRepo = Container::getDocumentRepository();
267+
266268
/** @var CDocument|null $sharedDocument */
267269
$sharedDocument = $resourceNode
268270
? $documentRepo->findOneBy(['resourceNode' => $resourceNode])
@@ -735,7 +737,7 @@ private function createVisibleDocumentFromResourceFile(
735737
): CDocument {
736738
$userEntity = $this->userHelper->getCurrent();
737739
if (null === $userEntity) {
738-
throw new \RuntimeException('Current user is required to create or reuse a document.');
740+
throw new RuntimeException('Current user is required to create or reuse a document.');
739741
}
740742

741743
// Current node (may be null for truly orphan files).
@@ -744,7 +746,7 @@ private function createVisibleDocumentFromResourceFile(
744746
if (null === $resourceNode) {
745747
$courseRootNode = $course->getResourceNode();
746748
if (null === $courseRootNode) {
747-
throw new \RuntimeException('Course root node is required to attach a resource node.');
749+
throw new RuntimeException('Course root node is required to attach a resource node.');
748750
}
749751

750752
// Create the node that will be shared by all courses.

src/CoreBundle/Controller/Admin/SettingsController.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Symfony\Component\Validator\Exception\ValidatorException;
2828
use Symfony\Contracts\Translation\TranslatorInterface;
2929

30+
use const DIRECTORY_SEPARATOR;
31+
3032
#[Route('/admin')]
3133
class SettingsController extends BaseController
3234
{
@@ -381,37 +383,38 @@ private function buildSearchDiagnostics(SettingsManager $manager): array
381383
// Base status rows (Xapian extension + directory checks + custom fields)
382384
$indexDir = $this->searchIndexPathResolver->getIndexDir();
383385

384-
$xapianLoaded = \extension_loaded('xapian');
385-
$dirExists = \is_dir($indexDir);
386-
$dirWritable = \is_writable($indexDir);
387-
$fieldsCount = $this->entityManager
386+
$xapianLoaded = \extension_loaded('xapian');
387+
$dirExists = is_dir($indexDir);
388+
$dirWritable = is_writable($indexDir);
389+
$fieldsCount = $this->entityManager
388390
->getRepository(SearchEngineField::class)
389-
->count([]);
391+
->count([])
392+
;
390393

391394
$statusRows = [
392395
[
393396
'label' => $this->translator->trans('Xapian module installed'),
394-
'ok' => $xapianLoaded,
397+
'ok' => $xapianLoaded,
395398
],
396399
[
397400
'label' => $this->translator->trans('The directory exists').' - '.$indexDir,
398-
'ok' => $dirExists,
401+
'ok' => $dirExists,
399402
],
400403
[
401404
'label' => $this->translator->trans('Is writable').' - '.$indexDir,
402-
'ok' => $dirWritable,
405+
'ok' => $dirWritable,
403406
],
404407
[
405408
'label' => $this->translator->trans('Available custom search fields'),
406-
'ok' => $fieldsCount > 0,
409+
'ok' => $fieldsCount > 0,
407410
],
408411
];
409412

410413
// External converters (ps2pdf, pdftotext, ...)
411-
$tools = [];
414+
$tools = [];
412415
$toolsWarning = null;
413416

414-
$isWindows = \DIRECTORY_SEPARATOR === '\\';
417+
$isWindows = DIRECTORY_SEPARATOR === '\\';
415418

416419
if ($isWindows) {
417420
$toolsWarning = $this->translator->trans(
@@ -421,30 +424,30 @@ private function buildSearchDiagnostics(SettingsManager $manager): array
421424
$programs = ['ps2pdf', 'pdftotext', 'catdoc', 'html2text', 'unrtf', 'catppt', 'xls2csv'];
422425

423426
foreach ($programs as $program) {
424-
$output = [];
427+
$output = [];
425428
$returnVar = null;
426429

427430
// Same behaviour as "which $program" in Chamilo 1
428-
@\exec('which '.\escapeshellarg($program), $output, $returnVar);
429-
$path = $output[0] ?? '';
430-
$installed = $path !== '';
431+
@exec('which '.escapeshellarg($program), $output, $returnVar);
432+
$path = $output[0] ?? '';
433+
$installed = '' !== $path;
431434

432435
$tools[] = [
433436
'name' => $program,
434437
'path' => $path,
435-
'ok' => $installed,
438+
'ok' => $installed,
436439
];
437440
}
438441
}
439442

440443
return [
441444
// Whether full-text search is enabled at all
442-
'enabled' => ($searchEnabled === 'true'),
445+
'enabled' => ('true' === $searchEnabled),
443446
// Xapian + directory + custom fields
444-
'status_rows' => $statusRows,
447+
'status_rows' => $statusRows,
445448
// External converters
446-
'tools' => $tools,
447-
'tools_warning' => $toolsWarning,
449+
'tools' => $tools,
450+
'tools_warning' => $toolsWarning,
448451
];
449452
}
450453
}

src/CoreBundle/Controller/Api/MoveDocumentAction.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use Chamilo\CoreBundle\Entity\ResourceNode;
1212
use Chamilo\CoreBundle\Entity\Session;
1313
use Chamilo\CoreBundle\Repository\ResourceLinkRepository;
14-
use Chamilo\CourseBundle\Entity\CGroup;
1514
use Chamilo\CourseBundle\Entity\CDocument;
15+
use Chamilo\CourseBundle\Entity\CGroup;
1616
use Doctrine\ORM\EntityManagerInterface;
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@@ -27,7 +27,7 @@ public function __construct(
2727
public function __invoke(CDocument $document, Request $request): CDocument
2828
{
2929
$payload = json_decode((string) $request->getContent(), true);
30-
if (!is_array($payload)) {
30+
if (!\is_array($payload)) {
3131
throw new BadRequestHttpException('Invalid JSON body.');
3232
}
3333

@@ -109,11 +109,11 @@ public function __invoke(CDocument $document, Request $request): CDocument
109109

110110
private function normalizeNodeId(mixed $value): ?int
111111
{
112-
if (is_int($value)) {
112+
if (\is_int($value)) {
113113
return $value;
114114
}
115115

116-
if (is_string($value)) {
116+
if (\is_string($value)) {
117117
if (ctype_digit($value)) {
118118
return (int) $value;
119119
}

src/CoreBundle/Controller/SearchController.php

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
1818
use Symfony\Component\Routing\Attribute\Route;
19+
use Throwable;
1920

2021
final class SearchController extends AbstractController
2122
{
2223
public function __construct(
2324
private readonly XapianSearchService $xapianSearchService,
2425
private readonly XapianIndexService $xapianIndexService,
2526
private readonly EntityManagerInterface $em,
26-
) {
27-
}
27+
) {}
2828

2929
/**
3030
* Minimal Xapian search endpoint returning JSON.
@@ -38,12 +38,12 @@ public function __construct(
3838
)]
3939
public function xapianSearchAction(Request $request): JsonResponse
4040
{
41-
$q = \trim((string) $request->query->get('q', ''));
41+
$q = trim((string) $request->query->get('q', ''));
4242

43-
if ($q === '') {
43+
if ('' === $q) {
4444
return $this->json([
45-
'query' => '',
46-
'total' => 0,
45+
'query' => '',
46+
'total' => 0,
4747
'results' => [],
4848
]);
4949
}
@@ -56,11 +56,11 @@ public function xapianSearchAction(Request $request): JsonResponse
5656
);
5757

5858
return $this->json([
59-
'query' => $q,
60-
'total' => $result['count'],
59+
'query' => $q,
60+
'total' => $result['count'],
6161
'results' => $result['results'],
6262
]);
63-
} catch (\Throwable $e) {
63+
} catch (Throwable $e) {
6464
return $this->json([
6565
'query' => $q,
6666
'error' => $e->getMessage(),
@@ -80,35 +80,35 @@ public function xapianSearchAction(Request $request): JsonResponse
8080
)]
8181
public function xapianSearchPageAction(Request $request): Response
8282
{
83-
$q = \trim((string) $request->query->get('q', ''));
83+
$q = trim((string) $request->query->get('q', ''));
8484

8585
$total = 0;
8686
$results = [];
8787
$error = null;
8888

89-
if ($q !== '') {
89+
if ('' !== $q) {
9090
try {
9191
$searchResult = $this->xapianSearchService->search(
9292
queryString: $q,
9393
offset: 0,
9494
length: 20
9595
);
9696

97-
$total = $searchResult['count'] ?? 0;
97+
$total = $searchResult['count'] ?? 0;
9898
$results = $searchResult['results'] ?? [];
9999

100100
$results = $this->hydrateResultsWithCourseRootNode($results);
101101
$results = $this->hydrateQuestionResultsWithQuizIds($results);
102-
} catch (\Throwable $e) {
102+
} catch (Throwable $e) {
103103
$error = $e->getMessage();
104104
}
105105
}
106106

107107
return $this->render('@ChamiloCore/Search/xapian_search.html.twig', [
108-
'query' => $q,
109-
'total' => $total,
108+
'query' => $q,
109+
'total' => $total,
110110
'results' => $results,
111-
'error' => $error,
111+
'error' => $error,
112112
]);
113113
}
114114

@@ -129,12 +129,12 @@ public function xapianDemoIndexAction(): JsonResponse
129129

130130
return $this->json([
131131
'indexed' => true,
132-
'doc_id' => $docId,
132+
'doc_id' => $docId,
133133
]);
134-
} catch (\Throwable $e) {
134+
} catch (Throwable $e) {
135135
return $this->json([
136136
'indexed' => false,
137-
'error' => $e->getMessage(),
137+
'error' => $e->getMessage(),
138138
], 500);
139139
}
140140
}
@@ -161,22 +161,25 @@ private function hydrateResultsWithCourseRootNode(array $results): array
161161
// If the field already exists (coming from the indexer), keep it.
162162
if (!empty($data['course_root_node_id'])) {
163163
$result['data'] = $data;
164+
164165
continue;
165166
}
166167

167-
$courseId = isset($data['course_id']) && $data['course_id'] !== ''
168+
$courseId = isset($data['course_id']) && '' !== $data['course_id']
168169
? (int) $data['course_id']
169170
: null;
170171

171172
if (!$courseId) {
172173
$result['data'] = $data;
174+
173175
continue;
174176
}
175177

176178
/** @var Course|null $course */
177179
$course = $this->em->find(Course::class, $courseId);
178180
if (!$course || !$course->getResourceNode()) {
179181
$result['data'] = $data;
182+
180183
continue;
181184
}
182185

@@ -239,7 +242,8 @@ private function hydrateQuestionResultsWithQuizIds(array $results): array
239242
/** @var CQuizRelQuestion|null $rel */
240243
$rel = $this->em
241244
->getRepository(CQuizRelQuestion::class)
242-
->findOneBy(['question' => $questionId]);
245+
->findOneBy(['question' => $questionId])
246+
;
243247

244248
if (!$rel) {
245249
$result['data'] = $data;

src/CoreBundle/Entity/Listener/ResourceListener.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Symfony\Component\HttpFoundation\File\UploadedFile;
3939
use Symfony\Component\HttpFoundation\RequestStack;
4040
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
41+
use Throwable;
4142

4243
use const JSON_THROW_ON_ERROR;
4344
use const PATHINFO_EXTENSION;
@@ -298,7 +299,7 @@ public function postPersist(AbstractResource $resource, PostPersistEventArgs $ev
298299

299300
try {
300301
$docId = $this->documentXapianIndexer->indexDocument($resource);
301-
} catch (\Throwable $e) {
302+
} catch (Throwable $e) {
302303
error_log(
303304
'[Xapian] postPersist: indexing failed: '.
304305
$e->getMessage().
@@ -323,12 +324,13 @@ public function postUpdate(AbstractResource $resource, PostUpdateEventArgs $even
323324
if ($resource instanceof CDocument) {
324325
if (!$this->shouldIndexDocumentFromRequest()) {
325326
error_log('[Xapian] postUpdate: indexing disabled by indexDocumentContent flag');
327+
326328
return;
327329
}
328330

329331
try {
330332
$docId = $this->documentXapianIndexer->indexDocument($resource);
331-
} catch (\Throwable $e) {
333+
} catch (Throwable $e) {
332334
error_log(
333335
'[Xapian] postUpdate: indexing failed: '.
334336
$e->getMessage().
@@ -442,7 +444,7 @@ public function preRemove(AbstractResource $resource, LifecycleEventArgs $args):
442444
if ($resourceNode) {
443445
try {
444446
$this->documentXapianIndexer->deleteForResourceNodeId((int) $resourceNode->getId());
445-
} catch (\Throwable $e) {
447+
} catch (Throwable $e) {
446448
error_log(
447449
'[Xapian] preRemove: deleteForResourceNodeId() failed: '.
448450
$e->getMessage().' in '.$e->getFile().':'.$e->getLine()
@@ -485,7 +487,7 @@ private function shouldIndexDocumentFromRequest(): bool
485487
return $raw;
486488
}
487489

488-
if (\is_numeric($raw)) {
490+
if (is_numeric($raw)) {
489491
return ((int) $raw) !== 0;
490492
}
491493

src/CoreBundle/Entity/ResourceFile.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class ResourceFile implements Stringable
138138
#[Groups(['resource_file:read', 'resource_node:read', 'document:read', 'message:read', 'personal_file:read'])]
139139
#[ORM\Column(type: 'integer')]
140140
protected ?int $size = 0;
141+
141142
/**
142143
* Optional language for the file variant.
143144
* This is used for indexing and future-proof resource variations.
@@ -199,13 +200,15 @@ public function __toString(): string
199200
{
200201
return $this->getOriginalName();
201202
}
203+
202204
/**
203205
* Get the file language (can be null if unknown/multilingual).
204206
*/
205207
public function getLanguage(): ?Language
206208
{
207209
return $this->language;
208210
}
211+
209212
/**
210213
* Set the file language (nullable by design).
211214
*/

src/CoreBundle/Entity/ResourceLink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ResourceLink implements Stringable
6262
/**
6363
* @var Collection<int, self>
6464
*
65-
* Children links in the document hierarchy by context.
65+
* Children links in the document hierarchy by context
6666
*/
6767
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
6868
private Collection $children;

0 commit comments

Comments
 (0)