amphibee / metaboxmaker Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
In the src/Transformer/FieldTransformer.php
file, the current implementation only checks for instances of Field
to process through the addField
method. This implementation is restrictive as there are other types of objects that need processing, such as Heading
and Divider
, which are not strictly fields but still require similar handling.
The code snippet:
if ($subField instanceof Field) {
$this->addField($subField);
}
This condition only allows objects of type Field
to be processed. However, instances of Heading
or Divider
are also valid inputs that need to be added but are currently being excluded.
We propose extending the condition to include Heading
and Divider
types. This can be implemented by modifying the existing conditional check to include these types, or by implementing a new interface that these classes can inherit, representing all types that are valid for addField
.
A possible modification might look like this:
if ($subField instanceof Field || $subField instanceof Heading || $subField instanceof Divider) {
$this->addField($subField);
}
Alternatively, defining a new interface like FieldCompatible
could make the system more flexible and maintainable:
interface FieldCompatible {}
class Field implements FieldCompatible {}
class Heading implements FieldCompatible {}
class Divider implements FieldCompatible {}
if ($subField instanceof FieldCompatible) {
$this->addField($subField);
}
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
This repository currently has no open or pending branches.
composer.json
php ^8.1.0
laravel/pint ^1.13
pestphp/pest ^2.19
rector/rector ^1.0.0
nunomaduro/phpinsights ^2.8
Currently, the type of input field in our Field
class hierarchy is managed as a protected property, which allows for dynamic modification of the field type at runtime. This is observed in the Text
class as follows:
class Text extends Field
{
/**
* The type of input field. Defaults to 'text'.
*/
protected string $type = 'text';
}
Additionally, there's functionality to modify this type through a setter method:
public function type(string|InputTextType $type): static
{
$this->type = OptionValidation::check($type, InputTextType::class);
return $this;
}
This design, while flexible, does not enforce type immutability which might be desirable for certain field types like text
, url
, or email
.
To ensure type safety and immutability, it is proposed to define the type of each field class using constants rather than properties. This would also involve the use of an interface to enforce the declaration of this constant in all field subclasses.
interface FieldType
{
public const TYPE = '';
}
Each field class, such as Text
, Email
, and URL
, would implement the FieldType
interface and define their own TYPE
constant:
class Text extends Field implements FieldType
{
public const TYPE = 'text';
}
class Email extends Field implements FieldType
{
public const TYPE = 'email';
}
class URL extends Field implements FieldType
{
public const TYPE = 'url';
}
Since the field type will now be immutable and defined at compile-time, the setter method type()
would be removed from these classes.
This change will:
This approach does, however, reduce the flexibility of changing the field type dynamically but increases reliability and predictability of field behavior across our application.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.