Fix psalm issues

pull/4197/head
Angel Fernando Quiroz Campos 4 years ago
parent 499bec4a62
commit 095661df32
  1. 1
      psalm.xml
  2. 4
      public/main/admin/update_schema.php
  3. 2
      public/main/admin/user_edit.php
  4. 2
      public/main/exercise/exercise.class.php
  5. 24
      public/main/gradebook/lib/be/category.class.php
  6. 10
      public/main/gradebook/lib/be/exerciselink.class.php
  7. 2
      public/main/inc/lib/TicketManager.php
  8. 4
      public/main/inc/lib/urlmanager.lib.php
  9. 7
      public/main/inc/lib/usermanager.lib.php
  10. 17
      public/main/social/map.php
  11. 1
      src/CoreBundle/Controller/Api/AbstractFeedbackSocialPostController.php
  12. 9
      src/CoreBundle/Controller/CourseController.php
  13. 13
      src/CoreBundle/Controller/ResetPasswordController.php
  14. 11
      src/CoreBundle/Controller/SessionController.php

@ -1,6 +1,5 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<psalm <psalm
totallyTyped="false"
resolveFromConfigFile="true" resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config" xmlns="https://getpsalm.org/schema/config"

@ -14,14 +14,14 @@ if (true != api_get_configuration_value('sync_db_with_schema')) {
$em = Database::getManager(); $em = Database::getManager();
$connection = Database::getManager()->getConnection(); $connection = Database::getManager()->getConnection();
$sm = $connection->getSchemaManager(); $sm = $connection->createSchemaManager();
$fromSchema = $sm->createSchema(); $fromSchema = $sm->createSchema();
$tool = new \Doctrine\ORM\Tools\SchemaTool(Database::getManager()); $tool = new \Doctrine\ORM\Tools\SchemaTool(Database::getManager());
$metadatas = $em->getMetadataFactory()->getAllMetadata(); $metadatas = $em->getMetadataFactory()->getAllMetadata();
$toSchema = $tool->getSchemaFromMetadata($metadatas); $toSchema = $tool->getSchemaFromMetadata($metadatas);
$comparator = new \Doctrine\DBAL\Schema\Comparator(); $comparator = new \Doctrine\DBAL\Schema\Comparator();
$schemaDiff = $comparator->compare($fromSchema, $toSchema); $schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);
$sqlList = $schemaDiff->toSaveSql($connection->getDatabasePlatform()); $sqlList = $schemaDiff->toSaveSql($connection->getDatabasePlatform());
$content = ''; $content = '';

@ -321,7 +321,7 @@ if (!empty($studentBossList)) {
$studentBossList = array_column($studentBossList, 'boss_id'); $studentBossList = array_column($studentBossList, 'boss_id');
} }
$user_data['student_boss'] = array_values($studentBossList); $user_data['student_boss'] = $studentBossList;
$form->addMultiSelect('student_boss', get_lang('Superior (n+1)'), $studentBossToSelect); $form->addMultiSelect('student_boss', get_lang('Superior (n+1)'), $studentBossToSelect);
// EXTRA FIELDS // EXTRA FIELDS

@ -609,7 +609,7 @@ class Exercise
/** /**
* @param int $start * @param int $start
* @param int $limit * @param int $limit
* @param int $sidx * @param string $sidx
* @param string $sord * @param string $sord
* @param array $whereCondition * @param array $whereCondition
* @param array $extraFields * @param array $extraFields

@ -833,7 +833,7 @@ class Category implements GradebookItem
* @param string $course_code * @param string $course_code
* @param int $session_id * @param int $session_id
* *
* @return array (score sum, weight sum) or null if no scores available * @return array|null (score sum, weight sum) or null if no scores available
*/ */
public function calc_score( public function calc_score(
$studentId = null, $studentId = null,
@ -846,9 +846,9 @@ class Category implements GradebookItem
$cacheAvailable = api_get_configuration_value('apc') && $useCache; $cacheAvailable = api_get_configuration_value('apc') && $useCache;
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver = new \Doctrine\Common\Cache\ApcuCache(); $cache = new \Symfony\Component\Cache\Adapter\ApcuAdapter();
if ($cacheDriver->contains($key)) { if ($cache->hasItem($key)) {
return $cacheDriver->fetch($key); return $cache->getItem($key)->get();
} }
} }
// Classic // Classic
@ -1092,14 +1092,20 @@ class Category implements GradebookItem
case 'average': case 'average':
if (empty($ressum)) { if (empty($ressum)) {
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, null); $cacheItem = $cache->getItem($key);
$cacheItem->set(null);
$cache->save($cacheItem);
} }
return null; return null;
} }
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, [$ressum, $weightsum]); $cacheItem = $cache->getItem($key);
$cacheItem->set([$ressum, $weightsum]);
$cache->save($cacheItem);
} }
return [$ressum, $weightsum]; return [$ressum, $weightsum];
@ -1113,11 +1119,13 @@ class Category implements GradebookItem
break; break;
default: default:
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, [$ressum, $weightsum]); $cacheItem = $cache->getItem($key);
$cacheItem->set([$ressum, $weightsum]);
$cache->save($cacheItem);
} }
return [$ressum, $weightsum]; return [$ressum, $weightsum];
break;
} }
} }

@ -198,9 +198,9 @@ class ExerciseLink extends AbstractLink
$cacheAvailable = api_get_configuration_value('apc') && $useCache; $cacheAvailable = api_get_configuration_value('apc') && $useCache;
$cacheDriver = null; $cacheDriver = null;
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver = new \Doctrine\Common\Cache\ApcuCache(); $cache = new \Symfony\Component\Cache\Adapter\ApcuAdapter();
if ($cacheDriver->contains($key)) { if ($cache->hasItem($key)) {
return $cacheDriver->fetch($key); return $cache->getItem($key)->get();
} }
} }
@ -287,7 +287,9 @@ class ExerciseLink extends AbstractLink
} }
$result = [$data['score'], $data['max_score'], $data['exe_date'], $counter]; $result = [$data['score'], $data['max_score'], $data['exe_date'], $counter];
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, $result); $cacheItem = $cache->getItem($key);
$cacheItem->set($result);
$cache->save($cacheItem);
} }
return $result; return $result;

@ -2355,7 +2355,7 @@ class TicketManager
public static function deleteUserFromTicketSystem($userId) public static function deleteUserFromTicketSystem($userId)
{ {
$userId = (int) $userId; $userId = (int) $userId;
$schema = Database::getManager()->getConnection()->getSchemaManager(); $schema = Database::getManager()->getConnection()->createSchemaManager();
if ($schema->tablesExist('ticket_assigned_log')) { if ($schema->tablesExist('ticket_assigned_log')) {
$sql = "UPDATE ticket_assigned_log SET user_id = NULL WHERE user_id = $userId"; $sql = "UPDATE ticket_assigned_log SET user_id = NULL WHERE user_id = $userId";

@ -124,7 +124,7 @@ class UrlManager
WHERE url = '".Database::escape_string($url)."' "; WHERE url = '".Database::escape_string($url)."' ";
$res = Database::query($sql); $res = Database::query($sql);
return (int) Database::num_rows($res); return Database::num_rows($res);
} }
/** /**
@ -298,7 +298,7 @@ class UrlManager
WHERE c_id = '$courseId'"; WHERE c_id = '$courseId'";
$res = Database::query($sql); $res = Database::query($sql);
return (int) Database::num_rows($res); return Database::num_rows($res);
} }
/** /**

@ -805,7 +805,8 @@ class UserManager
} }
$connection = Database::getManager()->getConnection(); $connection = Database::getManager()->getConnection();
$tableExists = $connection->getSchemaManager()->tablesExist(['plugin_bbb_room']); $schemaManager = $connection->createSchemaManager();
$tableExists = $schemaManager->tablesExist(['plugin_bbb_room']);
if ($tableExists) { if ($tableExists) {
// Delete user from database // Delete user from database
$sql = "DELETE FROM plugin_bbb_room WHERE participant_id = $user_id"; $sql = "DELETE FROM plugin_bbb_room WHERE participant_id = $user_id";
@ -813,12 +814,12 @@ class UserManager
} }
// Delete user/ticket relationships :( // Delete user/ticket relationships :(
$tableExists = $connection->getSchemaManager()->tablesExist(['ticket_ticket']); $tableExists = $schemaManager->tablesExist(['ticket_ticket']);
if ($tableExists) { if ($tableExists) {
TicketManager::deleteUserFromTicketSystem($user_id); TicketManager::deleteUserFromTicketSystem($user_id);
} }
$tableExists = $connection->getSchemaManager()->tablesExist(['c_lp_category_user']); $tableExists = $schemaManager->tablesExist(['c_lp_category_user']);
if ($tableExists) { if ($tableExists) {
$sql = "DELETE FROM c_lp_category_user WHERE user_id = $user_id"; $sql = "DELETE FROM c_lp_category_user WHERE user_id = $user_id";
Database::query($sql); Database::query($sql);

@ -59,7 +59,7 @@ $sql = "SELECT u.id, firstname, lastname, ev.value ville, ev2.value stage
(ev.value LIKE '%::%' OR ev2.value LIKE '%::%') (ev.value LIKE '%::%' OR ev2.value LIKE '%::%')
"; ";
$cacheDriver = new \Doctrine\Common\Cache\ApcuCache(); $cache = new \Symfony\Component\Cache\Adapter\ApcuAdapter();
$keyDate = 'map_cache_date'; $keyDate = 'map_cache_date';
$keyData = 'map_cache_data'; $keyData = 'map_cache_data';
@ -70,8 +70,8 @@ $now = time();
$tomorrow = strtotime('+5 minute', $now); $tomorrow = strtotime('+5 minute', $now);
$loadFromDatabase = true; $loadFromDatabase = true;
if ($cacheDriver->contains($keyData) && $cacheDriver->contains($keyDate)) { if ($cache->hasItem($keyData) && $cache->hasItem($keyDate)) {
$savedDate = $cacheDriver->fetch($keyDate); $savedDate = $cache->getItem($keyDate)->get();
$loadFromDatabase = false; $loadFromDatabase = false;
if ($savedDate < $now) { if ($savedDate < $now) {
$loadFromDatabase = true; $loadFromDatabase = true;
@ -83,10 +83,15 @@ if ($loadFromDatabase) {
$result = Database::query($sql); $result = Database::query($sql);
$data = Database::store_result($result, 'ASSOC'); $data = Database::store_result($result, 'ASSOC');
$cacheDriver->save($keyData, $data); $cacheItem = $cache->getItem($keyData);
$cacheDriver->save($keyDate, $tomorrow); $cacheItem->set($data);
$cache->save($cacheItem);
$cacheItem = $cache->getItem($keyDate);
$cacheItem->set($tomorrow);
$cache->save($cacheItem);
} else { } else {
$data = $cacheDriver->fetch($keyData); $data = $cache->getItem($keyData)->get();
} }
foreach ($data as &$result) { foreach ($data as &$result) {

@ -15,7 +15,6 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\User\UserInterface;
#[AsController] #[AsController]
abstract class AbstractFeedbackSocialPostController extends AbstractController abstract class AbstractFeedbackSocialPostController extends AbstractController

@ -39,6 +39,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Exception\ValidatorException;
use UserManager; use UserManager;
@ -48,6 +49,10 @@ use UserManager;
#[Route('/course')] #[Route('/course')]
class CourseController extends ToolBaseController class CourseController extends ToolBaseController
{ {
public function __construct(private SerializerInterface $serializer)
{
}
#[Route('/{cid}/checkLegal.json', name: 'chamilo_core_course_check_legal_json')] #[Route('/{cid}/checkLegal.json', name: 'chamilo_core_course_check_legal_json')]
public function checkTermsAndConditionJson(Request $request, LegalRepository $legalTermsRepo, LanguageRepository $languageRepository): Response public function checkTermsAndConditionJson(Request $request, LegalRepository $legalTermsRepo, LanguageRepository $languageRepository): Response
{ {
@ -119,7 +124,7 @@ class CourseController extends ToolBaseController
} }
} }
$json = $this->get('serializer')->serialize( $json = $this->serializer->serialize(
$responseData, $responseData,
'json', 'json',
[ [
@ -288,7 +293,7 @@ class CourseController extends ToolBaseController
'tools' => $tools, 'tools' => $tools,
]; ];
$json = $this->get('serializer')->serialize( $json = $this->serializer->serialize(
$responseData, $responseData,
'json', 'json',
[ [

@ -7,6 +7,8 @@ namespace Chamilo\CoreBundle\Controller;
use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Form\ChangePasswordFormType; use Chamilo\CoreBundle\Form\ChangePasswordFormType;
use Chamilo\CoreBundle\Form\ResetPasswordRequestFormType; use Chamilo\CoreBundle\Form\ResetPasswordRequestFormType;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
@ -27,8 +29,11 @@ class ResetPasswordController extends AbstractController
private ResetPasswordHelperInterface $resetPasswordHelper; private ResetPasswordHelperInterface $resetPasswordHelper;
public function __construct(ResetPasswordHelperInterface $resetPasswordHelper) public function __construct(
{ ResetPasswordHelperInterface $resetPasswordHelper,
private EntityManagerInterface $entityManager,
private UserRepository $userRepository
) {
$this->resetPasswordHelper = $resetPasswordHelper; $this->resetPasswordHelper = $resetPasswordHelper;
} }
@ -115,7 +120,7 @@ class ResetPasswordController extends AbstractController
); );
$user->setPassword($encodedPassword); $user->setPassword($encodedPassword);
$this->getDoctrine()->getManager()->flush(); $this->entityManager->flush();
// The session is cleaned up after the password has been changed. // The session is cleaned up after the password has been changed.
$this->cleanSessionAfterReset(); $this->cleanSessionAfterReset();
@ -130,7 +135,7 @@ class ResetPasswordController extends AbstractController
private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse
{ {
$user = $this->getDoctrine()->getRepository(User::class)->findOneBy([ $user = $this->userRepository->findOneBy([
'email' => $emailFormData, 'email' => $emailFormData,
]); ]);

@ -20,6 +20,7 @@ use Chamilo\CoreBundle\Repository\SequenceRepository;
use Chamilo\CoreBundle\Repository\TagRepository; use Chamilo\CoreBundle\Repository\TagRepository;
use Chamilo\CourseBundle\Entity\CCourseDescription; use Chamilo\CourseBundle\Entity\CCourseDescription;
use CourseDescription; use CourseDescription;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Essence\Essence; use Essence\Essence;
use ExtraFieldValue; use ExtraFieldValue;
@ -39,11 +40,15 @@ class SessionController extends AbstractController
* *
* @Entity("session", expr="repository.find(sid)") * @Entity("session", expr="repository.find(sid)")
*/ */
public function aboutAction(Request $request, Session $session, IllustrationRepository $illustrationRepo, UserRepository $userRepo): Response public function aboutAction(
{ Request $request,
Session $session,
IllustrationRepository $illustrationRepo,
UserRepository $userRepo,
EntityManagerInterface $em
): Response {
$requestSession = $request->getSession(); $requestSession = $request->getSession();
$htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js'); $htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js');
$em = $this->getDoctrine()->getManager();
$sessionId = $session->getId(); $sessionId = $session->getId();
$courses = []; $courses = [];

Loading…
Cancel
Save