diff --git a/application/Espo/Core/Acl.php b/application/Espo/Core/Acl.php index f734a57c27..de10256901 100644 --- a/application/Espo/Core/Acl.php +++ b/application/Espo/Core/Acl.php @@ -29,10 +29,9 @@ namespace Espo\Core; -use Espo\Core\{ - Acl\GlobalRestriction, - Acl\Table, - Acl\Exceptions\NotImplemented}; +use Espo\Core\Acl\Exceptions\NotImplemented; +use Espo\Core\Acl\GlobalRestriction; +use Espo\Core\Acl\Table; use Espo\ORM\Entity; use Espo\Entities\User; @@ -44,14 +43,11 @@ use stdClass; */ class Acl { - protected AclManager $aclManager; - protected User $user; - public function __construct(AclManager $aclManager, User $user) - { - $this->aclManager = $aclManager; - $this->user = $user; - } + public function __construct( + protected AclManager $aclManager, + protected User $user + ) {} /** * Get a full access data map. diff --git a/application/Espo/Core/AclManager.php b/application/Espo/Core/AclManager.php index 20c3f1a1e0..60b441b2fc 100644 --- a/application/Espo/Core/AclManager.php +++ b/application/Espo/Core/AclManager.php @@ -30,37 +30,33 @@ namespace Espo\Core; use Espo\ORM\Entity; +use Espo\ORM\EntityManager; use Espo\Entities\User; -use Espo\ORM\EntityManager; - -use Espo\Core\{ - Acl, - Acl\GlobalRestriction, - Acl\OwnerUserFieldProvider, - Acl\Table\TableFactory, - Acl\Table, - Acl\Map\Map, - Acl\Map\MapFactory, - Acl\OwnershipChecker\OwnershipCheckerFactory, - Acl\OwnershipChecker, - Acl\OwnershipOwnChecker, - Acl\OwnershipTeamChecker, - Acl\AccessChecker\AccessCheckerFactory, - Acl\AccessChecker, - Acl\AccessCreateChecker, - Acl\AccessReadChecker, - Acl\AccessEditChecker, - Acl\AccessDeleteChecker, - Acl\AccessStreamChecker, - Acl\AccessEntityCreateChecker, - Acl\AccessEntityReadChecker, - Acl\AccessEntityEditChecker, - Acl\AccessEntityDeleteChecker, - Acl\AccessEntityStreamChecker, - Acl\Exceptions\NotImplemented, -}; +use Espo\Core\Acl\AccessChecker; +use Espo\Core\Acl\AccessChecker\AccessCheckerFactory; +use Espo\Core\Acl\AccessCreateChecker; +use Espo\Core\Acl\AccessDeleteChecker; +use Espo\Core\Acl\AccessEditChecker; +use Espo\Core\Acl\AccessEntityCreateChecker; +use Espo\Core\Acl\AccessEntityDeleteChecker; +use Espo\Core\Acl\AccessEntityEditChecker; +use Espo\Core\Acl\AccessEntityReadChecker; +use Espo\Core\Acl\AccessEntityStreamChecker; +use Espo\Core\Acl\AccessReadChecker; +use Espo\Core\Acl\AccessStreamChecker; +use Espo\Core\Acl\Exceptions\NotImplemented; +use Espo\Core\Acl\GlobalRestriction; +use Espo\Core\Acl\Map\Map; +use Espo\Core\Acl\Map\MapFactory; +use Espo\Core\Acl\OwnershipChecker; +use Espo\Core\Acl\OwnershipChecker\OwnershipCheckerFactory; +use Espo\Core\Acl\OwnershipOwnChecker; +use Espo\Core\Acl\OwnershipTeamChecker; +use Espo\Core\Acl\OwnerUserFieldProvider; +use Espo\Core\Acl\Table; +use Espo\Core\Acl\Table\TableFactory; use stdClass; use InvalidArgumentException; @@ -101,9 +97,9 @@ class AclManager Table::ACTION_STREAM => AccessStreamChecker::class, ]; - /** @var AccessCheckerFactory|\Espo\Core\Portal\Acl\AccessChecker\AccessCheckerFactory */ + /** @var AccessCheckerFactory|Portal\Acl\AccessChecker\AccessCheckerFactory */ protected $accessCheckerFactory; - /** @var OwnershipCheckerFactory|\Espo\Core\Portal\Acl\OwnershipChecker\OwnershipCheckerFactory */ + /** @var OwnershipCheckerFactory|Portal\Acl\OwnershipChecker\OwnershipCheckerFactory */ protected $ownershipCheckerFactory; /** @var TableFactory */ private $tableFactory; @@ -639,7 +635,7 @@ class AclManager /** * Get a restricted field list for a specific scope by a restriction type. * - * @param GlobalRestriction::TYPE_*|array $type + * @param GlobalRestriction::TYPE_*|array $type * @return string[] */ public function getScopeRestrictedFieldList(string $scope, $type): array diff --git a/application/Espo/Core/ApplicationState.php b/application/Espo/Core/ApplicationState.php index d1ebab5be1..3fc74bf88c 100644 --- a/application/Espo/Core/ApplicationState.php +++ b/application/Espo/Core/ApplicationState.php @@ -29,7 +29,6 @@ namespace Espo\Core; -use Espo\Core\Exceptions\Error; use Espo\Entities\Portal as PortalEntity; use Espo\Entities\User as UserEntity; @@ -40,12 +39,8 @@ use LogicException; */ class ApplicationState { - private Container $container; - - public function __construct(Container $container) - { - $this->container = $container; - } + public function __construct(private Container $container) + {} /** * Whether an application is initialized as a portal. diff --git a/application/Espo/Core/Utils/AdminNotificationManager.php b/application/Espo/Core/Utils/AdminNotificationManager.php index 08bf78900f..3d431b4f37 100644 --- a/application/Espo/Core/Utils/AdminNotificationManager.php +++ b/application/Espo/Core/Utils/AdminNotificationManager.php @@ -37,22 +37,12 @@ use Espo\ORM\EntityManager; */ class AdminNotificationManager { - private EntityManager $entityManager; - private Config $config; - private Language $language; - private ScheduledJob $scheduledJob; - public function __construct( - EntityManager $entityManager, - Config $config, - Language $language, - ScheduledJob $scheduledJob - ) { - $this->entityManager = $entityManager; - $this->config = $config; - $this->language = $language; - $this->scheduledJob = $scheduledJob; - } + private EntityManager $entityManager, + private Config $config, + private Language $language, + private ScheduledJob $scheduledJob + ) {} /** * @return array diff --git a/application/Espo/Core/Utils/ApiKey.php b/application/Espo/Core/Utils/ApiKey.php index 10d303b81d..a8f1b81c34 100644 --- a/application/Espo/Core/Utils/ApiKey.php +++ b/application/Espo/Core/Utils/ApiKey.php @@ -29,22 +29,14 @@ namespace Espo\Core\Utils; -use Espo\Core\{ - Utils\Config, - Utils\Config\ConfigWriter, -}; +use Espo\Core\Utils\Config\ConfigWriter; class ApiKey { - private $config; - - private $configWriter; - - public function __construct(Config $config, ConfigWriter $configWriter) - { - $this->config = $config; - $this->configWriter = $configWriter; - } + public function __construct( + private Config $config, + private ConfigWriter $configWriter) + {} public static function hash(string $secretKey, string $string = ''): string { @@ -81,7 +73,6 @@ class ApiKey $apiSecretKeys->$id = $secretKey; $this->configWriter->set('apiSecretKeys', $apiSecretKeys); - $this->configWriter->save(); } @@ -96,7 +87,6 @@ class ApiKey unset($apiSecretKeys->$id); $this->configWriter->set('apiSecretKeys', $apiSecretKeys); - $this->configWriter->save(); } } diff --git a/application/Espo/Core/Utils/Autoload.php b/application/Espo/Core/Utils/Autoload.php index 4b9bd9eb4e..f43603f612 100644 --- a/application/Espo/Core/Utils/Autoload.php +++ b/application/Espo/Core/Utils/Autoload.php @@ -29,53 +29,28 @@ namespace Espo\Core\Utils; -use Espo\Core\{ - Utils\Autoload\Loader, - Utils\DataCache, - Utils\File\Manager as FileManager, - Utils\Resource\PathProvider, -}; +use Espo\Core\Utils\Autoload\Loader; +use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\Utils\Resource\PathProvider; use Exception; class Autoload { - /** - * @var ?array - */ + /** @var ?array */ private $data = null; private string $cacheKey = 'autoload'; - private string $autoloadFileName = 'autoload.json'; - private Config $config; - - private Metadata $metadata; - - private DataCache $dataCache; - - private FileManager $fileManager; - - private Loader $loader; - - private PathProvider $pathProvider; - public function __construct( - Config $config, - Metadata $metadata, - DataCache $dataCache, - FileManager $fileManager, - Loader $loader, - PathProvider $pathProvider - ) { - $this->config = $config; - $this->metadata = $metadata; - $this->dataCache = $dataCache; - $this->fileManager = $fileManager; - $this->loader = $loader; - $this->pathProvider = $pathProvider; - } + private Config $config, + private Metadata $metadata, + private DataCache $dataCache, + private FileManager $fileManager, + private Loader $loader, + private PathProvider $pathProvider + ) {} /** * @return array diff --git a/application/Espo/Core/Utils/ClassFinder.php b/application/Espo/Core/Utils/ClassFinder.php index 593c2e633b..290b2a205f 100644 --- a/application/Espo/Core/Utils/ClassFinder.php +++ b/application/Espo/Core/Utils/ClassFinder.php @@ -38,17 +38,12 @@ use Espo\Core\Utils\File\ClassMap; */ class ClassFinder { - private ClassMap $classMap; - /** - * @var array> - */ + /** @var array> */ private $dataHashMap = []; - public function __construct(ClassMap $classMap) - { - $this->classMap = $classMap; - } + public function __construct(private ClassMap $classMap) + {} /** * Find class name by a category and name. @@ -59,15 +54,13 @@ class ClassFinder { $map = $this->getMap($category, $subDirs); - $className = $map[$name] ?? null; - - return $className; + return $map[$name] ?? null; } /** * Get a name => class name map. * - * @return array + * @return array */ public function getMap(string $category, bool $subDirs = false): array { diff --git a/application/Espo/Core/Utils/ClientManager.php b/application/Espo/Core/Utils/ClientManager.php index c72ed76abb..27a9f83155 100644 --- a/application/Espo/Core/Utils/ClientManager.php +++ b/application/Espo/Core/Utils/ClientManager.php @@ -51,27 +51,14 @@ class ClientManager private const APP_DESCRIPTION = "EspoCRM - Open Source CRM application."; - private Config $config; - private ThemeManager $themeManager; - private Metadata $metadata; - private FileManager $fileManager; - private DevModeJsFileListProvider $devModeJsFileListProvider; - private Module $module; - public function __construct( - Config $config, - ThemeManager $themeManager, - Metadata $metadata, - FileManager $fileManager, - DevModeJsFileListProvider $devModeJsFileListProvider, - Module $module + private Config $config, + private ThemeManager $themeManager, + private Metadata $metadata, + private FileManager $fileManager, + private DevModeJsFileListProvider $devModeJsFileListProvider, + private Module $module ) { - $this->config = $config; - $this->themeManager = $themeManager; - $this->metadata = $metadata; - $this->fileManager = $fileManager; - $this->devModeJsFileListProvider = $devModeJsFileListProvider; - $this->module = $module; $this->nonce = Util::generateKey(); } @@ -145,7 +132,7 @@ class ClientManager $siteUrl = $this->config->get('siteUrl') ?? ''; - if (strpos($siteUrl, 'https://') === 0) { + if (str_starts_with($siteUrl, 'https://')) { $response->setHeader('Strict-Transport-Security', 'max-age=10368000'); } } diff --git a/application/Espo/Core/Utils/Config.php b/application/Espo/Core/Utils/Config.php index bba5200ebd..d80033fc95 100644 --- a/application/Espo/Core/Utils/Config.php +++ b/application/Espo/Core/Utils/Config.php @@ -42,49 +42,27 @@ use const E_USER_DEPRECATED; class Config { private string $configPath = 'data/config.php'; - private string $internalConfigPath = 'data/config-internal.php'; - private string $systemConfigPath = 'application/Espo/Resources/defaults/systemConfig.php'; - private string $cacheTimestamp = 'cacheTimestamp'; - - /** - * @var string[] - */ + /** @var string[] */ protected $associativeArrayAttributeList = [ 'currencyRates', 'database', 'logger', 'defaultPermissions', ]; - - /** - * @var ?array - */ + /** @var ?array */ private $data = null; - - /** - * @var array - */ + /** @var array */ private $changedData = []; - - /** - * @var string[] - */ + /** @var string[] */ private $removeData = []; - - private ConfigFileManager $fileManager; - - /** - * @var string[] - */ + /** @var string[] */ private $internalParamList = []; - public function __construct(ConfigFileManager $fileManager) - { - $this->fileManager = $fileManager; - } + public function __construct(private ConfigFileManager $fileManager) + {} /** * A path to the config file. @@ -191,7 +169,7 @@ class Config /** * @deprecated As of v7.0. Use ConfigWriter instead. * - * @param string|array|\stdClass $name + * @param string|array|stdClass $name * @param mixed $value */ public function set($name, $value = null, bool $dontMarkDirty = false): void @@ -282,7 +260,7 @@ class Config throw new RuntimeException('Invalid config data while saving.'); } - $data['microtime'] = $microtime = microtime(true); + $data['microtime'] = microtime(true); $this->fileManager->putPhpContents($configPath, $data); @@ -323,7 +301,7 @@ class Config $internalData = $this->fileManager->isFile($this->internalConfigPath) ? $this->fileManager->getPhpContents($this->internalConfigPath) : []; - /** @var array $mergedData */ + /** @var array $mergedData */ $mergedData = Util::merge( Util::merge($systemData, $data), $internalData @@ -364,7 +342,7 @@ class Config /** * @deprecated As of 7.0. Use ConfigWriter instead. - * @param array $data + * @param array $data * @return void */ public function setData($data) diff --git a/application/Espo/Core/Utils/DataCache.php b/application/Espo/Core/Utils/DataCache.php index ca727554dc..46e6a31458 100644 --- a/application/Espo/Core/Utils/DataCache.php +++ b/application/Espo/Core/Utils/DataCache.php @@ -37,14 +37,10 @@ use stdClass; class DataCache { - protected FileManager $fileManager; - protected string $cacheDir = 'data/cache/application/'; - public function __construct(FileManager $fileManager) - { - $this->fileManager = $fileManager; - } + public function __construct(protected FileManager $fileManager) + {} /** * Whether is cached. @@ -71,7 +67,7 @@ class DataCache /** * Store in cache. * - * @param array|stdClass $data + * @param array|stdClass $data */ public function store(string $key, $data): void { diff --git a/application/Espo/Core/Utils/DataUtil.php b/application/Espo/Core/Utils/DataUtil.php index 01c7998b6a..8f50d9439a 100644 --- a/application/Espo/Core/Utils/DataUtil.php +++ b/application/Espo/Core/Utils/DataUtil.php @@ -36,9 +36,9 @@ use stdClass; class DataUtil { /** - * @param array $data - * @param array|string $unsetList - * @return array + * @param array $data + * @param array|string $unsetList + * @return array */ public static function unsetByKey(&$data, $unsetList, bool $removeEmptyItems = false) { @@ -65,7 +65,6 @@ class DataUtil } $pointer = &$data; - $parent = null; $elementArr = []; $elementArr[] = &$pointer; @@ -76,38 +75,44 @@ class DataUtil if (array_key_exists($key, $pointer)) { unset($pointer[$key]); } + + continue; } - else if (is_object($pointer)) { - unset($pointer->$key); - if ($removeEmptyItems) { - for ($j = count($elementArr); $j > 0; $j--) { - $pointerBack =& $elementArr[$j]; + if (!is_object($pointer)) { + continue; + } - if (is_object($pointerBack) && count(get_object_vars($pointerBack)) === 0) { - $previous =& $elementArr[$j - 1]; + unset($pointer->$key); - if (is_object($previous)) { - $key = $arr[$j - 1]; - unset($previous->$key); - } - } + if (!$removeEmptyItems) { + continue; + } + + for ($j = count($elementArr); $j > 0; $j--) { + $pointerBack =& $elementArr[$j]; + + if (is_object($pointerBack) && count(get_object_vars($pointerBack)) === 0) { + $previous =& $elementArr[$j - 1]; + + if (is_object($previous)) { + $key = $arr[$j - 1]; + unset($previous->$key); } } } - } - else { - $parent = $pointer; - if (is_array($pointer)) { - $pointer = &$pointer[$key]; - } - else if (is_object($pointer)) { - $pointer = &$pointer->$key; - } - - $elementArr[] = &$pointer; + continue; } + + if (is_array($pointer)) { + $pointer = &$pointer[$key]; + } + else if (is_object($pointer)) { + $pointer = &$pointer->$key; + } + + $elementArr[] = &$pointer; } } @@ -115,7 +120,7 @@ class DataUtil } /** - * @param array|stdClass $data + * @param array|stdClass $data * @param mixed $needle * @return array|stdClass */ @@ -200,10 +205,10 @@ class DataUtil $data = []; } - /** @var array $data */ + /** @var array $data */ if (in_array($appendIdentifier, $overrideData)) { - foreach ($overrideData as $key => $item) { + foreach ($overrideData as $item) { if ($item === $appendIdentifier) { continue; } diff --git a/application/Espo/Core/Utils/DateTime.php b/application/Espo/Core/Utils/DateTime.php index a0c0125984..270340dcad 100644 --- a/application/Espo/Core/Utils/DateTime.php +++ b/application/Espo/Core/Utils/DateTime.php @@ -43,15 +43,11 @@ use RuntimeException; class DateTime { public const SYSTEM_DATE_TIME_FORMAT = 'Y-m-d H:i:s'; - public const SYSTEM_DATE_FORMAT = 'Y-m-d'; private string $dateFormat; - private string $timeFormat; - private DateTimeZone $timezone; - private string $language; public function __construct( @@ -113,9 +109,9 @@ class DateTime * Convert a system date-time. * * @param string $string A system date-time. - * @param string $timezone A target timezone. If not specified then the default timezone will be used. - * @param string|null $format A target format. If not specified then the default format will be used. - * @param string|null $language A language. If not specified then the default language will be used. + * @param ?string $timezone A target timezone. If not specified then the default timezone will be used. + * @param ?string $format A target format. If not specified then the default format will be used. + * @param ?string $language A language. If not specified then the default language will be used. * @throws RuntimeException If could not parse. */ public function convertSystemDateTime( @@ -125,7 +121,7 @@ class DateTime ?string $language = null ): string { - if (is_string($string) && strlen($string) === 16) { + if (strlen($string) === 16) { $string .= ':00'; } @@ -140,7 +136,6 @@ class DateTime $dateTime->setTimezone($tz); $carbon = Carbon::instance($dateTime); - $carbon->locale($language ?? $this->language); return $carbon->isoFormat($format ?? $this->getDateTimeFormat()); @@ -149,19 +144,17 @@ class DateTime /** * Get a current date. * - * @param string|null $timezone If not specified then the default will be used. - * @param string|null $format If not specified then the default will be used. + * @param ?string $timezone If not specified then the default will be used. + * @param ?string $format If not specified then the default will be used. */ public function getTodayString(?string $timezone = null, ?string $format = null): string { $tz = $timezone ? new DateTimeZone($timezone) : $this->timezone; $dateTime = new DateTimeStd(); - $dateTime->setTimezone($tz); $carbon = Carbon::instance($dateTime); - $carbon->locale($this->language); return $carbon->isoFormat($format ?? $this->getDateFormat()); @@ -170,8 +163,8 @@ class DateTime /** * Get a current date-time. * - * @param string|null $timezone If not specified then the default will be used. - * @param string|null $format If not specified then the default will be used. + * @param ?string $timezone If not specified then the default will be used. + * @param ?string $format If not specified then the default will be used. */ public function getNowString(?string $timezone = null, ?string $format = null): string { diff --git a/application/Espo/Core/Utils/EmailFilterManager.php b/application/Espo/Core/Utils/EmailFilterManager.php index 2aef1e1dba..422cd49de3 100644 --- a/application/Espo/Core/Utils/EmailFilterManager.php +++ b/application/Espo/Core/Utils/EmailFilterManager.php @@ -45,14 +45,11 @@ class EmailFilterManager { /** @var array> */ private array $data = []; - private EntityManager $entityManager; - private FiltersMatcher $filtersMatcher; - public function __construct(EntityManager $entityManager, FiltersMatcher $filtersMatcher) - { - $this->entityManager = $entityManager; - $this->filtersMatcher = $filtersMatcher; - } + public function __construct( + private EntityManager $entityManager, + private FiltersMatcher $filtersMatcher + ) {} public function getMatchingFilter(Email $email, string $userId): ?EmailFilter { diff --git a/application/Espo/Core/Utils/FieldManager.php b/application/Espo/Core/Utils/FieldManager.php index 9c8096d4f4..ceaafcc5b2 100644 --- a/application/Espo/Core/Utils/FieldManager.php +++ b/application/Espo/Core/Utils/FieldManager.php @@ -30,10 +30,9 @@ namespace Espo\Core\Utils; /** - * @deprecated - * @todo Remove in 6.4. + * @deprecated As of v6.0. Use FieldUtil. + * @todo Remove in 8.0. */ class FieldManager extends FieldUtil { - } diff --git a/application/Espo/Core/Utils/FieldManagerUtil.php b/application/Espo/Core/Utils/FieldManagerUtil.php index 82cd3dabbf..f9b5555355 100644 --- a/application/Espo/Core/Utils/FieldManagerUtil.php +++ b/application/Espo/Core/Utils/FieldManagerUtil.php @@ -35,5 +35,4 @@ namespace Espo\Core\Utils; */ class FieldManagerUtil extends FieldUtil { - } diff --git a/application/Espo/Core/Utils/FieldUtil.php b/application/Espo/Core/Utils/FieldUtil.php index 6575f9c045..612df2a023 100644 --- a/application/Espo/Core/Utils/FieldUtil.php +++ b/application/Espo/Core/Utils/FieldUtil.php @@ -31,17 +31,11 @@ namespace Espo\Core\Utils; class FieldUtil { - private Metadata $metadata; - - /** - * @var array> - */ + /** @var array> */ private $fieldByTypeListCache = []; - public function __construct(Metadata $metadata) - { - $this->metadata = $metadata; - } + public function __construct(private Metadata $metadata) + {} /** * @return string[] diff --git a/application/Espo/Core/Utils/Hasher.php b/application/Espo/Core/Utils/Hasher.php index bf56856049..f50a8d45de 100644 --- a/application/Espo/Core/Utils/Hasher.php +++ b/application/Espo/Core/Utils/Hasher.php @@ -29,22 +29,16 @@ namespace Espo\Core\Utils; -use Espo\Core\Utils\Config; - /** * Hash a string. E.g. hash an email address to use it in opt-out URL * to recognize a recipient who clicked opt-out. */ class Hasher { - private Config $config; - private string $secretKeyParam = 'hashSecretKey'; - public function __construct(Config $config) - { - $this->config = $config; - } + public function __construct(private Config $config) + {} public function hash(string $string): string { diff --git a/application/Espo/Core/Utils/Json.php b/application/Espo/Core/Utils/Json.php index 1b6a8af42b..3794c8d6ef 100644 --- a/application/Espo/Core/Utils/Json.php +++ b/application/Espo/Core/Utils/Json.php @@ -39,7 +39,6 @@ class Json * JSON encode. * * @param mixed $value - * * @throws JsonException */ public static function encode($value, int $options = 0): string @@ -52,7 +51,6 @@ class Json * * @param bool $associative Objects will be converted to associative. * @return mixed - * * @throws JsonException */ public static function decode(string $json, bool $associative = false) diff --git a/application/Espo/Core/Utils/Language.php b/application/Espo/Core/Utils/Language.php index 626b336950..1aa4390366 100644 --- a/application/Espo/Core/Utils/Language.php +++ b/application/Espo/Core/Utils/Language.php @@ -29,67 +29,38 @@ namespace Espo\Core\Utils; -use Espo\Core\{ - Utils\File\Manager as FileManager, - Utils\Resource\Reader as ResourceReader, - Utils\Resource\Reader\Params as ResourceReaderParams, -}; - +use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\Utils\Resource\Reader as ResourceReader; +use Espo\Core\Utils\Resource\Reader\Params as ResourceReaderParams; use Espo\Entities\Preferences; use RuntimeException; class Language { - /** - * @var array> - */ + /** @var array> */ private $data = []; - - /** - * @var array> - */ + /** @var array> */ private $deletedData = []; - - /** - * @var array> - */ + /** @var array> */ private $changedData = []; private string $currentLanguage; - protected string $defaultLanguage = 'en_US'; - protected bool $useCache = false; - - protected bool $noCustom = false; - private string $customPath = 'custom/Espo/Custom/Resources/i18n/{language}'; - private string $resourcePath = 'i18n/{language}'; - private FileManager $fileManager; - - private ResourceReader $resourceReader; - - private DataCache $dataCache; - public function __construct( ?string $language, - FileManager $fileManager, - ResourceReader $resourceReader, - DataCache $dataCache, - bool $useCache = false, - bool $noCustom = false + private FileManager $fileManager, + private ResourceReader $resourceReader, + private DataCache $dataCache, + protected bool $useCache = false, + protected bool $noCustom = false ) { $this->currentLanguage = $language ?? $this->defaultLanguage; - $this->fileManager = $fileManager; - $this->resourceReader = $resourceReader; - $this->dataCache = $dataCache; - - $this->useCache = $useCache; - $this->noCustom = $noCustom; } public function getLanguage(): string @@ -104,11 +75,7 @@ class Language public static function detectLanguage(Config $config, ?Preferences $preferences = null): ?string { - $language = null; - - if ($preferences) { - $language = $preferences->get('language'); - } + $language = $preferences?->get('language'); if (!$language) { $language = $config->get('language'); @@ -117,6 +84,9 @@ class Language return $language; } + /** + * @deprecated As of v7.4. Not to be used. + */ public function setLanguage(string $language): void { $this->currentLanguage = $language; @@ -156,7 +126,7 @@ class Language * Ex., $requiredOptions = ['en_US', 'de_DE'] * "language" option has only ['en_US' => 'English (United States)'] * Result will be ['en_US' => 'English (United States)', 'de_DE' => 'de_DE']. - * @return string|string[]|array + * @return string|string[]|array */ public function translate( $label, @@ -171,7 +141,7 @@ class Language $translated[$subLabel] = $this->translate($subLabel, $category, $scope, $requiredOptions); } - /** @var string[]|array */ + /** @var string[]|array */ return $translated; } @@ -239,7 +209,7 @@ class Language } /** - * @return array> + * @return array> */ public function getAll(): array { @@ -292,7 +262,7 @@ class Language } /** - * @return ?array + * @return ?array */ private function getData(): ?array { @@ -308,7 +278,7 @@ class Language /** * Set/change a label. * - * @param string|array $name + * @param string|array $name * @param mixed $value */ public function set(string $scope, string $category, $name, $value): void @@ -385,7 +355,7 @@ class Language } /** - * @return array + * @return array */ private function getDefaultLanguageData(bool $reload = false): array { @@ -393,7 +363,7 @@ class Language } /** - * @return array + * @return array */ private function getLanguageData(string $language, bool $reload = false): array { diff --git a/application/Espo/Core/Utils/Layout.php b/application/Espo/Core/Utils/Layout.php index 47691a5efe..eb4074d20e 100644 --- a/application/Espo/Core/Utils/Layout.php +++ b/application/Espo/Core/Utils/Layout.php @@ -29,34 +29,24 @@ namespace Espo\Core\Utils; -use Espo\Core\{ - Utils\File\Manager as FileManager, - InjectableFactory, - Exceptions\Error, - Utils\Resource\FileReader, - Utils\Resource\FileReader\Params as FileReaderParams, -}; +use Espo\Core\InjectableFactory; +use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\Utils\Resource\FileReader; +use Espo\Core\Utils\Resource\FileReader\Params as FileReaderParams; +use RuntimeException; class Layout { private string $defaultPath = 'application/Espo/Resources/defaults/layouts'; - private FileManager $fileManager; - - private InjectableFactory $injectableFactory; - - /** - * @internal Used by the portal layout util. - */ + /** @internal Used by the portal layout util. */ protected FileReader $fileReader; public function __construct( - FileManager $fileManager, - InjectableFactory $injectableFactory, + private FileManager $fileManager, + private InjectableFactory $injectableFactory, FileReader $fileReader ) { - $this->fileManager = $fileManager; - $this->injectableFactory = $injectableFactory; $this->fileReader = $fileReader; } @@ -66,7 +56,7 @@ class Layout $this->sanitizeInput($scope) !== $scope || $this->sanitizeInput($name) !== $name ) { - throw new Error("Bad parameters."); + throw new RuntimeException("Bad parameters."); } $path = 'layouts/' . $scope . '/' . $name . '.json'; @@ -94,7 +84,7 @@ class Layout $defaultImpl = $this->injectableFactory->create($defaultImplClassName); if (!method_exists($defaultImpl, 'get')) { - throw new Error("No 'get' method in '{$defaultImplClassName}'."); + throw new RuntimeException("No 'get' method in '{$defaultImplClassName}'."); } $data = $defaultImpl->get($scope); diff --git a/application/Espo/Core/Utils/Metadata.php b/application/Espo/Core/Utils/Metadata.php index 82f9debe7d..afa4bff594 100644 --- a/application/Espo/Core/Utils/Metadata.php +++ b/application/Espo/Core/Utils/Metadata.php @@ -29,12 +29,10 @@ namespace Espo\Core\Utils; -use Espo\Core\{ - Utils\File\Manager as FileManager, - Utils\Metadata\Helper, - Utils\Resource\Reader as ResourceReader, - Utils\Resource\Reader\Params as ResourceReaderParams, -}; +use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\Utils\Metadata\Helper; +use Espo\Core\Utils\Resource\Reader as ResourceReader; +use Espo\Core\Utils\Resource\Reader\Params as ResourceReaderParams; use stdClass; use LogicException; @@ -45,32 +43,20 @@ use RuntimeException; */ class Metadata { - /** - * @var ?array - */ + /** @var ?array */ private ?array $data = null; - private ?stdClass $objData = null; private string $cacheKey = 'metadata'; - private string $objCacheKey = 'objMetadata'; - private string $customPath = 'custom/Espo/Custom/Resources/metadata'; - /** - * @var array> - */ + /** @var array> */ private $deletedData = []; - - /** - * @var array> - */ + /** @var array> */ private $changedData = []; - /** - * @var array - */ + /** @var array */ private $forceAppendPathList = [ ['app', 'rebuild', 'actionClassNameList'], ['app', 'fieldProcessing', 'readLoaderClassNameList'], @@ -96,26 +82,14 @@ class Metadata private const ANY_KEY = '__ANY__'; private Helper $metadataHelper; - private Module $module; - private FileManager $fileManager; - private DataCache $dataCache; - private ResourceReader $resourceReader; - private bool $useCache; public function __construct( - FileManager $fileManager, - DataCache $dataCache, - ResourceReader $resourceReader, - Module $module, - bool $useCache = false - ){ - $this->fileManager = $fileManager; - $this->dataCache = $dataCache; - $this->resourceReader = $resourceReader; - $this->module = $module; - - $this->useCache = $useCache; - } + private FileManager $fileManager, + private DataCache $dataCache, + private ResourceReader $resourceReader, + private Module $module, + private bool $useCache = false + ){} private function getMetadataHelper(): Helper { @@ -158,7 +132,7 @@ class Metadata /** * Get metadata array. * - * @return array + * @return array */ private function getData(): array { @@ -188,7 +162,7 @@ class Metadata * * @param bool $isJSON * @param bool $reload - * @return array|string + * @return array|string */ public function getAll(bool $isJSON = false, bool $reload = false) { @@ -437,7 +411,7 @@ class Metadata /** * Set Metadata data. * - * @param array|scalar|null $data + * @param array|scalar|null $data */ public function set(string $key1, string $key2, $data): void { @@ -455,9 +429,9 @@ class Metadata ], ]; - /** @var array> $mergedChangedData */ + /** @var array> $mergedChangedData */ $mergedChangedData = Util::merge($this->changedData, $newData); - /** @var array $mergedData */ + /** @var array $mergedData */ $mergedData = Util::merge($this->getData(), $newData); $this->changedData = $mergedChangedData; @@ -481,7 +455,7 @@ class Metadata switch ($key1) { case 'entityDefs': - //unset related additional fields, e.g. a field with "address" type + // unset related additional fields, e.g. a field with "address" type $fieldDefinitionList = $this->get('fields'); $unsetList = $unsets; @@ -524,21 +498,21 @@ class Metadata ] ]; - /** @var array> $mergedDeletedData */ + /** @var array> $mergedDeletedData */ $mergedDeletedData = Util::merge($this->deletedData, $unsetData); $this->deletedData = $mergedDeletedData; - /** @var array> $unsetDeletedData */ + /** @var array> $unsetDeletedData */ $unsetDeletedData = Util::unsetInArrayByValue('__APPEND__', $this->deletedData, true); $this->deletedData = $unsetDeletedData; - /** @var array $data */ + /** @var array $data */ $data = Util::unsetInArray($this->getData(), $metadataUnsetData, true); $this->data = $data; } /** - * @param array $data + * @param array $data */ private function undelete(string $key1, string $key2, $data): void { diff --git a/application/Espo/Core/Utils/Module.php b/application/Espo/Core/Utils/Module.php index 50f9e336bf..9c058fbb60 100644 --- a/application/Espo/Core/Utils/Module.php +++ b/application/Espo/Core/Utils/Module.php @@ -29,11 +29,7 @@ namespace Espo\Core\Utils; -use Espo\Core\{ - Utils\File\Manager as FileManager, - Utils\DataCache, - Utils\Json, -}; +use Espo\Core\Utils\File\Manager as FileManager; /** * Gets module parameters. @@ -42,51 +38,25 @@ class Module { private const DEFAULT_ORDER = 11; - private bool $useCache; - - /** - * @var ?array> - */ + /** @var ?array> */ private $data = null; - - /** - * @var ?string[] - */ + /** @var ?string[] */ private $list = null; - - /** - * @var ?string[] - */ + /** @var ?string[] */ private $internalList = null; - - /** - * @var ?string[] - */ + /** @var ?string[] */ private $orderedList = null; private string $cacheKey = 'modules'; - private string $internalPath = 'application/Espo/Modules'; - private string $customPath = 'custom/Espo/Modules'; - private string $moduleFilePath = 'Resources/module.json'; - private FileManager $fileManager; - - private ?DataCache $dataCache; - public function __construct( - FileManager $fileManager, - ?DataCache $dataCache = null, - bool $useCache = false - ) { - - $this->fileManager = $fileManager; - $this->dataCache = $dataCache; - - $this->useCache = $useCache; - } + private FileManager $fileManager, + private ?DataCache $dataCache = null, + private bool $useCache = false + ) {} /** * Get module parameters. @@ -117,7 +87,7 @@ class Module $this->dataCache && $this->dataCache->has($this->cacheKey) ) { - /** @var array> $data */ + /** @var array> $data */ $data = $this->dataCache->get($this->cacheKey); $this->data = $data; @@ -136,7 +106,6 @@ class Module * Get an ordered list of modules. * * @return string[] - * * @todo Use cache if available. */ public function getOrderedList(): array @@ -204,7 +173,7 @@ class Module /** * @todo Use event-dispatcher class (passed via constructor). - * `$this->clearCacheEventDispatcher->subscribe( ... );` + * `$this->clearCacheEventDispatcher->subscribe(...);` */ public function clearCache(): void { @@ -215,7 +184,7 @@ class Module } /** - * @return array> + * @return array> */ private function loadData(): array { @@ -229,7 +198,7 @@ class Module } /** - * @return array + * @return array */ private function loadModuleData(string $moduleName): array { diff --git a/application/Espo/Core/Utils/NumberUtil.php b/application/Espo/Core/Utils/NumberUtil.php index 37741ec495..2089e15f63 100644 --- a/application/Espo/Core/Utils/NumberUtil.php +++ b/application/Espo/Core/Utils/NumberUtil.php @@ -31,15 +31,10 @@ namespace Espo\Core\Utils; class NumberUtil { - private ?string $decimalMark; - - private ?string $thousandSeparator; - - public function __construct(?string $decimalMark = '.', ?string $thousandSeparator = ',') - { - $this->decimalMark = $decimalMark; - $this->thousandSeparator = $thousandSeparator; - } + public function __construct( + private ?string $decimalMark = '.', + private ?string $thousandSeparator = ',' + ) {} /** * @param scalar $value diff --git a/application/Espo/Core/Utils/PasswordHash.php b/application/Espo/Core/Utils/PasswordHash.php index 07a5bc5603..464d25dd08 100644 --- a/application/Espo/Core/Utils/PasswordHash.php +++ b/application/Espo/Core/Utils/PasswordHash.php @@ -33,17 +33,13 @@ use RuntimeException; class PasswordHash { - private Config $config; - /** * SHA-512 salt format. */ private string $saltFormat = '$6${0}$'; - public function __construct(Config $config) - { - $this->config = $config; - } + public function __construct(private Config $config) + {} /** * Hash a password. diff --git a/application/Espo/Core/Utils/Preload.php b/application/Espo/Core/Utils/Preload.php index 7cdcb4ca6c..6b10b344f6 100644 --- a/application/Espo/Core/Utils/Preload.php +++ b/application/Espo/Core/Utils/Preload.php @@ -99,12 +99,12 @@ class Preload $file = str_replace('\\', '/', $file); foreach ($this->ignoreList as $item) { - if (strpos($file, $item) === 0) { + if (str_starts_with($file, $item)) { return true; } } - if (strpos($file, 'vendor/composer/ClassLoader.php') !== false) { + if (str_contains($file, 'vendor/composer/ClassLoader.php')) { return true; } diff --git a/application/Espo/Core/Utils/Route.php b/application/Espo/Core/Utils/Route.php index 6e530dbff5..146143c6f6 100644 --- a/application/Espo/Core/Utils/Route.php +++ b/application/Espo/Core/Utils/Route.php @@ -49,25 +49,13 @@ class Route private string $cacheKey = 'routes'; private string $routesFileName = 'routes.json'; - private Config $config; - private Metadata $metadata; - private FileManager $fileManager; - private DataCache $dataCache; - private PathProvider $pathProvider; - public function __construct( - Config $config, - Metadata $metadata, - FileManager $fileManager, - DataCache $dataCache, - PathProvider $pathProvider - ) { - $this->config = $config; - $this->metadata = $metadata; - $this->fileManager = $fileManager; - $this->dataCache = $dataCache; - $this->pathProvider = $pathProvider; - } + private Config $config, + private Metadata $metadata, + private FileManager $fileManager, + private DataCache $dataCache, + private PathProvider $pathProvider + ) {} /** * Get all routes. @@ -254,8 +242,8 @@ class Route } /** - * @param array $newRoute - * @param array> $routeList + * @param array $newRoute + * @param array> $routeList */ static private function isRouteInList(array $newRoute, array $routeList): bool { diff --git a/application/Espo/Core/Utils/ScheduledJob.php b/application/Espo/Core/Utils/ScheduledJob.php index 43bb9b91a4..d3c0e99fe8 100644 --- a/application/Espo/Core/Utils/ScheduledJob.php +++ b/application/Espo/Core/Utils/ScheduledJob.php @@ -54,23 +54,14 @@ class ScheduledJob 'default' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BINARY} -f {CRON-FILE} > /dev/null 2>&1', ]; - private ClassFinder $classFinder; - private Language $language; - private EntityManager $entityManager; - private MetadataProvider $metadataProvider; private System $systemUtil; public function __construct( - ClassFinder $classFinder, - EntityManager $entityManager, - Language $language, - MetadataProvider $metadataProvider + private ClassFinder $classFinder, + private EntityManager $entityManager, + private Language $language, + private MetadataProvider $metadataProvider ) { - $this->classFinder = $classFinder; - $this->entityManager = $entityManager; - $this->language = $language; - $this->metadataProvider = $metadataProvider; - $this->systemUtil = new System(); } @@ -121,9 +112,9 @@ class ScheduledJob 'FULL-CRON-PATH' => Util::concatPath($this->systemUtil->getRootDir(), $this->cronFile), ]; - $message = isset($desc[$OS]) ? $desc[$OS] : $desc['default']; + $message = $desc[$OS] ?? $desc['default']; - $command = isset($this->cronSetup[$OS]) ? $this->cronSetup[$OS] : $this->cronSetup['default']; + $command = $this->cronSetup[$OS] ?? $this->cronSetup['default']; foreach ($data as $name => $value) { /** @var string $command */ diff --git a/application/Espo/Core/Utils/System.php b/application/Espo/Core/Utils/System.php index ba6998ea9a..92fd0c04a6 100644 --- a/application/Espo/Core/Utils/System.php +++ b/application/Espo/Core/Utils/System.php @@ -48,17 +48,15 @@ class System preg_match('/^(.*)\/?/i', $serverSoft, $match); } - $serverName = strtolower( + return strtolower( trim($match[1]) ); - - return $serverName; } /** * Get an OS. Details at http://en.wikipedia.org/wiki/Uname. * - * @return string E.g. `windows`, `mac`, `linux`. + * @return ?string E.g. `windows`, `mac`, `linux`. */ public function getOS(): ?string { @@ -98,9 +96,8 @@ class System public function getRootDir(): string { $bPath = realpath('bootstrap.php') ?: ''; - $rootDir = dirname($bPath); - return $rootDir; + return dirname($bPath); } /** diff --git a/application/Espo/Core/Utils/TemplateFileManager.php b/application/Espo/Core/Utils/TemplateFileManager.php index 760f41d5b9..6e0b1c2f6e 100644 --- a/application/Espo/Core/Utils/TemplateFileManager.php +++ b/application/Espo/Core/Utils/TemplateFileManager.php @@ -29,30 +29,17 @@ namespace Espo\Core\Utils; -use Espo\Core\{ - Utils\File\Manager as FileManager, - Exceptions\Error, - Utils\Resource\FileReader, - Utils\Resource\FileReader\Params as FileReaderParams, -}; +use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\Utils\Resource\FileReader; +use Espo\Core\Utils\Resource\FileReader\Params as FileReaderParams; class TemplateFileManager { - private Config $config; - - private FileManager $fileManager; - - private FileReader $fileReader; - public function __construct( - Config $config, - FileManager $fileManager, - FileReader $fileReader - ) { - $this->config = $config; - $this->fileManager = $fileManager; - $this->fileReader = $fileReader; - } + private Config $config, + private FileManager $fileManager, + private FileReader $fileReader + ) {} public function getTemplate( string $type, diff --git a/application/Espo/Core/Utils/ThemeManager.php b/application/Espo/Core/Utils/ThemeManager.php index b46cc937a5..fbfce44cbe 100644 --- a/application/Espo/Core/Utils/ThemeManager.php +++ b/application/Espo/Core/Utils/ThemeManager.php @@ -31,19 +31,13 @@ namespace Espo\Core\Utils; class ThemeManager { - private Config $config; - - private Metadata $metadata; - private string $defaultName = 'Espo'; - private string $defaultStylesheet = 'client/css/espo/espo.css'; - public function __construct(Config $config, Metadata $metadata) - { - $this->config = $config; - $this->metadata = $metadata; - } + public function __construct( + private Config $config, + private Metadata $metadata + ) {} public function getName(): string { diff --git a/application/Espo/Hooks/Common/WebSocketSubmit.php b/application/Espo/Hooks/Common/WebSocketSubmit.php index 192ea9d5d6..65356bfce2 100644 --- a/application/Espo/Hooks/Common/WebSocketSubmit.php +++ b/application/Espo/Hooks/Common/WebSocketSubmit.php @@ -31,28 +31,20 @@ namespace Espo\Hooks\Common; use Espo\ORM\Entity; -use Espo\Core\{ - ORM\Repository\Option\SaveOption, - Utils\Metadata, - Utils\Config, - WebSocket\Submission as WebSocketSubmission}; +use Espo\Core\ORM\Repository\Option\SaveOption; +use Espo\Core\Utils\Config; +use Espo\Core\Utils\Metadata; +use Espo\Core\WebSocket\Submission as WebSocketSubmission; class WebSocketSubmit { public static int $order = 20; - private Metadata $metadata; - - private WebSocketSubmission $webSocketSubmission; - - private Config $config; - - public function __construct(Metadata $metadata, WebSocketSubmission $webSocketSubmission, Config $config) - { - $this->metadata = $metadata; - $this->webSocketSubmission = $webSocketSubmission; - $this->config = $config; - } + public function __construct( + private Metadata $metadata, + private WebSocketSubmission $webSocketSubmission, + private Config $config + ) {} /** * @param array $options diff --git a/application/Espo/Hooks/Note/WebSocketSubmit.php b/application/Espo/Hooks/Note/WebSocketSubmit.php index 651fb7d867..38845769de 100644 --- a/application/Espo/Hooks/Note/WebSocketSubmit.php +++ b/application/Espo/Hooks/Note/WebSocketSubmit.php @@ -30,25 +30,17 @@ namespace Espo\Hooks\Note; use Espo\ORM\Entity; - -use Espo\Core\{ - Utils\Config, - WebSocket\Submission as WebSocketSubmission, -}; +use Espo\Core\Utils\Config; +use Espo\Core\WebSocket\Submission as WebSocketSubmission; class WebSocketSubmit { public static int $order = 20; - private $webSocketSubmission; - - private $config; - - public function __construct(WebSocketSubmission $webSocketSubmission, Config $config) - { - $this->webSocketSubmission = $webSocketSubmission; - $this->config = $config; - } + public function __construct( + private WebSocketSubmission $webSocketSubmission, + private Config $config + ) {} public function afterSave(Entity $entity): void {