Skip to content

Commit

Permalink
LegalDocuments: Annotation cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lscharmer authored and mjansenDatabay committed Sep 10, 2024
1 parent 9fe9f68 commit 0cbb7f3
Show file tree
Hide file tree
Showing 49 changed files with 150 additions and 86 deletions.
2 changes: 1 addition & 1 deletion components/ILIAS/DataProtection/classes/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function uses(UseSlot $slot, LazyProvide $provide): UseSlot

$slot = $slot->showOnLoginPage($blocks->slot()->showOnLoginPage());

$agreement = $blocks->slot()->agreement($user, $global_settings);
$agreement = $blocks->slot()->agreement($user);
$constraint = $this->container->refinery()->custom()->constraint(...);

if ($global_settings->noAcceptance()->value()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use ILIAS\DataProtection\Consumer;
use ILIAS\DataProtection\Settings;
use ILIAS\LegalDocuments\ConsumerToolbox\Settings as SettingsInterface;
use ILIAS\LegalDocuments\ConsumerToolbox\Setting;
use ILIAS\LegalDocuments\ConsumerToolbox\KeyValueStore\ReadOnlyStore;
use ILIAS\LegalDocuments\ConsumerToolbox\KeyValueStore\ILIASSettingStore;
Expand All @@ -34,6 +33,7 @@
use ILIAS\UI\Component\Component;
use ILIAS\Data\Factory as DataFactory;
use ILIAS\LegalDocuments\ConsumerToolbox\UI;
use ILIAS\UI\Component\Input\Input;

/**
* @ilCtrl_isCalledBy ilObjDataProtectionGUI: ilAdministrationGUI
Expand All @@ -45,7 +45,7 @@ final class ilObjDataProtectionGUI extends ilObject2GUI
private readonly ilLegalDocumentsAdministrationGUI $legal_documents;
private readonly Container $container;
private readonly Config $config;
private readonly SettingsInterface $data_protection_settings;
private readonly Settings $data_protection_settings;
private readonly UI $ui;

public function __construct()
Expand Down Expand Up @@ -214,6 +214,9 @@ private function form(): Component
});
}

/**
* @param array<string|int, Input> $fields
*/
private function optionalGroup(string $label, string $description, array $fields): OptionalGroup
{
return $this->ui->create()->input()->field()->optionalGroup(
Expand All @@ -223,6 +226,9 @@ private function optionalGroup(string $label, string $description, array $fields
);
}

/**
* @param array<string|int, string> $options
*/
private function radio(string $prefix, array $options): Component
{
$field = $this->ui->create()->input()->field()->radio($this->ui->txt($prefix), $this->ui->txt($prefix . '_desc'));
Expand Down
43 changes: 28 additions & 15 deletions components/ILIAS/LegalDocuments/classes/Administration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

namespace ILIAS\LegalDocuments;

use ILIAS\UI\Component\Button\Button;
use ILIAS\UI\Component\Button\Standard as Button;
use ILIAS\LegalDocuments\DocumentId;
use ILIAS\LegalDocuments\Value\Criterion;
use ILIAS\LegalDocuments\Value\Document;
use ILIAS\LegalDocuments\Value\CriterionContent;
use ILIAS\DI\Container;
use ILIAS\UI\Component\Component;
use ilDatePresentation;
Expand All @@ -44,6 +45,7 @@
use ILIAS\LegalDocuments\Legacy\Confirmation;
use ilObjUserFolderGUI;
use ILIAS\LegalDocuments\Value\DocumentContent;
use ILIAS\UI\Component\Input\Container\Form\Form;

class Administration
{
Expand Down Expand Up @@ -112,6 +114,9 @@ public function withDocumentAndCriterion(Closure $proc): void
$proc($document, $criterion);
}

/**
* @return list<Document>
*/
public function retrieveDocuments(): array
{
$ids = $this->retrieveIds();
Expand All @@ -123,13 +128,16 @@ public function retrieveDocuments(): array
return $documents;
}

/**
* @return list<int>
*/
public function retrieveIds(): array
{
return $this->container->http()->wrapper()->post()->retrieve('ids', $this->container->refinery()->to()->listOf($this->container->refinery()->kindlyTo()->int()));
}

/**
* @param Closure(Closure(string): string, DocumentId, bool): void $then
* @param Closure(Closure(string): string, string, DocumentId, bool): mixed $then
*/
public function idOrHash(object $gui, Closure $then): void
{
Expand All @@ -144,13 +152,13 @@ public function idOrHash(object $gui, Closure $then): void

}

public function targetWithDoc(object $gui, $document, string $cmd, string $method = 'getLinkTarget'): string
public function targetWithDoc(object $gui, Document $document, string $cmd, string $method = 'getLinkTarget'): string
{
$link = $this->willLinkWith($gui, ['doc_id' => (string) $document->id()]);
return $link($cmd, $method);
}

public function targetWithDocAndCriterion(object $gui, $document, $criterion, string $cmd, string $method = 'getLinkTarget')
public function targetWithDocAndCriterion(object $gui, Document $document, Criterion $criterion, string $cmd, string $method = 'getLinkTarget'): string
{
$link = $this->willLinkWith($gui, [
'doc_id' => (string) $document->id(),
Expand All @@ -161,7 +169,9 @@ public function targetWithDocAndCriterion(object $gui, $document, $criterion, st
}

/**
* @param array<string, string> $parameters
* @param string|object $gui
* @param array<int|string, string> $parameters
* @return Closure(string, ?string?): string
*/
public function willLinkWith($gui, array $parameters = []): Closure
{
Expand All @@ -170,11 +180,11 @@ public function willLinkWith($gui, array $parameters = []): Closure
$method ??= $class === $gui ? 'getLinkTargetByClass' : 'getLinkTarget';
$array = $this->container->ctrl()->getParameterArrayByClass($class);
foreach ($parameters as $key => $value) {
$this->container->ctrl()->setParameterByClass($class, $key, $value);
$this->container->ctrl()->setParameterByClass($class, (string) $key, $value);
}
$link = $this->container->ctrl()->$method($gui, $cmd);
foreach ($parameters as $key => $_) {
$this->container->ctrl()->setParameterByClass($class, $key, $array[$key] ?? '');
$this->container->ctrl()->setParameterByClass($class, (string) $key, $array[$key] ?? '');
}

return $link;
Expand All @@ -184,7 +194,7 @@ public function willLinkWith($gui, array $parameters = []): Closure
/**
* @param Closure(array): void $then
*/
public function withFormData($form, Closure $then)
public function withFormData(Form $form, Closure $then): Form
{
$request = $this->container->http()->request();
if ($request->getMethod() !== 'POST') {
Expand Down Expand Up @@ -227,7 +237,7 @@ public function currentDocument(): Result
return $this->container->refinery()->kindlyTo()->int()->applyTo(new Ok($doc_id))->then($repo->find(...));
}

public function criterionForm(string $url, Document $document, $criterion = null)
public function criterionForm(string $url, Document $document, ?CriterionContent $criterion = null): Form
{
$groups = $this->config->legalDocuments()->document()->conditionGroups($criterion);
$group = $this->ui->create()->input()->field()->switchableGroup($groups->choices(), $this->ui->txt('form_criterion'));
Expand Down Expand Up @@ -282,7 +292,7 @@ public function uploadContent(): string
}

/**
* @param list<Component>|Component $component
* @param list<Component>|Component|string $component
*/
public function setContent($component): void
{
Expand Down Expand Up @@ -317,7 +327,7 @@ public function render($component): string
}

/**
* @param list<Button> $buttons
* @param array<Button> $buttons
*/
public function resetBox(DateTimeImmutable $reset_date, array $buttons = []): Component
{
Expand All @@ -328,7 +338,7 @@ public function resetBox(DateTimeImmutable $reset_date, array $buttons = []): Co
->withButtons($buttons);
}

public function resetButton(string $confirm_reset_link): Component
public function resetButton(string $confirm_reset_link): Button
{
return $this->ui->create()->button()->standard(
$this->ui->txt('reset_for_all_users'),
Expand All @@ -340,7 +350,7 @@ public function resetButton(string $confirm_reset_link): Component
* @param Closure(string): string $link
* @param Closure(): Result<DocumentContent> $document_content
*/
public function documentForm(Closure $link, string $title, Closure $document_content, bool $may_be_new): Component
public function documentForm(Closure $link, string $title, Closure $document_content, bool $may_be_new): Form
{
$edit_link = $link('editDocument');
$content_title = $may_be_new ? 'form_document' : 'form_document_new';
Expand Down Expand Up @@ -374,7 +384,10 @@ public function saveDocumentOrder(array $documents, array $order_by_document): v
}

/**
* @param Closure(list<Document>, array<int, int>) $proc
* @template A
*
* @param Closure(list<Document>, array<int, int>): A $proc
* @return A
*/
public function withDocumentsAndOrder(Closure $proc)
{
Expand Down Expand Up @@ -434,7 +447,7 @@ public function externalSettingsMessage(bool $enabled): Component
)->withLinks([
$this->ui->create()->link()->standard(
$this->ui->txt('adm_external_setting_edit'),
$this->willLinkWith(ilObjUserFolderGUI::class, ['ref_id' => USER_FOLDER_ID])('generalSettings')
$this->willLinkWith(ilObjUserFolderGUI::class, ['ref_id' => (string) USER_FOLDER_ID])('generalSettings')
)
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
use ilObjectDataCache;
use ilRbacReview;
use Closure;
use ILIAS\UI\Component\Input\Field\Radio;

class RoleDefinition implements ConditionDefinition
{
/**
* @param Closure(array<string, mixed>): Constraint $required
* @param Closure(array<int|string, mixed>): Constraint $required
*/
public function __construct(
private readonly UI $ui,
Expand Down Expand Up @@ -75,9 +76,9 @@ public function withCriterion(CriterionContent $criterion): Condition
}

/**
* @param array<string, string> $options
* @param array<string|int, string> $options
*/
private function radio($lang_key, array $options, $value)
private function radio(string $lang_key, array $options, $value): Radio
{
$field = $this->ui->create()->input()->field()->radio($lang_key);
foreach ($options as $key => $label) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ interface ConditionDefinition
{
public function formGroup(array $arguments = []): Group;
public function withCriterion(CriterionContent $criterion): Condition;
public function translatedType(): string;
}
6 changes: 6 additions & 0 deletions components/ILIAS/LegalDocuments/classes/Conductor.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public function findGotoLink(string $goto_target): Result
)->map(fn($goto_link) => $goto_link->target());
}

/**
* @return list<Intercept>
*/
public function intercepting(): array
{
return $this->internal->all('intercept');
Expand All @@ -176,6 +179,9 @@ public function selfRegistration(): SelfRegistration
return new Bundle($this->internal->all('self-registration'));
}

/**
* @return array<string|int, string>
*/
public function userManagementFields(ilObjUser $user): array
{
return array_reduce(
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/LegalDocuments/classes/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface Consumer
{
/**
* @template A
* @param UseSlot<A> $lens
* @param UseSlot<A> $slot
* @return UseSlot<A>
*/
public function uses(UseSlot $slot, LazyProvide $provide): UseSlot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,18 @@

use ILIAS\LegalDocuments\ConsumerSlots\Agreement as AgreementInterface;
use ILIAS\LegalDocuments\Value\Document;
use ILIAS\LegalDocuments\Provide;
use ILIAS\UI\Component\Component;
use ILIAS\LegalDocuments\PageFragment;
use ILIAS\LegalDocuments\PageFragment\PageContent;
use ILIAS\Data\Result;
use ILIAS\Data\Result\Ok;
use ilLegacyFormElementsUtil;
use ilSystemSupportContacts;
use Psr\Http\Message\RequestInterface;
use ilSession;
use ILIAS\LegalDocuments\ConsumerToolbox\Settings;
use ILIAS\LegalDocuments\ConsumerToolbox\User;
use ILIAS\LegalDocuments\ConsumerToolbox\Marshal;
use ILIAS\LegalDocuments\ConsumerToolbox\Setting;
use ILIAS\LegalDocuments\ConsumerToolbox\Routing;
use ILIAS\LegalDocuments\ConsumerToolbox\UI;
use Closure;
use ILIAS\UI\Component\Input\Container\Form\Form;

final class Agreement implements AgreementInterface
{
Expand All @@ -47,7 +42,6 @@ final class Agreement implements AgreementInterface
*/
public function __construct(
private readonly User $user,
private readonly Settings $settings,
private readonly UI $ui,
private readonly Routing $routing,
private readonly Closure $with_request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
use ILIAS\LegalDocuments\Provide;
use ILIAS\Data\Result\Ok;
use Closure;
use ILIAS\UI\Component\Component;
use ilFormPropertyGUI;

final class SelfRegistration implements SelfRegistrationInterface
{
private readonly Closure $create_input;

/**
* @param Closure(ilObjUser $user): User
* @param Closure(list<Component>|Component): string $render
* @param Closure(ilObjUser): User $build_user
* @param Closure(string): object $create_input
Expand Down Expand Up @@ -86,6 +87,9 @@ public function userCreation(ilObjUser $user): void
($this->build_user)($user)->acceptMatchingDocument();
}

/**
* @return array<ilFormPropertyGUI|ilFormSectionHeaderGUI>
*/
private function guis(Document $document): array
{
$header = ($this->create_input)(ilFormSectionHeaderGUI::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use ILIAS\LegalDocuments\ConsumerToolbox\UI;
use ILIAS\UI\Component\Component;
use Closure;
use ilTemplate;

final class ShowOnLoginPage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use ILIAS\Refinery\Factory as Refinery;
use ILIAS\LegalDocuments\ConsumerToolbox\Settings;
use ilStartUpGUI;
use ILIAS\Refinery\Transformation;

final class WithdrawProcess implements WithdrawProcessInterface
{
Expand Down Expand Up @@ -169,11 +170,6 @@ private function sendMail(): void
$mail->sendGeneric($this->ui->txt('withdrawal_mail_subject'), $this->user->format($this->ui->txt('withdrawal_mail_text')));
}

private function refuseContent($components): PageFragment
{
return new PageContent($this->ui->txt('refuse_tos_acceptance'), $components);
}

private function query(string $query_parameter): ?string
{
return ($this->query_parameter)($query_parameter, fn(Refinery $r) => $r->byTrying([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace ILIAS\LegalDocuments\ConsumerToolbox;

use ilCtrl;
use ilCtrlInterface;
use Closure;

class Routing
Expand All @@ -30,14 +30,14 @@ class Routing
* @param Closure(): string $logout_url
*/
public function __construct(
private readonly ilCtrl $ctrl,
private readonly ilCtrlInterface $ctrl,
private readonly SelectSetting $session,
private readonly Closure $redirect_to_starting_page,
private readonly Closure $logout_url
) {
}

public function ctrl(): ilCtrl
public function ctrl(): ilCtrlInterface
{
return $this->ctrl;
}
Expand Down
Loading

0 comments on commit 0cbb7f3

Please sign in to comment.