for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace SoareCostin\BladeFormComponents\Traits;
trait GluesAttributes
{
public function glueAttributes($attributesList = null)
if (is_null($attributesList) && isset($this->attributesList)) {
$attributesList = $this->attributesList;
attributesList
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
$pairs = [];
foreach ($attributesList as $attr) {
if (isset($this->{$attr})) {
// Edge cases
if ($attr == 'autocomplete') {
$pairs[] = sprintf('%s="%s"', $attr, $this->{$attr} ? 'on' : 'off');
continue;
if ($attr == 'class' && is_array($this->{$attr})) {
$pairs[] = sprintf('%s="%s"', $attr, implode(' ', $this->{$attr}));
// Required, disabled, readonly: true/false
if (is_bool($this->{$attr})) {
if ($this->{$attr} == true) {
$pairs[] = $attr;
$pairs[] = sprintf('%s="%s"', $attr, $this->{$attr});
return implode(" ", $pairs);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: