yajra / laravel-datatables-html

Laravel DataTables HTML Builder Plugin
https://yajrabox.com/docs/laravel-datatables/html-installation
MIT License
272 stars 63 forks source link

Update Column.php: Rename data method to setData #231

Closed bishwajitcadhikary closed 7 hours ago

bishwajitcadhikary commented 10 hours ago

This change renames the data method in the Yajra\DataTables\Html\Column class to setData to resolve a method signature conflict with the parent class Illuminate\Support\Fluent.

public function data(array|string $value): static

This conflicts with the data method in the parent Illuminate\Support\Fluent class, which has the signature:

protected function data($key = null, $default = null)

This results in the following PHP error:

Declaration of Yajra\DataTables\Html\Column::data(array|string $value): static must be compatible with Illuminate\Support\Fluent::data($key = null, $default = null)

Proposed Solution The data method in the Column class has been renamed to setData to avoid the conflict:

/**
 * Set column data option value.
 *
 * @param  array|string  $value
 * @return $this
 *
 * @see https://datatables.net/reference/option/columns.data
 * @see https://datatables.net/manual/data/orthogonal-data
 */
public function setData(array|string $value): static
{
    $this->attributes['data'] = $value;

    return $this;
}

Benefits of the Fix

  1. Conflict Resolution: Avoids the signature conflict with Illuminate\Support\Fluent.
  2. Clarity: Improves method naming by explicitly reflecting its purpose (setData for setting values).
  3. Backward Compatibility: Allows the Column class to coexist with Fluent without breaking functionality.

Additional Notes • Any existing usage of data() to set column data will need to be updated to setData() in the codebase. • This change only affects the method used to set column data. The method inherited from Fluent (data($key = null, $default = null)) remains intact for retrieving data.

sonarcloud[bot] commented 10 hours ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

yajra commented 7 hours ago

fixed via https://github.com/yajra/laravel-datatables-html/pull/230, thanks!