type fixes

This commit is contained in:
Yuri Kuznetsov
2022-03-19 10:16:36 +02:00
parent 77e02fd66f
commit ab137263dc
21 changed files with 72 additions and 35 deletions

View File

@@ -45,7 +45,7 @@ use Espo\Core\{
class AccessCheckerFactory
{
/**
* @var class-string
* @var class-string<AccessChecker>
*/
private string $defaultClassName = DefaultAccessChecker::class;
@@ -80,11 +80,12 @@ class AccessCheckerFactory
}
/**
* @return class-string
* @return class-string<AccessChecker>
* @throws NotImplemented
*/
private function getClassName(string $scope): string
{
/** @var ?class-string<AccessChecker> */
$className1 = $this->metadata->get(['aclDefs', $scope, 'accessCheckerClassName']);
if ($className1) {
@@ -99,6 +100,7 @@ class AccessCheckerFactory
$className2 = $this->classFinder->find('Acl', $scope);
if ($className2) {
/** @var ?class-string<AccessChecker> */
return $className2;
}

View File

@@ -40,7 +40,7 @@ use Espo\Core\{
class AssignmentCheckerFactory
{
/**
* @var class-string
* @var class-string<AssignmentChecker<\Espo\Core\ORM\Entity>>
*/
private string $defaultClassName = DefaultAssignmentChecker::class;
@@ -70,12 +70,12 @@ class AssignmentCheckerFactory
}
/**
* @return class-string
* @return class-string<AssignmentChecker<\Espo\ORM\Entity>>
* @throws NotImplemented
*/
private function getClassName(string $scope): string
{
/** @var ?class-string */
/** @var ?class-string<AssignmentChecker<\Espo\ORM\Entity>> */
$className = $this->metadata->get(['aclDefs', $scope, 'assignmentCheckerClassName']);
if ($className) {
@@ -86,6 +86,7 @@ class AssignmentCheckerFactory
throw new NotImplemented();
}
/** @var class-string<AssignmentChecker<\Espo\ORM\Entity>> */
return $this->defaultClassName;
}
}

View File

@@ -101,27 +101,22 @@ class GlobalRestricton
$this->fieldUtil = $fieldUtil;
$this->log = $log;
$isFromCache = false;
$useCache = $config->get('useCache');
if ($useCache && $this->dataCache->has($this->cacheKey)) {
$this->data = $this->dataCache->get($this->cacheKey);
/** @var stdClass */
$cachedData = $this->dataCache->get($this->cacheKey);
$isFromCache = true;
$this->data = $cachedData;
if (!$this->data instanceof stdClass) {
$this->log->error("ACL GlobalRestricton: Bad data fetched from cache.");
$this->data = null;
}
return;
}
if (!$this->data) {
$this->buildData();
}
if ($useCache && !$isFromCache) {
if ($useCache) {
$this->storeCacheFile();
}
}
@@ -133,12 +128,15 @@ class GlobalRestricton
protected function buildData(): void
{
/** @var string[] */
$scopeList = array_keys($this->metadata->get(['entityDefs'], []));
$data = (object) [];
foreach ($scopeList as $scope) {
/** @var string[] */
$fieldList = array_keys($this->metadata->get(['entityDefs', $scope, 'fields'], []));
/** @var string[] */
$linkList = array_keys($this->metadata->get(['entityDefs', $scope, 'links'], []));
$isNotEmpty = false;

View File

@@ -95,7 +95,10 @@ class Map
$this->cacheKey = $cacheKeyProvider->get();
if ($this->config->get('useCache') && $this->dataCache->has($this->cacheKey)) {
$this->data = $this->dataCache->get($this->cacheKey);
/** @var stdClass */
$cachedData = $this->dataCache->get($this->cacheKey);
$this->data = $cachedData;
}
else {
$this->data = $this->dataBuilder->build($table);

View File

@@ -43,10 +43,11 @@ class MetadataProvider
}
/**
* @return array<int,string>
* @return string[]
*/
public function getScopeList(): array
{
/** @var string[] */
return array_keys($this->metadata->get('scopes') ?? []);
}
@@ -56,10 +57,11 @@ class MetadataProvider
}
/**
* @return array<int,string>
* @return string[]
*/
public function getScopeFieldList(string $scope): array
{
/** @var string[] */
return array_keys($this->metadata->get(['entityDefs', $scope, 'fields']) ?? []);
}

View File

@@ -44,7 +44,7 @@ use Espo\Core\{
class OwnershipCheckerFactory
{
/**
* @var class-string
* @var class-string<OwnershipChecker>
*/
private string $defaultClassName = DefaultOwnershipChecker::class;
@@ -75,12 +75,12 @@ class OwnershipCheckerFactory
}
/**
* @return class-string
* @return class-string<OwnershipChecker>
* @throws NotImplemented
*/
private function getClassName(string $scope): string
{
/** @var ?class-string */
/** @var ?class-string<OwnershipChecker> */
$className = $this->metadata->get(['aclDefs', $scope, 'ownershipCheckerClassName']);
if ($className) {

View File

@@ -146,7 +146,10 @@ class DefaultTable implements Table
$this->cacheKey = $cacheKeyProvider->get();
if ($config->get('useCache') && $dataCache->has($this->cacheKey)) {
$this->data = $dataCache->get($this->cacheKey);
/** @var stdClass */
$cachedData = $dataCache->get($this->cacheKey);
$this->data = $cachedData;
}
else {
$this->load();

View File

@@ -658,6 +658,7 @@ class AclManager
$acl = new $className($this, $user);
/** @var Acl */
return $acl;
}

View File

@@ -80,7 +80,7 @@ class ActionFactory
}
/**
* @return ?class-string
* @return ?class-string<Action>
*/
private function getClassName(string $action, ?string $entityType): ?string
{
@@ -92,16 +92,18 @@ class ActionFactory
}
}
/** @var ?class-string<Action> */
return $this->metadata->get(
['app', 'actions', $action, 'implementationClassName']
);
}
/**
* @return ?class-string
* @return ?class-string<Action>
*/
private function getEntityTypeClassName(string $action, string $entityType): ?string
{
/** @var ?class-string<Action> */
return $this->metadata->get(
['recordDefs', $entityType, 'actions', $action, 'implementationClassName']
);

View File

@@ -40,6 +40,8 @@ use Espo\Core\{
Acl\Table,
};
use stdClass;
class Merge implements Action
{
private $acl;
@@ -67,7 +69,7 @@ class Merge implements Action
throw new BadRequest("No 'sourceIdList'.");
}
if (!is_object($attributes)) {
if (!$attributes instanceof stdClass) {
throw new BadRequest("No 'attributes'.");
}

View File

@@ -69,7 +69,10 @@ class ActionProcessor
$requestMethod = $request->getMethod();
if ($actionName == 'index') {
if (
$actionName == 'index' &&
property_exists($controller, 'defaultAction')
) {
$actionName = $controller::$defaultAction ?? 'index';
}
@@ -174,7 +177,10 @@ class ActionProcessor
return false;
}
$firstParamClass = new ReflectionClass($type->getName());
/** @var class-string */
$className = $type->getName();
$firstParamClass = new ReflectionClass($className);
if (
$firstParamClass->getName() === Request::class ||

View File

@@ -39,6 +39,7 @@ use Espo\Core\Authentication\Authentication;
use Espo\Core\Authentication\AuthenticationData;
use Espo\Core\Authentication\Result;
use Espo\Core\Utils\Log;
use Espo\Core\Utils\Json;
use Exception;
@@ -177,12 +178,14 @@ class Auth
*/
protected function decodeAuthorizationString(string $string): array
{
/** @var string */
$stringDecoded = base64_decode($string);
if (strpos($stringDecoded, ':') === false) {
throw new BadRequest("Auth: Bad authorization string provided.");
}
/** @var array{string,string} */
return explode(':', $stringDecoded, 2);
}
@@ -199,7 +202,7 @@ class Auth
'data' => $result->getData(),
];
$response->writeBody(json_encode($bodyData));
$response->writeBody(Json::encode($bodyData));
}
protected function handleException(Response $response, Exception $e): void

View File

@@ -103,26 +103,31 @@ class Application
protected function getInjectableFactory(): InjectableFactory
{
/** @var InjectableFactory */
return $this->container->get('injectableFactory');
}
protected function getApplicationUser(): ApplicationUser
{
/** @var ApplicationUser */
return $this->container->get('applicationUser');
}
protected function getClientManager(): ClientManager
{
/** @var ClientManager */
return $this->container->get('clientManager');
}
protected function getMetadata(): Metadata
{
/** @var Metadata */
return $this->container->get('metadata');
}
protected function getConfig(): Config
{
/** @var Config */
return $this->container->get('config');
}

View File

@@ -70,7 +70,7 @@ class RunnerRunner
if (
$class->getStaticPropertyValue('cli', false) &&
substr(php_sapi_name(), 0, 3) !== 'cli'
substr(php_sapi_name() ?: '', 0, 3) !== 'cli'
) {
throw new RunnerException("Can be run only via CLI.");
}

View File

@@ -74,6 +74,7 @@ class ApplicationState
throw new Error("Can't get portal for non-portal application.");
}
/** @var PortalEntity */
return $this->container->get('portal');
}
@@ -94,6 +95,7 @@ class ApplicationState
throw new Error("User is not yet available.");
}
/** @var UserEntity */
return $this->container->get('user');
}

View File

@@ -84,12 +84,13 @@ class Manager
}
/**
* @return class-string[]
* @return class-string<BeforeLogin|OnResult>[]
*/
private function getHookClassNameList(string $type): array
{
$key = $type . 'HookClassNameList';
/** @var class-string<BeforeLogin|OnResult>[] */
return $this->metadata->get(['app', 'authentication', $key]) ?? [];
}
@@ -101,6 +102,7 @@ class Manager
$list = [];
foreach ($this->getHookClassNameList('beforeLogin') as $className) {
/** @var class-string<BeforeLogin> $className */
$list[] = $this->injectableFactory->create($className);
}
@@ -115,6 +117,7 @@ class Manager
$list = [];
foreach ($this->getHookClassNameList('onFail') as $className) {
/** @var class-string<OnResult> $className */
$list[] = $this->injectableFactory->create($className);
}
@@ -129,6 +132,7 @@ class Manager
$list = [];
foreach ($this->getHookClassNameList('onSuccess') as $className) {
/** @var class-string<OnResult> $className */
$list[] = $this->injectableFactory->create($className);
}
@@ -143,6 +147,7 @@ class Manager
$list = [];
foreach ($this->getHookClassNameList('onSuccessByToken') as $className) {
/** @var class-string<OnResult> $className */
$list[] = $this->injectableFactory->create($className);
}
@@ -157,6 +162,7 @@ class Manager
$list = [];
foreach ($this->getHookClassNameList('onSecondStepRequired') as $className) {
/** @var class-string<OnResult> $className */
$list[] = $this->injectableFactory->create($className);
}

View File

@@ -52,14 +52,14 @@ class LoginFactory
public function create(string $method, bool $isPortal = false): Login
{
/** @var class-string */
/** @var class-string<Login> */
$className = $this->metadata->get(['authenticationMethods', $method, 'implementationClassName']);
if (!$className) {
$sanitizedName = preg_replace('/[^a-zA-Z0-9]+/', '', $method);
if (!class_exists($className)) {
/** @var class-string */
/** @var class-string<Login> */
$className = "Espo\\Core\\Authentication\\Logins\\" . $sanitizedName;
}
}

View File

@@ -461,6 +461,7 @@ class LDAP implements Login
$fields = [];
foreach ($this->$typeMap as $fieldName => $fieldValue) {
/** @var string $fieldName */
if (isset($options[$fieldValue])) {
$fields[$fieldName] = $options[$fieldValue];
}

View File

@@ -47,7 +47,7 @@ class LoginFactory
public function create(string $method): Login
{
/** @var ?class-string */
/** @var ?class-string<Login> */
$className = $this->metadata->get(['app', 'authentication2FAMethods', $method, 'loginClassName']);
if (!$className) {

View File

@@ -271,7 +271,7 @@ class Util
{
$fromNumber = $this->config->get('outboundSmsFromNumber');
$bodyTpl = $this->language->translate('yourAuthenticationCode', 'messages', 'User');
$bodyTpl = $this->language->translateLabel('yourAuthenticationCode', 'messages', 'User');
$body = str_replace('{code}', $code, $bodyTpl);

View File

@@ -48,7 +48,7 @@ class UserSetupFactory
public function create(string $method): UserSetup
{
/** @var ?class-string */
/** @var ?class-string<UserSetup> */
$className = $this->metadata->get(['app', 'authentication2FAMethods', $method, 'userSetupClassName']);
if (!$className) {