Skip to content

Commit

Permalink
IBX-7935: Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Apr 3, 2024
1 parent 72fd718 commit 7534cba
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 105 deletions.
53 changes: 3 additions & 50 deletions src/lib/Event/UserCreateFieldOptionsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,72 +11,25 @@
use Ibexa\Contracts\ContentForms\Data\Content\FieldData;
use Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct;
use Symfony\Component\Form\FormInterface;
use Symfony\Contracts\EventDispatcher\Event;

final class UserCreateFieldOptionsEvent extends Event
final class UserCreateFieldOptionsEvent extends UserStructFieldOptionsEvent
{
/** @var \Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct */
private $userCreateStruct;

/** @var \Symfony\Component\Form\FormInterface */
private $parentForm;

/** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData */
private $fieldData;

/** @var array<string, mixed> */
private $options;

public function __construct(
UserCreateStruct $userCreateStruct,
FormInterface $parentForm,
FieldData $fieldData,
array $options
) {
$this->userCreateStruct = $userCreateStruct;
$this->parentForm = $parentForm;
$this->fieldData = $fieldData;
$this->options = $options;

parent::__construct($parentForm, $fieldData, $options);
}

public function getUserCreateStruct(): UserCreateStruct
{
return $this->userCreateStruct;
}

public function getParentForm(): FormInterface
{
return $this->parentForm;
}

public function getFieldData(): FieldData
{
return $this->fieldData;
}

/**
* @return array<string, mixed>
*/
public function getOptions(): array
{
return $this->options;
}

/**
* @param array<string, mixed> $options
*/
public function setOptions(array $options): void
{
$this->options = $options;
}

public function setOption(string $option, $value): void
{
$this->options[$option] = $value;
}

public function getOption(string $option)
{
return $this->options[$option] ?? null;
}
}
71 changes: 71 additions & 0 deletions src/lib/Event/UserStructFieldOptionsEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\ContentForms\Event;

use Ibexa\Contracts\ContentForms\Data\Content\FieldData;
use Symfony\Component\Form\FormInterface;
use Symfony\Contracts\EventDispatcher\Event;

abstract class UserStructFieldOptionsEvent extends Event
{
/** @var \Symfony\Component\Form\FormInterface */
protected $parentForm;

/** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData */
protected $fieldData;

/** @var array<string, mixed> */
protected $options;

public function __construct(
FormInterface $parentForm,
FieldData $fieldData,
array $options
) {
$this->parentForm = $parentForm;
$this->fieldData = $fieldData;
$this->options = $options;
}

public function getParentForm(): FormInterface
{
return $this->parentForm;
}

public function getFieldData(): FieldData
{
return $this->fieldData;
}

/**
* @return array<string, mixed>
*/
public function getOptions(): array
{
return $this->options;
}

/**
* @param array<string, mixed> $options
*/
public function setOptions(array $options): void
{
$this->options = $options;
}

public function setOption(string $option, $value): void
{
$this->options[$option] = $value;
}

public function getOption(string $option)
{
return $this->options[$option] ?? null;
}
}
58 changes: 3 additions & 55 deletions src/lib/Event/UserUpdateFieldOptionsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,15 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\User\UserUpdateStruct;
use Symfony\Component\Form\FormInterface;
use Symfony\Contracts\EventDispatcher\Event;

final class UserUpdateFieldOptionsEvent extends Event
final class UserUpdateFieldOptionsEvent extends UserStructFieldOptionsEvent
{
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content */
private $content;

/** @var \Ibexa\Contracts\Core\Repository\Values\User\UserUpdateStruct */
private $userUpdateStruct;

/** @var \Symfony\Component\Form\FormInterface */
private $parentForm;

/** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData */
private $fieldData;

/** @var array<string, mixed> */
private $options;

public function __construct(
Content $content,
UserUpdateStruct $userUpdateStruct,
Expand All @@ -40,59 +30,17 @@ public function __construct(
) {
$this->content = $content;
$this->userUpdateStruct = $userUpdateStruct;
$this->parentForm = $parentForm;
$this->fieldData = $fieldData;
$this->options = $options;

parent::__construct($parentForm, $fieldData, $options);
}

public function getContent(): Content
{
return $this->content;
}

public function setContent(Content $content): void
{
$this->content = $content;
}

public function getUserUpdateStruct(): UserUpdateStruct
{
return $this->userUpdateStruct;
}

public function getParentForm(): FormInterface
{
return $this->parentForm;
}

public function getFieldData(): FieldData
{
return $this->fieldData;
}

/**
* @return array<string, mixed>
*/
public function getOptions(): array
{
return $this->options;
}

/**
* @param array<string, mixed> $options
*/
public function setOptions(array $options): void
{
$this->options = $options;
}

public function setOption(string $option, $value): void
{
$this->options[$option] = $value;
}

public function getOption(string $option)
{
return $this->options[$option] ?? null;
}
}

0 comments on commit 7534cba

Please sign in to comment.