Method getExtraAttributesValues
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getExtraAttributesValues(Model $model, ?int $visibility = null): array
{
if (config('model-fields.enabled')) {
if (!array_key_exists('id', $model->getAttributes())) {
return [];
Method addOrUpdateMetadataField
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addOrUpdateMetadataField(string $class_type, string $name, string $type, string $default = '', array $rules = null, int $visibility = 1 << 0, array $extra = null): Metadata
Avoid using static access to class '\Illuminate\Support\Facades\Cache' in method 'addOrUpdateMetadataField'. Open
Cache::flush();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\EscolaLms\ModelFields\Enum\MetaFieldTypeEnum' in method 'addOrUpdateMetadataField'. Open
if (!MetaFieldTypeEnum::hasValue($type)) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\EscolaLms\ModelFields\Models\Metadata' in method 'addOrUpdateMetadataField'. Open
return Metadata::updateOrCreate(
['class_type' => $class_type, 'name' => $name],
['type' => $type, 'default' => $default, 'rules' => $rules, 'visibility' => $visibility, 'extra' => $extra]
);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\EscolaLms\ModelFields\Enum\MetaFieldTypeEnum' in method 'addOrUpdateMetadataField'. Open
'type' => [sprintf('type must be one of %s', implode(",", MetaFieldTypeEnum::getValues()))],
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Illuminate\Validation\ValidationException' in method 'addOrUpdateMetadataField'. Open
throw ValidationException::withMessages([
'type' => [sprintf('type must be one of %s', implode(",", MetaFieldTypeEnum::getValues()))],
]);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Illuminate\Support\Facades\Cache' in method 'removeMetaField'. Open
Cache::flush();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Illuminate\Support\Facades\Cache' in method 'getFieldsMetadata'. Open
Cache::put('model_fields_metadata_table_exists', $tableExist);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Illuminate\Support\Facades\Cache' in method 'getFieldsMetadata'. Open
return Cache::rememberForever($key, function () use ($class_type) {
try {
$classTypes = class_parents($class_type) ? array_merge([$class_type], class_parents($class_type)) : [$class_type];
return Metadata::whereIn('class_type', $classTypes)->get();
} catch (QueryException $qe) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Illuminate\Support\Facades\Cache' in method 'getFieldsMetadata'. Open
Cache::put('model_fields_metadata_table_exists', false);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Illuminate\Support\Facades\Schema' in method 'getFieldsMetadata'. Open
return Schema::hasTable('model_fields_metadata');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Illuminate\Support\Facades\Schema' in method 'getFieldsMetadata'. Open
$tableExist = Schema::hasTable('model_fields_metadata');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Illuminate\Support\Facades\Cache' in method 'getFieldsMetadata'. Open
$tableExist = Cache::rememberForever('model_fields_metadata_table_exists', function () {
return Schema::hasTable('model_fields_metadata');
});
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Illuminate\Support\Facades\Cache' in method 'getExtraAttributesValues'. Open
$modelFields = Cache::rememberForever($key, function () use ($model) {
// @phpstan-ignore-next-line
return $model->fields()->get();
});
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid unused parameters such as '$key'. Open
->mapWithKeys(fn($item, $key) => [$item['name'] => is_array($item['rules']) ? $item['rules'] : []])
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
syntax error, unexpected '|', expecting ';' or '{'
Open
public function getFieldsMetadataListPaginated(string $class_type, ?int $perPage = 15, ?OrderDto $orderDto = null): Collection|LengthAwarePaginator
- Exclude checks
Avoid excessively long variable names like $metadataFieldVisibility. Keep variable name length under 20. Open
private function checkVisibility(?int $visibility = null, int $metadataFieldVisibility): int|bool
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
The parameter $class_type is not named in camelCase. Open
public function removeMetaField(string $class_type, string $name): bool
{
$bool = Metadata::where(
['class_type' => $class_type, 'name' => $name]
)->delete();
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $class_type is not named in camelCase. Open
public function addOrUpdateMetadataField(string $class_type, string $name, string $type, string $default = '', array $rules = null, int $visibility = 1 << 0, array $extra = null): Metadata
{
if (!MetaFieldTypeEnum::hasValue($type)) {
throw ValidationException::withMessages([
'type' => [sprintf('type must be one of %s', implode(",", MetaFieldTypeEnum::getValues()))],
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $class_type is not named in camelCase. Open
public function getFieldsMetadata(string $class_type): Collection
{
// add result of hasTable to the cache to limit database queries
$tableExist = Cache::rememberForever('model_fields_metadata_table_exists', function () {
return Schema::hasTable('model_fields_metadata');
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $class_type is not named in camelCase. Open
public function getFieldsMetadataListPaginated(string $class_type, ?int $perPage = 15, ?OrderDto $orderDto = null): Collection|LengthAwarePaginator
{
if (!config('model-fields.enabled')) {
return collect([]);
}
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $class_type is not named in camelCase. Open
public function getFieldsMetadataRules(string $class_type): array
{
if (config('model-fields.enabled')) {
return $this->getFieldsMetadata($class_type)
->mapWithKeys(fn($item, $key) => [$item['name'] => is_array($item['rules']) ? $item['rules'] : []])
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
Line exceeds 120 characters; contains 151 characters Open
public function getFieldsMetadataListPaginated(string $class_type, ?int $perPage = 15, ?OrderDto $orderDto = null): Collection|LengthAwarePaginator
- Exclude checks
Line exceeds 120 characters; contains 192 characters Open
public function addOrUpdateMetadataField(string $class_type, string $name, string $type, string $default = '', array $rules = null, int $visibility = 1 << 0, array $extra = null): Metadata
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$classTypes = class_parents($class_type) ? array_merge([$class_type], class_parents($class_type)) : [$class_type];
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
->mapWithKeys(fn($item, $key) => [$item['name'] => self::castField($item['value'], ($fields[$item['name']] ?? null))])
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
$classTypes = class_parents($class_type) ? array_merge([$class_type], class_parents($class_type)) : [$class_type];
- Exclude checks
The variable $class_type is not named in camelCase. Open
public function addOrUpdateMetadataField(string $class_type, string $name, string $type, string $default = '', array $rules = null, int $visibility = 1 << 0, array $extra = null): Metadata
{
if (!MetaFieldTypeEnum::hasValue($type)) {
throw ValidationException::withMessages([
'type' => [sprintf('type must be one of %s', implode(",", MetaFieldTypeEnum::getValues()))],
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function getFieldsMetadataListPaginated(string $class_type, ?int $perPage = 15, ?OrderDto $orderDto = null): Collection|LengthAwarePaginator
{
if (!config('model-fields.enabled')) {
return collect([]);
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function getFieldsMetadataListPaginated(string $class_type, ?int $perPage = 15, ?OrderDto $orderDto = null): Collection|LengthAwarePaginator
{
if (!config('model-fields.enabled')) {
return collect([]);
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function getFieldsMetadata(string $class_type): Collection
{
// add result of hasTable to the cache to limit database queries
$tableExist = Cache::rememberForever('model_fields_metadata_table_exists', function () {
return Schema::hasTable('model_fields_metadata');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function removeMetaField(string $class_type, string $name): bool
{
$bool = Metadata::where(
['class_type' => $class_type, 'name' => $name]
)->delete();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function getFieldsMetadata(string $class_type): Collection
{
// add result of hasTable to the cache to limit database queries
$tableExist = Cache::rememberForever('model_fields_metadata_table_exists', function () {
return Schema::hasTable('model_fields_metadata');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function removeMetaField(string $class_type, string $name): bool
{
$bool = Metadata::where(
['class_type' => $class_type, 'name' => $name]
)->delete();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function getFieldsMetadataRules(string $class_type): array
{
if (config('model-fields.enabled')) {
return $this->getFieldsMetadata($class_type)
->mapWithKeys(fn($item, $key) => [$item['name'] => is_array($item['rules']) ? $item['rules'] : []])
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function getFieldsMetadata(string $class_type): Collection
{
// add result of hasTable to the cache to limit database queries
$tableExist = Cache::rememberForever('model_fields_metadata_table_exists', function () {
return Schema::hasTable('model_fields_metadata');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function getFieldsMetadata(string $class_type): Collection
{
// add result of hasTable to the cache to limit database queries
$tableExist = Cache::rememberForever('model_fields_metadata_table_exists', function () {
return Schema::hasTable('model_fields_metadata');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function getFieldsMetadataListPaginated(string $class_type, ?int $perPage = 15, ?OrderDto $orderDto = null): Collection|LengthAwarePaginator
{
if (!config('model-fields.enabled')) {
return collect([]);
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function getFieldsMetadataListPaginated(string $class_type, ?int $perPage = 15, ?OrderDto $orderDto = null): Collection|LengthAwarePaginator
{
if (!config('model-fields.enabled')) {
return collect([]);
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_type is not named in camelCase. Open
public function getFieldsMetadata(string $class_type): Collection
{
// add result of hasTable to the cache to limit database queries
$tableExist = Cache::rememberForever('model_fields_metadata_table_exists', function () {
return Schema::hasTable('model_fields_metadata');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}