Replaced filter classes getters with public readonly properties to improve DX

This commit is contained in:
Jan Böhmer 2023-06-18 16:41:00 +02:00
parent afa17ca429
commit 4a644d8712
5 changed files with 56 additions and 325 deletions

View file

@ -167,7 +167,7 @@ class PartListsController extends AbstractController
return $this->showListWithFilter($request, return $this->showListWithFilter($request,
'parts/lists/category_list.html.twig', 'parts/lists/category_list.html.twig',
function (PartFilter $filter) use ($category) { function (PartFilter $filter) use ($category) {
$filter->getCategory()->setOperator('INCLUDING_CHILDREN')->setValue($category); $filter->category->setOperator('INCLUDING_CHILDREN')->setValue($category);
}, function (FormInterface $filterForm) { }, function (FormInterface $filterForm) {
$this->disableFormFieldAfterCreation($filterForm->get('category')->get('value')); $this->disableFormFieldAfterCreation($filterForm->get('category')->get('value'));
}, [ }, [
@ -185,7 +185,7 @@ class PartListsController extends AbstractController
return $this->showListWithFilter($request, return $this->showListWithFilter($request,
'parts/lists/footprint_list.html.twig', 'parts/lists/footprint_list.html.twig',
function (PartFilter $filter) use ($footprint) { function (PartFilter $filter) use ($footprint) {
$filter->getFootprint()->setOperator('INCLUDING_CHILDREN')->setValue($footprint); $filter->footprint->setOperator('INCLUDING_CHILDREN')->setValue($footprint);
}, function (FormInterface $filterForm) { }, function (FormInterface $filterForm) {
$this->disableFormFieldAfterCreation($filterForm->get('footprint')->get('value')); $this->disableFormFieldAfterCreation($filterForm->get('footprint')->get('value'));
}, [ }, [
@ -203,7 +203,7 @@ class PartListsController extends AbstractController
return $this->showListWithFilter($request, return $this->showListWithFilter($request,
'parts/lists/manufacturer_list.html.twig', 'parts/lists/manufacturer_list.html.twig',
function (PartFilter $filter) use ($manufacturer) { function (PartFilter $filter) use ($manufacturer) {
$filter->getManufacturer()->setOperator('INCLUDING_CHILDREN')->setValue($manufacturer); $filter->manufacturer->setOperator('INCLUDING_CHILDREN')->setValue($manufacturer);
}, function (FormInterface $filterForm) { }, function (FormInterface $filterForm) {
$this->disableFormFieldAfterCreation($filterForm->get('manufacturer')->get('value')); $this->disableFormFieldAfterCreation($filterForm->get('manufacturer')->get('value'));
}, [ }, [
@ -221,7 +221,7 @@ class PartListsController extends AbstractController
return $this->showListWithFilter($request, return $this->showListWithFilter($request,
'parts/lists/store_location_list.html.twig', 'parts/lists/store_location_list.html.twig',
function (PartFilter $filter) use ($storelocation) { function (PartFilter $filter) use ($storelocation) {
$filter->getStorelocation()->setOperator('INCLUDING_CHILDREN')->setValue($storelocation); $filter->storelocation->setOperator('INCLUDING_CHILDREN')->setValue($storelocation);
}, function (FormInterface $filterForm) { }, function (FormInterface $filterForm) {
$this->disableFormFieldAfterCreation($filterForm->get('storelocation')->get('value')); $this->disableFormFieldAfterCreation($filterForm->get('storelocation')->get('value'));
}, [ }, [
@ -239,7 +239,7 @@ class PartListsController extends AbstractController
return $this->showListWithFilter($request, return $this->showListWithFilter($request,
'parts/lists/supplier_list.html.twig', 'parts/lists/supplier_list.html.twig',
function (PartFilter $filter) use ($supplier) { function (PartFilter $filter) use ($supplier) {
$filter->getSupplier()->setOperator('INCLUDING_CHILDREN')->setValue($supplier); $filter->supplier->setOperator('INCLUDING_CHILDREN')->setValue($supplier);
}, function (FormInterface $filterForm) { }, function (FormInterface $filterForm) {
$this->disableFormFieldAfterCreation($filterForm->get('supplier')->get('value')); $this->disableFormFieldAfterCreation($filterForm->get('supplier')->get('value'));
}, [ }, [
@ -257,7 +257,7 @@ class PartListsController extends AbstractController
return $this->showListWithFilter($request, return $this->showListWithFilter($request,
'parts/lists/tags_list.html.twig', 'parts/lists/tags_list.html.twig',
function (PartFilter $filter) use ($tag) { function (PartFilter $filter) use ($tag) {
$filter->getTags()->setOperator('ANY')->setValue($tag); $filter->tags->setOperator('ANY')->setValue($tag);
}, function (FormInterface $filterForm) { }, function (FormInterface $filterForm) {
$this->disableFormFieldAfterCreation($filterForm->get('tags')->get('value')); $this->disableFormFieldAfterCreation($filterForm->get('tags')->get('value'));
}, [ }, [

View file

@ -37,13 +37,13 @@ class AttachmentFilter implements FilterInterface
{ {
use CompoundFilterTrait; use CompoundFilterTrait;
protected NumberConstraint $dbId; public readonly NumberConstraint $dbId;
protected InstanceOfConstraint $targetType; public readonly InstanceOfConstraint $targetType;
protected TextConstraint $name; public readonly TextConstraint $name;
protected EntityConstraint $attachmentType; public readonly EntityConstraint $attachmentType;
protected BooleanConstraint $showInTable; public readonly BooleanConstraint $showInTable;
protected DateTimeConstraint $lastModified; public readonly DateTimeConstraint $lastModified;
protected DateTimeConstraint $addedDate; public readonly DateTimeConstraint $addedDate;
public function __construct(NodesListBuilder $nodesListBuilder) public function __construct(NodesListBuilder $nodesListBuilder)
@ -61,47 +61,4 @@ class AttachmentFilter implements FilterInterface
{ {
$this->applyAllChildFilters($queryBuilder); $this->applyAllChildFilters($queryBuilder);
} }
public function getDbId(): NumberConstraint
{
return $this->dbId;
}
public function getName(): TextConstraint
{
return $this->name;
}
public function getLastModified(): DateTimeConstraint
{
return $this->lastModified;
}
public function getAddedDate(): DateTimeConstraint
{
return $this->addedDate;
}
public function getShowInTable(): BooleanConstraint
{
return $this->showInTable;
}
public function getAttachmentType(): EntityConstraint
{
return $this->attachmentType;
}
public function getTargetType(): InstanceOfConstraint
{
return $this->targetType;
}
} }

View file

@ -39,9 +39,6 @@ trait CompoundFilterTrait
$reflection = new \ReflectionClass($this); $reflection = new \ReflectionClass($this);
foreach ($reflection->getProperties() as $property) { foreach ($reflection->getProperties() as $property) {
//Set property to accessible (otherwise we run into problems on PHP < 8.1)
$property->setAccessible(true);
$value = $property->getValue($this); $value = $property->getValue($this);
//We only want filters (objects implementing FilterInterface) //We only want filters (objects implementing FilterInterface)
if($value instanceof FilterInterface) { if($value instanceof FilterInterface) {

View file

@ -35,13 +35,13 @@ class LogFilter implements FilterInterface
{ {
use CompoundFilterTrait; use CompoundFilterTrait;
protected DateTimeConstraint $timestamp; public readonly DateTimeConstraint $timestamp;
protected IntConstraint $dbId; public readonly IntConstraint $dbId;
protected ChoiceConstraint $level; public readonly ChoiceConstraint $level;
protected InstanceOfConstraint $eventType; public readonly InstanceOfConstraint $eventType;
protected ChoiceConstraint $targetType; public readonly ChoiceConstraint $targetType;
protected IntConstraint $targetId; public readonly IntConstraint $targetId;
protected EntityConstraint $user; public readonly EntityConstraint $user;
public function __construct() public function __construct()
{ {
@ -59,44 +59,4 @@ class LogFilter implements FilterInterface
{ {
$this->applyAllChildFilters($queryBuilder); $this->applyAllChildFilters($queryBuilder);
} }
public function getTimestamp(): DateTimeConstraint
{
return $this->timestamp;
}
/**
* @return IntConstraint|NumberConstraint
*/
public function getDbId(): IntConstraint|NumberConstraint
{
return $this->dbId;
}
public function getLevel(): ChoiceConstraint
{
return $this->level;
}
public function getEventType(): InstanceOfConstraint
{
return $this->eventType;
}
public function getTargetType(): ChoiceConstraint
{
return $this->targetType;
}
public function getTargetId(): IntConstraint
{
return $this->targetId;
}
public function getUser(): EntityConstraint
{
return $this->user;
}
} }

View file

@ -49,46 +49,46 @@ class PartFilter implements FilterInterface
use CompoundFilterTrait; use CompoundFilterTrait;
protected IntConstraint $dbId; public readonly IntConstraint $dbId;
protected TextConstraint $ipn; public readonly TextConstraint $ipn;
protected TextConstraint $name; public readonly TextConstraint $name;
protected TextConstraint $description; public readonly TextConstraint $description;
protected TextConstraint $comment; public readonly TextConstraint $comment;
protected TagsConstraint $tags; public readonly TagsConstraint $tags;
protected NumberConstraint $minAmount; public readonly NumberConstraint $minAmount;
protected BooleanConstraint $favorite; public readonly BooleanConstraint $favorite;
protected BooleanConstraint $needsReview; public readonly BooleanConstraint $needsReview;
protected NumberConstraint $mass; public readonly NumberConstraint $mass;
protected DateTimeConstraint $lastModified; public readonly DateTimeConstraint $lastModified;
protected DateTimeConstraint $addedDate; public readonly DateTimeConstraint $addedDate;
protected EntityConstraint $category; public readonly EntityConstraint $category;
protected EntityConstraint $footprint; public readonly EntityConstraint $footprint;
protected EntityConstraint $manufacturer; public readonly EntityConstraint $manufacturer;
protected ChoiceConstraint $manufacturing_status; public readonly ChoiceConstraint $manufacturing_status;
protected EntityConstraint $supplier; public readonly EntityConstraint $supplier;
protected IntConstraint $orderdetailsCount; public readonly IntConstraint $orderdetailsCount;
protected BooleanConstraint $obsolete; public readonly BooleanConstraint $obsolete;
protected EntityConstraint $storelocation; public readonly EntityConstraint $storelocation;
protected IntConstraint $lotCount; public readonly IntConstraint $lotCount;
protected IntConstraint $amountSum; public readonly IntConstraint $amountSum;
protected LessThanDesiredConstraint $lessThanDesired; public readonly LessThanDesiredConstraint $lessThanDesired;
protected BooleanConstraint $lotNeedsRefill; public readonly BooleanConstraint $lotNeedsRefill;
protected TextConstraint $lotDescription; public readonly TextConstraint $lotDescription;
protected BooleanConstraint $lotUnknownAmount; public readonly BooleanConstraint $lotUnknownAmount;
protected DateTimeConstraint $lotExpirationDate; public readonly DateTimeConstraint $lotExpirationDate;
protected EntityConstraint $lotOwner; public readonly EntityConstraint $lotOwner;
protected EntityConstraint $measurementUnit; public readonly EntityConstraint $measurementUnit;
protected TextConstraint $manufacturer_product_url; public readonly TextConstraint $manufacturer_product_url;
protected TextConstraint $manufacturer_product_number; public readonly TextConstraint $manufacturer_product_number;
protected IntConstraint $attachmentsCount; public readonly IntConstraint $attachmentsCount;
protected EntityConstraint $attachmentType; public readonly EntityConstraint $attachmentType;
protected TextConstraint $attachmentName; public readonly TextConstraint $attachmentName;
/** @var ArrayCollection<int, ParameterConstraint> */ /** @var ArrayCollection<int, ParameterConstraint> */
protected ArrayCollection $parameters; public readonly ArrayCollection $parameters;
protected IntConstraint $parametersCount; public readonly IntConstraint $parametersCount;
public function __construct(NodesListBuilder $nodesListBuilder) public function __construct(NodesListBuilder $nodesListBuilder)
{ {
@ -146,187 +146,4 @@ class PartFilter implements FilterInterface
{ {
$this->applyAllChildFilters($queryBuilder); $this->applyAllChildFilters($queryBuilder);
} }
public function getFavorite(): BooleanConstraint
{
return $this->favorite;
}
public function getNeedsReview(): BooleanConstraint
{
return $this->needsReview;
}
public function getMass(): NumberConstraint
{
return $this->mass;
}
public function getName(): TextConstraint
{
return $this->name;
}
public function getDescription(): TextConstraint
{
return $this->description;
}
public function getLastModified(): DateTimeConstraint
{
return $this->lastModified;
}
public function getAddedDate(): DateTimeConstraint
{
return $this->addedDate;
}
public function getCategory(): EntityConstraint
{
return $this->category;
}
public function getFootprint(): EntityConstraint
{
return $this->footprint;
}
public function getManufacturer(): EntityConstraint
{
return $this->manufacturer;
}
public function getSupplier(): EntityConstraint
{
return $this->supplier;
}
public function getStorelocation(): EntityConstraint
{
return $this->storelocation;
}
public function getMeasurementUnit(): EntityConstraint
{
return $this->measurementUnit;
}
public function getDbId(): NumberConstraint
{
return $this->dbId;
}
public function getIpn(): TextConstraint
{
return $this->ipn;
}
public function getComment(): TextConstraint
{
return $this->comment;
}
public function getMinAmount(): NumberConstraint
{
return $this->minAmount;
}
public function getManufacturerProductUrl(): TextConstraint
{
return $this->manufacturer_product_url;
}
public function getManufacturerProductNumber(): TextConstraint
{
return $this->manufacturer_product_number;
}
public function getLotCount(): NumberConstraint
{
return $this->lotCount;
}
public function getLotOwner(): EntityConstraint
{
return $this->lotOwner;
}
public function getTags(): TagsConstraint
{
return $this->tags;
}
public function getOrderdetailsCount(): IntConstraint
{
return $this->orderdetailsCount;
}
public function getAttachmentsCount(): IntConstraint
{
return $this->attachmentsCount;
}
public function getLotNeedsRefill(): BooleanConstraint
{
return $this->lotNeedsRefill;
}
public function getLotUnknownAmount(): BooleanConstraint
{
return $this->lotUnknownAmount;
}
public function getLotExpirationDate(): DateTimeConstraint
{
return $this->lotExpirationDate;
}
public function getAttachmentType(): EntityConstraint
{
return $this->attachmentType;
}
public function getAttachmentName(): TextConstraint
{
return $this->attachmentName;
}
public function getManufacturingStatus(): ChoiceConstraint
{
return $this->manufacturing_status;
}
public function getAmountSum(): NumberConstraint
{
return $this->amountSum;
}
public function getParameters(): ArrayCollection
{
return $this->parameters;
}
public function getParametersCount(): IntConstraint
{
return $this->parametersCount;
}
public function getLotDescription(): TextConstraint
{
return $this->lotDescription;
}
public function getObsolete(): BooleanConstraint
{
return $this->obsolete;
}
public function getLessThanDesired(): LessThanDesiredConstraint
{
return $this->lessThanDesired;
}
} }