Commit 370ff1a8 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASk] Code cleanups

parent 39325c65
......@@ -77,11 +77,11 @@ class ConfigurationService extends AbstractService {
* @return array
* @throws \InvalidArgumentException
*/
public function prepareConfig() {
public function prepareConfig(): array {
if (!empty($this->extConfig)) {
return $this->extConfig;
}
$this->extConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['lfeditor']);
$this->extConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['lfeditor'], []);
// regular expressions
if (!preg_match('/^\/.*\/.*$/', $this->extConfig['searchRegex'])) {
......@@ -154,7 +154,7 @@ class ConfigurationService extends AbstractService {
$this->extConfig['defaultLanguage'] = 'default';
} else {
/** @var Locales $locales */
$locales = GeneralUtility::makeInstance('TYPO3\CMS\Core\Localization\Locales');
$locales = GeneralUtility::makeInstance(Locales::class);
$availableLanguageKeys = $locales->getLanguages();
if (!isset($availableLanguageKeys[$this->extConfig['defaultLanguage']])) {
$this->extConfig['defaultLanguage'] = 'default';
......@@ -171,13 +171,13 @@ class ConfigurationService extends AbstractService {
* @throws LFException raised if no extensions are found
* @return array
*/
public function menuExtList() {
public function menuExtList(): array {
// search extensions
$tmpExtList = [];
try {
// local extensions
if ($this->extConfig['viewLocalExt']) {
if (count(
if (\count(
$content = Functions::searchExtensions(
PATH_site . Typo3Lib::pathLocalExt, $this->extConfig['viewStateExt'],
$this->extConfig['extIgnore']
......@@ -190,7 +190,7 @@ class ConfigurationService extends AbstractService {
// global extensions
if ($this->extConfig['viewGlobalExt'] && is_dir(Typo3Lib::pathGlobalExt)) {
if (count(
if (\count(
$content = Functions::searchExtensions(
PATH_site . Typo3Lib::pathGlobalExt, $this->extConfig['viewStateExt'],
$this->extConfig['extIgnore']
......@@ -203,7 +203,7 @@ class ConfigurationService extends AbstractService {
// system extensions
if ($this->extConfig['viewSysExt']) {
if (count(
if (\count(
$content = Functions::searchExtensions(
PATH_site . Typo3Lib::pathSysExt, $this->extConfig['viewStateExt'],
$this->extConfig['extIgnore']
......@@ -218,7 +218,7 @@ class ConfigurationService extends AbstractService {
}
// check extension array
if (!count($tmpExtList)) {
if (!\count($tmpExtList)) {
throw new LFException('failure.search.noExtension');
}
......
......@@ -27,22 +27,25 @@ namespace SGalinski\Lfeditor\Utility;
***************************************************************/
use Exception;
use RuntimeException;
use TYPO3\CMS\Core\Charset\CharsetConverter;
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
/**
* includes special typo3 methods
*/
class Typo3Lib {
const pathLocalExt = 'typo3conf/ext/';
public const pathLocalExt = 'typo3conf/ext/';
const pathGlobalExt = 'typo3/ext/';
public const pathGlobalExt = 'typo3/ext/';
const pathSysExt = 'typo3/sysext/';
public const pathSysExt = 'typo3/sysext/';
const pathL10n = 'typo3conf/l10n/';
public const pathL10n = 'typo3conf/l10n/';
/**
* checks the file location type
......@@ -50,18 +53,24 @@ class Typo3Lib {
* @param string $file
* @return string
*/
public static function checkFileLocation($file) {
if (strpos($file, Typo3Lib::pathLocalExt) !== FALSE) {
public static function checkFileLocation($file): ?string {
if (strpos($file, self::pathLocalExt) !== FALSE) {
return 'local';
} elseif (strpos($file, Typo3Lib::pathGlobalExt) !== FALSE) {
}
if (strpos($file, self::pathGlobalExt) !== FALSE) {
return 'global';
} elseif (strpos($file, Typo3Lib::pathSysExt) !== FALSE) {
}
if (strpos($file, self::pathSysExt) !== FALSE) {
return 'system';
} elseif (strpos($file, Typo3Lib::pathL10n) !== FALSE) {
}
if (strpos($file, self::pathL10n) !== FALSE) {
return 'l10n';
} else {
return '';
}
return '';
}
/**
......@@ -72,38 +81,40 @@ class Typo3Lib {
* @param boolean $mode generate to relative(false) or absolute file
* @return string converted file path
*/
public static function transTypo3File($file, $mode) {
$extType['local'] = Typo3Lib::pathLocalExt;
$extType['global'] = Typo3Lib::pathGlobalExt;
$extType['system'] = Typo3Lib::pathSysExt;
public static function transTypo3File($file, $mode): ?string {
$extType['local'] = self::pathLocalExt;
$extType['global'] = self::pathGlobalExt;
$extType['system'] = self::pathSysExt;
// relative to absolute
if ($mode) {
if (strpos($file, 'EXT:') === FALSE) {
throw new Exception('no typo3 relative path "' . $file . '"');
throw new RuntimeException('no typo3 relative path "' . $file . '"');
}
$cleanFile = SgLib::trimPath('EXT:', $file);
/** @var string[] $extType */
foreach ($extType as $type) {
$path = Typo3Lib::fixFilePath(PATH_site . '/' . $type . '/' . $cleanFile);
if (is_dir(dirname($path))) {
$path = self::fixFilePath(PATH_site . '/' . $type . '/' . $cleanFile);
if (is_dir(\dirname($path))) {
return $path;
}
}
throw new Exception('cant convert typo3 relative file "' . $file . '"');
} else // absolute to relative
{
foreach ($extType as $type) {
if (strpos($file, $type) === FALSE) {
continue;
}
throw new RuntimeException('cant convert typo3 relative file "' . $file . '"');
}
return 'EXT:' . SgLib::trimPath($type, SgLib::trimPath(PATH_site, $file));
// absolute to relative
/** @var string[] $extType */
foreach ($extType as $type) {
if (strpos($file, $type) === FALSE) {
continue;
}
throw new Exception('cant convert absolute file "' . $file . '"');
return 'EXT:' . SgLib::trimPath($type, SgLib::trimPath(PATH_site, $file));
}
throw new RuntimeException('cant convert absolute file "' . $file . '"');
}
/**
......@@ -112,7 +123,7 @@ class Typo3Lib {
* @param string $file file
* @return string fixed file
*/
public static function fixFilePath($file) {
public static function fixFilePath($file): string {
return GeneralUtility::fixWindowsFilePath(str_replace('//', '/', $file));
}
......@@ -123,10 +134,11 @@ class Typo3Lib {
* @param boolean $mode to utf-8 (true) or to original charset (false)
* @param array $ignoreKeys language keys to ignore
* @return array decoded or encoded language content array
* @throws \InvalidArgumentException
*/
public static function utf8($localLang, $mode, $ignoreKeys) {
public static function utf8($localLang, $mode, $ignoreKeys): array {
// check
if (!is_array($localLang) || !count($localLang)) {
if (!\is_array($localLang) || !\count($localLang)) {
return $localLang;
}
......@@ -136,7 +148,7 @@ class Typo3Lib {
// loop all possible languages
foreach ($localLang as $langKey => $convContent) {
if (!is_array($convContent) || !count($convContent) || in_array($langKey, $ignoreKeys)) {
if (!\is_array($convContent) || !\count($convContent) || \in_array($langKey, $ignoreKeys, TRUE)) {
continue;
}
......@@ -145,7 +157,7 @@ class Typo3Lib {
$csConvObj->charSetArray[$langKey] : 'iso-8859-1'
);
if ($csConvObj->charSetArray[$langKey] == 'utf-8') {
if ($csConvObj->charSetArray[$langKey] === 'utf-8') {
continue;
}
......@@ -167,10 +179,10 @@ class Typo3Lib {
* @static
* @return bool
*/
public static function isTypo3BackendInUtf8Mode() {
public static function isTypo3BackendInUtf8Mode(): bool {
$isInUtf8Mode = FALSE;
$isTypo347 = (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 4007000);
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] === 'utf-8' || $isTypo347) {
if ($isTypo347 || $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] === 'utf-8') {
$isInUtf8Mode = TRUE;
}
......@@ -182,13 +194,12 @@ class Typo3Lib {
*
* @param string $configLine line to be added.
* @return void
* @throws \InvalidArgumentException
*/
public static function writeLineToAdditionalConfiguration($configLine) {
public static function writeLineToAdditionalConfiguration($configLine): void {
/** @var ConfigurationManager $configurationManager */
$configurationManager = GeneralUtility::makeInstance('TYPO3\CMS\Core\Configuration\ConfigurationManager');
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$additionalConfigurationFilePath = $configurationManager->getAdditionalConfigurationFileLocation();
SgLib::appendToPHPFile($additionalConfigurationFilePath, $configLine);
}
}
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment