getName(); $isPro = (bool)($fieldInfo->getArguments()['a-pro'] ?? false); // @phpstan-ignore-next-line $newValue = $this->{$fieldName}; /** * @var mixed $originValue */ $originValue = null !== $originInstance ? // @phpstan-ignore-next-line $originInstance->{$fieldName} : ($fieldInfo->getArguments()['default_value'] ?? null); $isGroup = $newValue instanceof self; $isGroupArray = is_array($newValue) && count($newValue) > 0 && $newValue[0] instanceof self; $isPlainType = !$isGroup && !$isGroupArray; if (!$isPro && $isPlainType) { continue; } // default value is not available if (is_null($originValue) && $isPlainType) { continue; } if ($isPro && !$isGroup && !$isGroupArray) { // potential number string to int, so it doesn't cause fatal error // check exactly the field default initially, and only then origin // @phpstan-ignore-next-line $originValue = true === is_int($this->{$fieldName}) && true === is_numeric($originValue) ? (int)$originValue : $originValue; // @phpstan-ignore-next-line $this->{$fieldName} = $originValue; continue; } if ($isGroup) { /** * @var Group $originValue */ $newValue->resetProFields($originValue); continue; } // group array $itemsCount = count($newValue); /** * @var Group[] $newValue */ for ($i = 0; $i < $itemsCount; $i++) { /** * @var array $originValue */ $newValue[$i]->resetProFields($originValue[$i] ?? null); } } } }