You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
In your code and contained docblocks you use e.g. (from file DataTable.php)
namespaceHermawan\DataTables;
/** * Make a DataTable instance from builder. * * Builder from CodeIgniter Query Builder * @param Builder $builder */publicstaticfunctionof($builder)
{
returnnewself($builder);
}
/** * Add Searchable columns * @param String|Array */publicfunctionaddSearchableColumns($columns)
{
$this->columnDefs->addSearchable($columns);
return$this;
}
This means that the in the static of function, the $builder argument is considered to be of type Hermawan\DataTables\Builder.
In the function addSearchableColumns, the $columns argument is not a regular, native php string (as you probably intend) but a Hermawan\DataTables\String.
Etc. etc.
However, since the builder is generated based off Codeigniter code, it is in fact of type CodeIgniter\Database\BaseBuilder. And what we pass to addSearchableColumns is a native string, etc.
This discrepancy is highlighted by my code linter all the time, all over the place and I believe it should be fixed. The solution would be, continuing with the example at from the top:
namespaceHermawan\DataTables;
/** * Make a DataTable instance from builder. * * Builder from CodeIgniter Query Builder * @param \CodeIgniter\Database\BaseBuilder $builder // <<<< note the change */publicstaticfunctionof($builder)
{
returnnewself($builder);
}
/** * Add Searchable columns * @param string|array // <<<< note the lowercase */publicfunctionaddSearchableColumns($columns)
{
$this->columnDefs->addSearchable($columns);
return$this;
}
I'm no expert in namespace, but I believe this would be more correct? It stops all the linter errors in any case...
Thanks!
Version (please complete the following information):
PHP Version: 8.3
CodeIgniter version: 4.4.5
Library version: 0.7.1
The text was updated successfully, but these errors were encountered:
Exactly, it's what's written in the comment (docblock) where the linter takes the information from. Ideally it should be in the function argument too, to make it strict.
E.g.
namespaceHermawan\DataTables;
/** * Make a DataTable instance from builder. * * Builder from CodeIgniter Query Builder * @param \CodeIgniter\Database\BaseBuilder $builder */publicstaticfunctionof(\CodeIgniter\Database\BaseBuilder$builder)
{
returnnewself($builder);
}
/** * Add Searchable columns * @param string|array */publicfunctionaddSearchableColumns(string|array$columns)
{
$this->columnDefs->addSearchable($columns);
return$this;
}
Describe the bug
In your code and contained docblocks you use e.g. (from file DataTable.php)
This means that the in the static
of
function, the$builder
argument is considered to be of typeHermawan\DataTables\Builder
.In the function
addSearchableColumns
, the$columns
argument is not a regular, native php string (as you probably intend) but aHermawan\DataTables\String
.Etc. etc.
However, since the builder is generated based off Codeigniter code, it is in fact of type
CodeIgniter\Database\BaseBuilder
. And what we pass toaddSearchableColumns
is a nativestring
, etc.This discrepancy is highlighted by my code linter all the time, all over the place and I believe it should be fixed. The solution would be, continuing with the example at from the top:
I'm no expert in namespace, but I believe this would be more correct? It stops all the linter errors in any case...
Thanks!
Version (please complete the following information):
The text was updated successfully, but these errors were encountered: