From 4e96534806bd92d13f6aa0523309518c2c0dd4f6 Mon Sep 17 00:00:00 2001 From: Julio Date: Thu, 19 Dec 2019 10:32:11 +0100 Subject: [PATCH] Remove unused code, refactor code. --- psalm.xml | 17 ++++++++-------- .../Controller/ContactController.php | 15 ++++++++------ .../Component/CourseCopy/CourseBuilder.php | 12 +++++------ .../Component/CourseCopy/CourseRestorer.php | 20 +++++++++---------- .../Repository/CAnnouncementRepository.php | 2 +- .../Manager/SettingsManager.php | 2 +- .../Controller/ExceptionController.php | 1 + src/ThemeBundle/Event/MessageListEvent.php | 2 +- .../Event/NotificationListEvent.php | 2 +- src/ThemeBundle/Event/TaskListEvent.php | 2 +- .../EventListener/TwigListener.php | 2 +- src/ThemeBundle/Model/MenuItemModel.php | 2 +- src/ThemeBundle/Theme/ThemeManager.php | 11 ++++------ src/UserBundle/Entity/User.php | 11 ---------- src/UserBundle/Repository/UserRepository.php | 15 ++------------ 15 files changed, 47 insertions(+), 69 deletions(-) diff --git a/psalm.xml b/psalm.xml index c45365b408..aa51a7ed57 100644 --- a/psalm.xml +++ b/psalm.xml @@ -12,7 +12,6 @@ - @@ -20,15 +19,15 @@ - - - - + + + + - - - - + + + + diff --git a/src/ContactBundle/Controller/ContactController.php b/src/ContactBundle/Controller/ContactController.php index a3580d8bd1..fbb708b9e4 100644 --- a/src/ContactBundle/Controller/ContactController.php +++ b/src/ContactBundle/Controller/ContactController.php @@ -9,6 +9,8 @@ use Chamilo\ContactBundle\Form\Type\ContactType; use Chamilo\UserBundle\Entity\User; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Mailer\MailerInterface; +use Symfony\Component\Mime\Email; use Symfony\Component\Routing\Annotation\Route; /** @@ -21,7 +23,7 @@ class ContactController extends AbstractController /** * @Route("/", name="contact") */ - public function indexAction(Request $request) + public function indexAction(Request $request, MailerInterface $mailer) { /** @var User $user */ $user = $this->getUser(); @@ -47,10 +49,10 @@ class ContactController extends AbstractController $category = $em->getRepository('ChamiloContactBundle:Category')->find($category); if ($form->isValid()) { - $message = \Swift_Message::newInstance() - ->setSubject($form->get('subject')->getData()) - ->setFrom($form->get('email')->getData()) - ->setTo($category->getEmail()) + $message = new Email(); + $message->subject($form->get('subject')->getData()) + ->from($form->get('email')->getData()) + ->to($category->getEmail()) ->setBody( $this->renderView( '@ChamiloContact/contact.html.twig', @@ -65,7 +67,8 @@ class ContactController extends AbstractController ) ); - $this->get('mailer')->send($message); + $mailer->send($message); + $this->addFlash( 'success', $this->get('translator')->trans('Your email has been sent! Thanks!') diff --git a/src/CourseBundle/Component/CourseCopy/CourseBuilder.php b/src/CourseBundle/Component/CourseCopy/CourseBuilder.php index b3df251801..651e81c55a 100644 --- a/src/CourseBundle/Component/CourseCopy/CourseBuilder.php +++ b/src/CourseBundle/Component/CourseCopy/CourseBuilder.php @@ -589,8 +589,8 @@ class CourseBuilder $courseId = (int) $courseId; $sql = "SELECT * FROM $table WHERE c_id = $courseId "; if (!empty($thread_id) && !empty($forum_id)) { - $forum_id = intval($forum_id); - $thread_id = intval($thread_id); + $forum_id = (int) $forum_id; + $thread_id = (int) $thread_id; $sql .= " AND thread_id = $thread_id AND forum_id = $forum_id "; } @@ -1349,7 +1349,7 @@ class CourseBuilder $courseId = (int) $courseId; if (!empty($session_id) && !empty($courseId)) { - $session_id = intval($session_id); + $session_id = (int) $session_id; if ($withBaseContent) { $sessionCondition = api_get_session_condition( $session_id, @@ -1573,7 +1573,7 @@ class CourseBuilder $courseId = (int) $courseId; if (!empty($session_id) && !empty($courseId)) { - $session_id = intval($session_id); + $session_id = (int) $session_id; if ($withBaseContent) { $sessionCondition = api_get_session_condition( $session_id, @@ -1670,7 +1670,7 @@ class CourseBuilder $courseId = (int) $courseId; if (!empty($session_id) && !empty($courseId)) { - $session_id = intval($session_id); + $session_id = (int) $session_id; if ($withBaseContent) { $sessionCondition = api_get_session_condition( $session_id, @@ -1728,7 +1728,7 @@ class CourseBuilder $courseId = (int) $courseId; $courseInfo = api_get_course_info_by_id($courseId); - $session_id = intval($session_id); + $session_id = (int) $session_id; if ($withBaseContent) { $sessionCondition = api_get_session_condition( $session_id, diff --git a/src/CourseBundle/Component/CourseCopy/CourseRestorer.php b/src/CourseBundle/Component/CourseCopy/CourseRestorer.php index 9b48d7c2af..15a1203f31 100644 --- a/src/CourseBundle/Component/CourseCopy/CourseRestorer.php +++ b/src/CourseBundle/Component/CourseCopy/CourseRestorer.php @@ -878,7 +878,7 @@ class CourseRestorer if (is_file($this->course->backup_path.'/'.$document->path) && is_readable($this->course->backup_path.'/'.$document->path) && is_dir(dirname($path.$document->path)) && - is_writeable(dirname($path.$document->path)) + is_writable(dirname($path.$document->path)) ) { copy( $this->course->backup_path.'/'.$document->path, @@ -970,7 +970,7 @@ class CourseRestorer dirname($path.$document->path).': destination directory not found' ); } - if (!is_writeable(dirname($path.$document->path))) { + if (!is_writable(dirname($path.$document->path))) { error_log( 'Course copy generated an ignorable error while trying to copy '. $this->course->backup_path.'/'.$document->path.' to '. @@ -1188,7 +1188,7 @@ class CourseRestorer $this->course->backup_path, $this->course->info['path'] ); - $params['session_id'] = intval($sessionId); + $params['session_id'] = (int) $sessionId; $params['cat_id'] = 0; unset($params['iid']); @@ -1239,7 +1239,7 @@ class CourseRestorer $params['thread_last_post'] = 0; $params['thread_replies'] = 0; $params['thread_views'] = 0; - $params['session_id'] = intval($sessionId); + $params['session_id'] = (int) $sessionId; $params['thread_id'] = 0; unset($params['iid']); @@ -1348,7 +1348,7 @@ class CourseRestorer FROM $link_table WHERE c_id = ".$this->destination_course_id." AND - category_id='".intval($cat_id)."'"; + category_id='".(int) $cat_id."'"; $result = Database::query($sql); list($max_order) = Database::fetch_array($result); @@ -3138,12 +3138,12 @@ class CourseRestorer 'reflink' => self::DBUTF8($wiki->reflink), 'title' => self::DBUTF8($wiki->title), 'content' => false === $wiki->content ? '' : self::DBUTF8($wiki->content), - 'user_id' => intval($wiki->user_id), - 'group_id' => intval($wiki->group_id), + 'user_id' => (int) ($wiki->user_id), + 'group_id' => (int) ($wiki->group_id), 'dtime' => self::DBUTF8($wiki->dtime), 'progress' => self::DBUTF8($wiki->progress), - 'version' => intval($wiki->version), - 'session_id' => !empty($session_id) ? intval($session_id) : 0, + 'version' => (int) ($wiki->version), + 'session_id' => !empty($session_id) ? (int) $session_id : 0, 'addlock' => 0, 'editlock' => 0, 'visibility' => 0, @@ -3585,7 +3585,7 @@ class CourseRestorer if (is_file($this->course->backup_path.'/'.$asset->path) && is_readable($this->course->backup_path.'/'.$asset->path) && is_dir(dirname($path.$asset->path)) && - is_writeable(dirname($path.$asset->path)) + is_writable(dirname($path.$asset->path)) ) { switch ($this->file_option) { case FILE_SKIP: diff --git a/src/CourseBundle/Repository/CAnnouncementRepository.php b/src/CourseBundle/Repository/CAnnouncementRepository.php index c1391238f6..ea5a2c214b 100644 --- a/src/CourseBundle/Repository/CAnnouncementRepository.php +++ b/src/CourseBundle/Repository/CAnnouncementRepository.php @@ -173,7 +173,7 @@ final class CAnnouncementRepository extends ResourceRepository ->createQuery($dql) ->setParameters($parameters); - if (!is_null($start) && !is_null($limit)) { + if (null !== $start && null !== $limit) { $query ->setFirstResult($start) ->setMaxResults($limit); diff --git a/src/SettingsBundle/Manager/SettingsManager.php b/src/SettingsBundle/Manager/SettingsManager.php index f9fd440fd3..0f0b1c5f83 100644 --- a/src/SettingsBundle/Manager/SettingsManager.php +++ b/src/SettingsBundle/Manager/SettingsManager.php @@ -9,7 +9,6 @@ use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\SettingsCurrent; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; -//use Sylius\Bundle\ResourceBundle\Controller\EventDispatcherInterface; use Sylius\Bundle\SettingsBundle\Event\SettingsEvent; use Sylius\Bundle\SettingsBundle\Manager\SettingsManagerInterface; use Sylius\Bundle\SettingsBundle\Model\Settings; @@ -18,6 +17,7 @@ use Sylius\Bundle\SettingsBundle\Schema\SchemaInterface; use Sylius\Bundle\SettingsBundle\Schema\SettingsBuilder; use Sylius\Component\Registry\ServiceRegistryInterface; use Sylius\Component\Resource\Factory\FactoryInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Validator\ConstraintViolationListInterface; use Symfony\Component\Validator\Exception\ValidatorException; diff --git a/src/ThemeBundle/Controller/ExceptionController.php b/src/ThemeBundle/Controller/ExceptionController.php index 11fc59f1ce..1475d5c664 100644 --- a/src/ThemeBundle/Controller/ExceptionController.php +++ b/src/ThemeBundle/Controller/ExceptionController.php @@ -6,6 +6,7 @@ namespace Chamilo\ThemeBundle\Controller; use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Templating\TemplateReference; /** * Class ExceptionController. diff --git a/src/ThemeBundle/Event/MessageListEvent.php b/src/ThemeBundle/Event/MessageListEvent.php index 48ef67b220..20e2995ec1 100644 --- a/src/ThemeBundle/Event/MessageListEvent.php +++ b/src/ThemeBundle/Event/MessageListEvent.php @@ -58,6 +58,6 @@ class MessageListEvent extends ThemeEvent */ public function getTotal() { - return 0 == $this->totalMessages ? sizeof($this->messages) : $this->totalMessages; + return 0 == $this->totalMessages ? count($this->messages) : $this->totalMessages; } } diff --git a/src/ThemeBundle/Event/NotificationListEvent.php b/src/ThemeBundle/Event/NotificationListEvent.php index f74524b824..0f3d542762 100644 --- a/src/ThemeBundle/Event/NotificationListEvent.php +++ b/src/ThemeBundle/Event/NotificationListEvent.php @@ -52,6 +52,6 @@ class NotificationListEvent extends ThemeEvent */ public function getTotal() { - return 0 == $this->total ? sizeof($this->notifications) : $this->total; + return 0 == $this->total ? count($this->notifications) : $this->total; } } diff --git a/src/ThemeBundle/Event/TaskListEvent.php b/src/ThemeBundle/Event/TaskListEvent.php index 1d30fd5887..2c607414ac 100644 --- a/src/ThemeBundle/Event/TaskListEvent.php +++ b/src/ThemeBundle/Event/TaskListEvent.php @@ -49,6 +49,6 @@ class TaskListEvent extends ThemeEvent */ public function getTotal() { - return 0 == $this->total ? sizeof($this->tasks) : $this->total; + return 0 == $this->total ? count($this->tasks) : $this->total; } } diff --git a/src/ThemeBundle/EventListener/TwigListener.php b/src/ThemeBundle/EventListener/TwigListener.php index 2af28c6d3a..5ceaa8e76a 100644 --- a/src/ThemeBundle/EventListener/TwigListener.php +++ b/src/ThemeBundle/EventListener/TwigListener.php @@ -170,7 +170,7 @@ class TwigListener implements EventSubscriberInterface foreach ($courseRegions as $subRegion) { if (!empty($courseInfo)) { if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof \Plugin) { - /** @var Plugin $plugin */ + /** @var \Plugin $plugin */ $plugin = $pluginInfo['obj']; $regionListContent[$subRegion][] = $plugin->renderRegion($subRegion); } diff --git a/src/ThemeBundle/Model/MenuItemModel.php b/src/ThemeBundle/Model/MenuItemModel.php index 635980f84c..c55111f834 100644 --- a/src/ThemeBundle/Model/MenuItemModel.php +++ b/src/ThemeBundle/Model/MenuItemModel.php @@ -253,7 +253,7 @@ class MenuItemModel implements MenuItemInterface */ public function hasChildren() { - return sizeof($this->children) > 0; + return count($this->children) > 0; } /** diff --git a/src/ThemeBundle/Theme/ThemeManager.php b/src/ThemeBundle/Theme/ThemeManager.php index 41a2a0792f..540041fc0c 100644 --- a/src/ThemeBundle/Theme/ThemeManager.php +++ b/src/ThemeBundle/Theme/ThemeManager.php @@ -54,36 +54,33 @@ class ThemeManager implements ContainerAwareInterface public function getScripts($location = 'bottom') { - $unsorted = []; + /*$unsorted = []; $srcList = []; foreach ($this->javascripts as $id => $scriptDefinition) { if ($scriptDefinition['location'] == $location) { $unsorted[$id] = $scriptDefinition; } } - $queue = $this->getResolver()->register($unsorted)->resolveAll(); foreach ($queue as $def) { $srcList[] = $def['src']; } - return $srcList; + return $srcList;*/ } public function getStyles() { + /* $srcList = []; $queue = $this->getResolver()->register($this->stylesheets)->resolveAll(); foreach ($queue as $def) { $srcList[] = $def['src']; } - return $srcList; + return $srcList;*/ } - /** - * @return DependencyResolverInterface - */ protected function getResolver() { $class = $this->resolverClass; diff --git a/src/UserBundle/Entity/User.php b/src/UserBundle/Entity/User.php index 9b5e68ac36..927cfe64b4 100644 --- a/src/UserBundle/Entity/User.php +++ b/src/UserBundle/Entity/User.php @@ -1872,17 +1872,6 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement return true; } - public function getPictureLegacy(): string - { - $id = $this->id; - $uri = $this->getPictureUri(); - if ($uri) { - return 'users/'.substr((string) $id, 0, 1).'/'.$id.'/'.'small_'.$uri; - } - - return ''; - } - /** * Get sentMessages. * diff --git a/src/UserBundle/Repository/UserRepository.php b/src/UserBundle/Repository/UserRepository.php index 0bd0260f95..8980b7b186 100644 --- a/src/UserBundle/Repository/UserRepository.php +++ b/src/UserBundle/Repository/UserRepository.php @@ -460,9 +460,9 @@ class UserRepository extends ResourceRepository return $qb ->select('COUNT(a)') ->innerJoin('a.portals', 'u') - ->where('u.portal = :u and u.group = :g') + ->where('u.portal = :u') ->andWhere($qb->expr()->in('a.roles', ['ROLE_TEACHER'])) - ->setParameters(['u' => $url, 'g' => $group]) + ->setParameters(['u' => $url]) ->getQuery() ->getSingleScalarResult() ; @@ -625,17 +625,6 @@ class UserRepository extends ResourceRepository /** @var CourseRelUser $course */ foreach ($courses as $course) { $list[] = $course->getCourse()->getCode(); - $courseDir = api_get_path(SYS_COURSE_PATH).$course->getCourse()->getDirectory(); - $documentDir = $courseDir.'/document/chat_files/'; - if (is_dir($documentDir)) { - $fs = new Finder(); - $fs->files()->in($documentDir); - foreach ($fs as $file) { - $chatFiles[] = - $course->getCourse()->getDirectory().'/document/chat_files/'.$file->getFilename().' - '. - get_lang('This content is not accessible to you directly because of course-related access rules. If you require access to that data, please contact the Data Privacy Officer as defined in our privacy terms.'); - } - } } $user->setCourses($list);