Skip to content

Commit

Permalink
Refactor and add constructors in Reorder classes
Browse files Browse the repository at this point in the history
Introduced constructors in `AbstractReorder`, `FormReorder`, `ShowReorder`, and `ShowAndFormReorder` classes to set initial values. Also removed unneeded import, improved function return types and removed unneeded whitespace. The refactoring improves code readability and makes initial state setting more explicit.
  • Loading branch information
ychadwick committed Feb 22, 2024
1 parent 75a51d0 commit 0d7c67a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/Admin/BaseAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public function getTrackedActions(): array

protected function configureListFields(ListMapper $list): void
{

$this->getSonataAnnotationReader()?->configureListFields($this->getClass(), $list);
}

Expand Down
7 changes: 5 additions & 2 deletions src/Annotation/Order/AbstractReorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

namespace Networking\InitCmsBundle\Annotation\Order;

use Networking\InitCmsBundle\Annotation\Order\ShowAndFormReorderInterface;

abstract class AbstractReorder implements ReorderInterface
{
/**
* @var array
*/
public $keys = [];

public function __construct(array $keys)
{
$this->keys = $keys;
}

/**
* @return array
*/
Expand Down
9 changes: 8 additions & 1 deletion src/Annotation/Order/FormReorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@
#[\Attribute(\Attribute::TARGET_CLASS)]
class FormReorder extends AbstractReorder implements FormReorderInterface
{

/**
* @var string
*/
public $with = null;
public ?string $with = null;

public function __construct(array $keys, ?string $with = null)
{
parent::__construct($keys);
$this->with = $with;
}

public function getWith(): ?string
{
Expand Down
8 changes: 7 additions & 1 deletion src/Annotation/Order/ShowAndFormReorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ class ShowAndFormReorder extends AbstractReorder implements ShowAndFormReorderIn
/**
* @var string
*/
public $with = null;
public ?string $with = null;

public function __construct(array $keys, ?string $with = null)
{
parent::__construct($keys);
$this->with = $with;
}

public function getWith(): ?string
{
Expand Down
8 changes: 7 additions & 1 deletion src/Annotation/Order/ShowReorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ class ShowReorder extends AbstractReorder implements ShowReorderInterface
/**
* @var string
*/
public $with = null;
public ?string $with = null;

public function __construct(array $keys, ?string $with = null)
{
parent::__construct($keys);
$this->with = $with;
}

public function getWith(): ?string
{
Expand Down
4 changes: 2 additions & 2 deletions src/AttributeReader/SonataAdminAttributeReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ public function getDatagridMapperCallbacks($entity): array
}

/**
* @return ListReorderInterface
* @return ListReorderInterface|null
*/
public function getListReorderAnnotation($entity): ListReorderInterface
public function getListReorderAnnotation($entity): ?ListReorderInterface
{
return $this->getAnnotationsByType($entity, self::ANNOTATION_TYPE_ADMIN_LIST_REORDER, self::SCOPE_CLASS);
}
Expand Down
4 changes: 2 additions & 2 deletions src/AttributeReader/SonataAdminAttributeReaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function getListMapperAnnotations($entity): array;
public function getListMapperCallbacks($entity): array;

/**
* @return ListReorderInterface
* @return ListReorderInterface|null
*/
public function getListReorderAnnotation($entity): ListReorderInterface;
public function getListReorderAnnotation($entity): ?ListReorderInterface;

/**
* @return ShowInterface[]
Expand Down

0 comments on commit 0d7c67a

Please sign in to comment.