protonemedia /
laravel-form-components
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ProtoneMedia\LaravelFormComponents\Components; |
||
| 4 | |||
| 5 | use Illuminate\Support\Str; |
||
| 6 | use Illuminate\View\Component as BaseComponent; |
||
| 7 | use ProtoneMedia\LaravelFormComponents\FormDataBinder; |
||
| 8 | |||
| 9 | abstract class Component extends BaseComponent |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * ID for this component. |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | private $id; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * {@inheritDoc} |
||
| 20 | */ |
||
| 21 | public function render() |
||
| 22 | { |
||
| 23 | $alias = Str::kebab(class_basename($this)); |
||
| 24 | |||
| 25 | $config = config("form-components.components.{$alias}"); |
||
| 26 | |||
| 27 | $framework = config("form-components.framework"); |
||
| 28 | |||
| 29 | return str_replace('{framework}', $framework, $config['view']); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Returns a boolean wether the form is wired to a Livewire component. |
||
| 34 | * |
||
| 35 | * @return boolean |
||
| 36 | */ |
||
| 37 | public function isWired(): bool |
||
| 38 | { |
||
| 39 | return app(FormDataBinder::class)->isWired(); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The inversion of 'isWired()'. |
||
| 44 | * |
||
| 45 | * @return boolean |
||
| 46 | */ |
||
| 47 | public function isNotWired(): bool |
||
| 48 | { |
||
| 49 | return !$this->isWired(); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Returns the optional wire modifier. |
||
| 54 | * |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | public function wireModifier(): ?string |
||
| 58 | { |
||
| 59 | $modifier = app(FormDataBinder::class)->getWireModifier(); |
||
|
0 ignored issues
–
show
|
|||
| 60 | |||
| 61 | return $modifier ? ".{$modifier}" : null; |
||
|
0 ignored issues
–
show
|
|||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Generates an ID, once, for this component. |
||
| 66 | * |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | public function id(): string |
||
| 70 | { |
||
| 71 | if ($this->id) { |
||
| 72 | return $this->id; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($this->name) { |
||
| 76 | return $this->id = $this->generateIdByName(); |
||
| 77 | } |
||
| 78 | |||
| 79 | return $this->id = Str::random(4); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Generates an ID by the name attribute. |
||
| 84 | * |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | protected function generateIdByName(): string |
||
| 88 | { |
||
| 89 | return "auto_id_" . $this->name; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Converts a bracket-notation to a dotted-notation |
||
| 94 | * |
||
| 95 | * @param string $name |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | protected static function convertBracketsToDots($name): string |
||
| 99 | { |
||
| 100 | return str_replace(['[', ']'], ['.', ''], $name); |
||
| 101 | } |
||
| 102 | } |
||
| 103 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.