Add declare(strict_types=1), fix type hints

pull/3844/head
Julio Montoya 5 years ago
parent 7b0d7d4e0d
commit 06a8ecaf2b
  1. 6
      src/CoreBundle/Component/HTMLPurifier/Filter/AllowIframes.php
  2. 20
      src/CoreBundle/Component/Resource/Settings.php
  3. 38
      src/CoreBundle/Component/Resource/Template.php
  4. 28
      src/CoreBundle/Component/Utils/AssetDirectoryNamer.php
  5. 73
      src/CoreBundle/Component/Utils/ChamiloApi.php
  6. 9
      src/CoreBundle/Component/Utils/Glide.php

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Component\HTMLPurifier\Filter;
@ -73,8 +75,8 @@ class AllowIframes extends HTMLPurifier_Filter
}
return '<iframe '.$matches[1].$extra.'></iframe>';
} else {
return '';
}
return '';
}
}

@ -1,23 +1,21 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Component\Resource;
class Settings
{
/** @var bool */
public $allowNodeCreation;
/** @var bool */
public $allowResourceCreation;
/** @var bool */
public $allowResourceUpload;
/** @var bool */
public $allowResourceEdit;
public $allowDownloadAll;
public $allowDiskSpace;
public bool $allowNodeCreation;
public bool $allowResourceCreation;
public bool $allowResourceUpload;
public bool $allowResourceEdit;
public bool $allowDownloadAll;
public bool $allowDiskSpace;
// Shows an extra ckeditor input to save the HTML content into a ResourceFile.
public $allowToSaveEditorToResourceFile;
public bool $allowToSaveEditorToResourceFile;
public $templates;
public function __construct()

@ -1,22 +1,36 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Component\Resource;
use InvalidArgumentException;
class Template
{
protected $index;
protected $list;
protected $edit;
protected $viewResource;
protected $new;
protected $newFolder;
protected $diskSpace;
protected $info;
protected $infoAjax;
protected $preview;
protected $upload;
protected string $index;
protected string $list;
protected string $edit;
protected string $viewResource;
protected string $new;
protected string $newFolder;
protected string $diskSpace;
protected string $info;
protected string $infoAjax;
protected string $preview;
protected string $upload;
public function __construct()
{
@ -46,7 +60,7 @@ class Template
return $this->$action;
}
throw new \InvalidArgumentException("No template found for action: $action");
throw new InvalidArgumentException("No template found for action: $action");
}
public function setIndex(string $index): self

@ -1,28 +1,28 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Component\Utils;
use Chamilo\CoreBundle\Entity\Asset;
use InvalidArgumentException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Vich\UploaderBundle\Mapping\PropertyMapping;
use Vich\UploaderBundle\Naming\ConfigurableInterface;
use Vich\UploaderBundle\Naming\DirectoryNamerInterface;
use function array_merge;
use function implode;
use function substr;
class AssetDirectoryNamer implements DirectoryNamerInterface, ConfigurableInterface
{
/**
* @var PropertyAccessorInterface
*/
protected $propertyAccessor;
/**
* @var string
*/
private $propertyPath;
private $charsPerDir = 2;
private $dirs = 1;
protected PropertyAccessorInterface $propertyAccessor;
private string $propertyPath;
private int $charsPerDir = 2;
private int $dirs = 1;
public function __construct(?PropertyAccessorInterface $propertyAccessor)
{
@ -37,12 +37,12 @@ class AssetDirectoryNamer implements DirectoryNamerInterface, ConfigurableInterf
public function configure(array $options): void
{
if (empty($options['property'])) {
throw new \InvalidArgumentException('Option "property" is missing or empty.');
throw new InvalidArgumentException('Option "property" is missing or empty.');
}
$this->propertyPath = $options['property'];
$options = \array_merge(['chars_per_dir' => $this->charsPerDir, 'dirs' => $this->dirs], $options);
$options = array_merge(['chars_per_dir' => $this->charsPerDir, 'dirs' => $this->dirs], $options);
$this->charsPerDir = $options['chars_per_dir'];
$this->dirs = $options['dirs'];
@ -57,12 +57,12 @@ class AssetDirectoryNamer implements DirectoryNamerInterface, ConfigurableInterf
if (Asset::EXTRA_FIELD === $category) {
for ($i = 0, $start = 0; $i < $this->dirs; $i++, $start += $this->charsPerDir) {
$parts[] = \substr($fileName, $start, $this->charsPerDir);
$parts[] = substr($fileName, $start, $this->charsPerDir);
}
} else {
$parts[] = $fileName;
}
return \implode('/', $parts);
return implode('/', $parts);
}
}

@ -1,10 +1,19 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Component\Utils;
use ChamiloSession as Session;
use Database;
use DateInterval;
use DateTime;
use DateTimeZone;
use Display;
use Exception;
use Template;
class ChamiloApi
{
@ -83,7 +92,7 @@ class ChamiloApi
$accessUrlId = $accessUrl;
}
}
$themeDir = \Template::getThemeDir($theme);
$themeDir = Template::getThemeDir($theme);
$customLogoPath = $themeDir."images/header-logo-custom$accessUrlId.png";
$svgIcons = api_get_setting('icons_mode_svg');
@ -91,25 +100,18 @@ class ChamiloApi
$customLogoPathSVG = substr($customLogoPath, 0, -3).'svg';
if (file_exists(api_get_path(SYS_PUBLIC_PATH)."css/$customLogoPathSVG")) {
if ($getSysPath) {
$logoPath = api_get_path(SYS_PUBLIC_PATH)."css/$customLogoPathSVG";
return $logoPath;
return api_get_path(SYS_PUBLIC_PATH)."css/$customLogoPathSVG";
}
$logoPath = api_get_path(WEB_CSS_PATH).$customLogoPathSVG;
return $logoPath;
return api_get_path(WEB_CSS_PATH).$customLogoPathSVG;
}
}
if (file_exists(api_get_path(SYS_PUBLIC_PATH)."css/$customLogoPath")) {
if ($getSysPath) {
$logoPath = api_get_path(SYS_PUBLIC_PATH)."css/$customLogoPath";
return $logoPath;
return api_get_path(SYS_PUBLIC_PATH)."css/$customLogoPath";
}
$logoPath = api_get_path(WEB_CSS_PATH).$customLogoPath;
return $logoPath;
return api_get_path(WEB_CSS_PATH).$customLogoPath;
}
$originalLogoPath = $themeDir.'images/header-logo.png';
@ -117,26 +119,19 @@ class ChamiloApi
$originalLogoPathSVG = $themeDir.'images/header-logo.svg';
if (file_exists(api_get_path(SYS_CSS_PATH).$originalLogoPathSVG)) {
if ($getSysPath) {
$logoPath = api_get_path(SYS_CSS_PATH).$originalLogoPathSVG;
return $logoPath;
return api_get_path(SYS_CSS_PATH).$originalLogoPathSVG;
}
$logoPath = api_get_path(WEB_CSS_PATH).$originalLogoPathSVG;
return $logoPath;
return api_get_path(WEB_CSS_PATH).$originalLogoPathSVG;
}
}
if (file_exists(api_get_path(SYS_CSS_PATH).$originalLogoPath)) {
if ($getSysPath) {
$logoPath = api_get_path(SYS_CSS_PATH).$originalLogoPath;
return $logoPath;
return api_get_path(SYS_CSS_PATH).$originalLogoPath;
}
$logoPath = api_get_path(WEB_CSS_PATH).$originalLogoPath;
return $logoPath;
return api_get_path(WEB_CSS_PATH).$originalLogoPath;
}
$logoPath = '';
}
@ -167,10 +162,10 @@ class ChamiloApi
$siteName = api_get_setting('siteName');
if (null === $logoPath) {
$headerLogo = \Display::url($siteName, api_get_path(WEB_PATH).'index.php');
$headerLogo = Display::url($siteName, api_get_path(WEB_PATH).'index.php');
if (!empty($institutionUrl) && !empty($institution)) {
$headerLogo .= ' - '.\Display::url($institution, $institutionUrl);
$headerLogo .= ' - '.Display::url($institution, $institutionUrl);
}
$courseInfo = api_get_course_info();
@ -178,7 +173,7 @@ class ChamiloApi
$headerLogo .= '<span class="extLinkSeparator"> - </span>';
if (!empty($courseInfo['extLink']['url'])) {
$headerLogo .= \Display::url(
$headerLogo .= Display::url(
$courseInfo['extLink']['name'],
$courseInfo['extLink']['url'],
['class' => 'extLink']
@ -188,12 +183,12 @@ class ChamiloApi
}
}
return \Display::tag('h2', $headerLogo, ['class' => 'text-left']);
return Display::tag('h2', $headerLogo, ['class' => 'text-left']);
}
$image = \Display::img($logoPath, $institution, $imageAttributes);
$image = Display::img($logoPath, $institution, $imageAttributes);
return \Display::url($image, api_get_path(WEB_PATH).'index.php');
return Display::url($image, api_get_path(WEB_PATH).'index.php');
}
/**
@ -208,7 +203,7 @@ class ChamiloApi
{
foreach ($tags as $tag) {
$string2 = preg_replace('#</\b'.$tag.'\b[^>]*>#i', ' ', $string);
if ($string2 != $string) {
if ($string2 !== $string) {
$string = preg_replace('/<\b'.$tag.'\b[^>]*>/i', ' ', $string2);
}
}
@ -227,14 +222,14 @@ class ChamiloApi
*/
public static function addOrSubTimeToDateTime($time, $datetime = 'now', $operation = true)
{
$date = new \DateTime($datetime);
$date = new DateTime($datetime);
$hours = $minutes = $seconds = 0;
sscanf($time, '%d:%d:%d', $hours, $minutes, $seconds);
$timeSeconds = isset($seconds) ? $hours * 3600 + $minutes * 60 + $seconds : $hours * 60 + $minutes;
if ($operation) {
$date->add(new \DateInterval('PT'.$timeSeconds.'S'));
$date->add(new DateInterval('PT'.$timeSeconds.'S'));
} else {
$date->sub(new \DateInterval('PT'.$timeSeconds.'S'));
$date->sub(new DateInterval('PT'.$timeSeconds.'S'));
}
return $date->format('Y-m-d H:i:s');
@ -250,10 +245,10 @@ class ChamiloApi
public static function getCourseIdByDirectory($directory = null)
{
if (!empty($directory)) {
$directory = \Database::escape_string($directory);
$row = \Database::select(
$directory = Database::escape_string($directory);
$row = Database::select(
'id',
\Database::get_main_table(TABLE_MAIN_COURSE),
Database::get_main_table(TABLE_MAIN_COURSE),
['where' => ['directory = ?' => [$directory]]],
'first'
);
@ -386,16 +381,16 @@ class ChamiloApi
* @param string|null $utcTime Optional. The time to ve converted.
* See api_get_local_time.
*
* @throws \Exception
* @throws Exception
*
* @return \DateTime
* @return DateTime
*/
public static function getServerMidnightTime($utcTime = null)
{
$localTime = api_get_local_time($utcTime);
$localTimeZone = api_get_timezone();
$localMidnight = new \DateTime($localTime, new \DateTimeZone($localTimeZone));
$localMidnight = new DateTime($localTime, new DateTimeZone($localTimeZone));
$localMidnight->modify('midnight');
return $localMidnight;

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Component\Utils;
@ -8,13 +10,10 @@ use League\Glide\Responses\SymfonyResponseFactory;
use League\Glide\Server;
use League\Glide\ServerFactory;
/**
* Class Glide.
*/
class Glide
{
protected $server;
protected $filters;
protected Server $server;
protected array $filters;
/**
* Glide constructor.

Loading…
Cancel
Save