type fixes

This commit is contained in:
Yuri Kuznetsov
2022-03-05 18:01:43 +02:00
parent bc4dbacafb
commit b7025bf834
11 changed files with 123 additions and 39 deletions
+12 -2
View File
@@ -36,6 +36,8 @@ use stdClass;
/**
* Contains an an ORM collection and total number of records.
*
* @template TEntity of \Espo\ORM\Entity
*/
class Collection
{
@@ -43,10 +45,16 @@ class Collection
public const TOTAL_HAS_NO_MORE = -2;
private $collection;
/**
* @var OrmCollection<TEntity>
*/
private OrmCollection $collection;
private $total;
private ?int $total;
/**
* @param OrmCollection<TEntity> $collection
*/
public function __construct(OrmCollection $collection, ?int $total = null)
{
$this->collection = $collection;
@@ -63,6 +71,8 @@ class Collection
/**
* Get an ORM collection.
*
* @return OrmCollection<TEntity>
*/
public function getCollection(): OrmCollection
{
@@ -31,15 +31,9 @@ namespace Espo\Core\Record;
class CreateParams
{
/**
* @var bool
*/
private $skipDuplicateCheck = false;
private bool $skipDuplicateCheck = false;
/**
* @var ?string
*/
private $duplicateSourceId = null;
private ?string $duplicateSourceId = null;
public function __construct() {}
@@ -37,20 +37,11 @@ use RuntimeException;
class FieldDuplicatorFactory
{
/**
* @var Defs
*/
private $defs;
private Defs $defs;
/**
* @var Metadata
*/
private $metadata;
private Metadata $metadata;
/**
* @var InjectableFactory
*/
private $injectableFactory;
private InjectableFactory $injectableFactory;
public function __construct(Defs $defs, Metadata $metadata, InjectableFactory $injectableFactory)
{
@@ -75,6 +66,9 @@ class FieldDuplicatorFactory
return $this->getClassName($entityType, $field) !== null;
}
/**
* @return ?class-string
*/
private function getClassName(string $entityType, string $field): ?string
{
$fieldDefs = $this->defs
+10 -2
View File
@@ -37,12 +37,19 @@ use RuntimeException;
class Provider
{
private $metadata;
private Metadata $metadata;
private $injectableFactory;
private InjectableFactory $injectableFactory;
/**
*
* @var array<string,object[]>
*/
private $map = [];
/**
* @var array<string,class-string>
*/
private $typeInterfaceMap = [
Type::BEFORE_CREATE => CreateHook::class,
Type::BEFORE_READ => ReadHook::class,
@@ -79,6 +86,7 @@ class Provider
{
$key = $type . 'HookClassNameList';
/** @var class-string[] */
$classNameList = $this->metadata->get(['recordDefs', $entityType, $key]) ?? [];
$interfaceName = $this->typeInterfaceMap[$type] ?? null;
+2 -2
View File
@@ -44,7 +44,7 @@ use Espo\Core\Record\Hook\{
class HookManager
{
private $provider;
private Provider $provider;
public function __construct(Provider $provider)
{
@@ -126,7 +126,7 @@ class HookManager
}
/**
* @return LinkHook[]
* @return LinkHook<\Espo\ORM\Entity>[]
*/
private function getBeforeLinkHookList(string $entityType): array
{
@@ -44,7 +44,7 @@ class SearchParamsFetcher
{
private const MAX_SIZE_LIMIT = 200;
private $config;
private Config $config;
public function __construct(Config $config)
{
@@ -58,6 +58,9 @@ class SearchParamsFetcher
);
}
/**
* @return array<string,mixed>
*/
private function fetchRaw(Request $request): array
{
$params = $request->hasQueryParam('searchParams') ?
@@ -69,6 +72,9 @@ class SearchParamsFetcher
return $params;
}
/**
* @return array<string,mixed>
*/
private function fetchRawJsonSearchParams(Request $request): array
{
try {
@@ -79,6 +85,9 @@ class SearchParamsFetcher
}
}
/**
* @return array<string,mixed>
*/
private function fetchRawMultipleParams(Request $request): array
{
$params = [];
@@ -147,6 +156,9 @@ class SearchParamsFetcher
return $params;
}
/**
* @param array<string,mixed> $params
*/
private function handleRawParams(array &$params): void
{
if (isset($params['maxSize']) && !is_int($params['maxSize'])) {
@@ -156,6 +168,9 @@ class SearchParamsFetcher
$this->handleMaxSize($params);
}
/**
* @param array<string,mixed> $params
*/
private function handleMaxSize(array &$params): void
{
$value = $params['maxSize'];
@@ -33,13 +33,16 @@ use Espo\Core\Utils\Metadata;
class ApplierClassNameListProvider
{
private $metadata;
private Metadata $metadata;
public function __construct(Metadata $metadata)
{
$this->metadata = $metadata;
}
/**
* @return class-string[]
*/
public function get(string $entityType): array
{
return $this->metadata->get(['recordDefs', $entityType, 'selectApplierClassNameList']) ?? [];
+57 -4
View File
@@ -110,11 +110,13 @@ class Service implements Crud,
use Di\AssignmentCheckerManagerSetter;
use Di\RecordHookManagerSetter;
/** @var bool */
protected $getEntityBeforeUpdate = false;
/** @var ?string */
protected $entityType = null;
/** @var ?StreamService */
private $streamService = null;
/**
@@ -162,26 +164,34 @@ class Service implements Crud,
/** @var string[] */
protected $noEditAccessRequiredLinkList = [];
/** @var bool */
protected $noEditAccessRequiredForLink = false;
/** @var bool */
protected $checkForDuplicatesInUpdate = false;
/** @var bool */
protected $actionHistoryDisabled = false;
/** @var string[] */
protected $duplicatingLinkList = [];
/** @var bool */
protected $listCountQueryDisabled = false;
/** @var ?int */
protected $maxSelectTextAttributeLength = null;
/** @var bool */
protected $maxSelectTextAttributeLengthDisabled = false;
/** @var ?string[] */
protected $selectAttributeList = null;
/** @var string[] */
protected $mandatorySelectAttributeList = [];
/** @var bool */
protected $forceSelectAllAttributes = false;
/** @var string[] */
@@ -189,6 +199,7 @@ class Service implements Crud,
/**
* @todo Move to metadata.
* @var string[]
*/
protected $validateRequiredSkipFieldList = [];
@@ -220,9 +231,11 @@ class Service implements Crud,
*/
protected $recordHookManager;
private $listLoadProcessor;
/** @var ?ListLoadProcessor */
private $listLoadProcessor = null;
private $duplicateFinder;
/** @var ?DuplicateFinder */
private $duplicateFinder = null;
protected const MAX_SELECT_TEXT_ATTRIBUTE_LENGTH = 10000;
@@ -357,6 +370,9 @@ class Service implements Crud,
return $this->listLoadProcessor;
}
/**
* @return void
*/
public function loadAdditionalFields(Entity $entity)
{
$loadProcessor = $this->createReadLoadProcessor();
@@ -378,6 +394,7 @@ class Service implements Crud,
}
/**
* @param stdClass $data
* @return void
* @throws BadRequest
*/
@@ -409,6 +426,11 @@ class Service implements Crud,
return $this->assignmentCheckerManager->check($this->user, $entity);
}
/**
* @param string $attribute
* @param mixed $value
* @return mixed
*/
protected function filterInputAttribute($attribute, $value)
{
if (in_array($attribute, $this->notFilteringAttributeList)) {
@@ -424,9 +446,13 @@ class Service implements Crud,
return $value;
}
/**
* @param stdClass $data
* @return void
*/
protected function filterInput($data)
{
foreach ($this->readOnlyAttributeList as $attribute) {
foreach($this->readOnlyAttributeList as $attribute) {
unset($data->$attribute);
}
@@ -434,7 +460,7 @@ class Service implements Crud,
unset($data->$attribute);
}
foreach ($data as $key => $value) {
foreach (get_object_vars($data) as $key => $value) {
$data->$key = $this->filterInputAttribute($key, $data->$key);
}
@@ -495,6 +521,8 @@ class Service implements Crud,
/**
* @deprecated
* @param stdClass $data
* @return void
*/
protected function handleCreateInput($data)
{
@@ -502,6 +530,8 @@ class Service implements Crud,
/**
* @deprecated
* @param stdClass $data
* @return void
*/
protected function handleInput($data)
{
@@ -776,6 +806,7 @@ class Service implements Crud,
/**
* Find records.
*
* @return RecordCollection<TEntity>
* @throws Forbidden
*/
public function find(SearchParams $searchParams): RecordCollection
@@ -903,6 +934,7 @@ class Service implements Crud,
/**
* Find linked records.
*
* @return RecordCollection<\Espo\ORM\Entity>
* @throws NotFound If a record not found.
* @throws Forbidden If no access.
* @throws Error
@@ -1496,6 +1528,8 @@ class Service implements Crud,
/**
* Find duplicates for an entity.
*
* @return ?Collection<TEntity>
*/
public function findDuplicates(Entity $entity): ?Collection
{
@@ -1544,6 +1578,11 @@ class Service implements Crud,
}
}
/**
* @return RecordCollection<\Espo\ORM\Entity>
* @throws NotFound
* @throws Forbidden
*/
protected function findLinkedFollowers(string $id, SearchParams $params): RecordCollection
{
$entity = $this->getRepository()->getById($id);
@@ -1627,6 +1666,10 @@ class Service implements Crud,
}
}
/**
* @param string $type
* @return string[]
*/
protected function getFieldByTypeList($type)
{
return $this->fieldUtil->getFieldByTypeList($this->entityType, $type);
@@ -1689,6 +1732,7 @@ class Service implements Crud,
/**
* @param stdClass $data
* @return void
*/
protected function beforeCreateEntity(Entity $entity, $data)
{
@@ -1696,6 +1740,7 @@ class Service implements Crud,
/**
* @param stdClass $data
* @return void
*/
protected function afterCreateEntity(Entity $entity, $data)
{
@@ -1703,6 +1748,7 @@ class Service implements Crud,
/**
* @param stdClass $data
* @return void
*/
protected function beforeUpdateEntity(Entity $entity, $data)
{
@@ -1710,15 +1756,22 @@ class Service implements Crud,
/**
* @param stdClass $data
* @return void
*/
protected function afterUpdateEntity(Entity $entity, $data)
{
}
/**
* @return void
*/
protected function beforeDeleteEntity(Entity $entity)
{
}
/**
* @return void
*/
protected function afterDeleteEntity(Entity $entity)
{
}
@@ -46,15 +46,21 @@ class ServiceContainer
private const RECORD_TREE_SERVICE_NAME = 'RecordTree';
/**
* @var array<string,string>
*/
private $defaultTypeMap = [
'CategoryTree' => self::RECORD_TREE_SERVICE_NAME,
];
/**
* @var array<string,Service<\Espo\ORM\Entity>>
*/
private $data = [];
private $serviceFactory;
private ServiceFactory $serviceFactory;
private $metadata;
private Metadata $metadata;
public function __construct(ServiceFactory $serviceFactory, Metadata $metadata)
{
@@ -62,6 +68,9 @@ class ServiceContainer
$this->metadata = $metadata;
}
/**
* @return Service<\Espo\ORM\Entity>
*/
public function get(string $entityType): Service
{
if (!array_key_exists($entityType, $this->data)) {
@@ -31,9 +31,9 @@ namespace Espo\Core\Record;
class UpdateParams
{
private $skipDuplicateCheck = false;
private bool $skipDuplicateCheck = false;
private $versionNumber = null;
private ?int $versionNumber = null;
public function __construct() {}
+1 -3
View File
@@ -29,8 +29,6 @@
namespace Espo\Services;
use Espo\Entities\Note;
use Espo\Core\{
Record\Collection as RecordCollection,
Exceptions\Error,
@@ -159,7 +157,7 @@ class Notification extends \Espo\Services\Record
switch ($entity->get('type')) {
case 'Note':
case 'MentionInPost':
/** @var ?Note $note */
/** @var ?\Espo\Entities\Note $note */
$note = $this->entityManager->getEntity('Note', $data->noteId);
if (!$note) {