EscolaLMS/model-fields

View on GitHub

Showing 192 of 192 total issues

Avoid excessively long variable names like $metadataFieldVisibility. Keep variable name length under 20.
Open

    private function checkVisibility(?int $visibility = null, int $metadataFieldVisibility): int|bool
Severity: Minor
Found in src/Services/ModelFieldsService.php by phpmd

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

Avoid using short method names like CreateModelFieldsMetadataTable::up(). The configured minimum method name length is 3.
Open

    public function up()
    {
        Schema::create('model_fields_metadata', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->timestamps();

ShortMethodName

Since: 0.2

Detects when very short method names are used.

Example

class ShortMethod {
    public function a( $index ) { // Violation
    }
}

Source https://phpmd.org/rules/naming.html#shortmethodname

Avoid using short method names like CreateModelFieldsValuesTable::up(). The configured minimum method name length is 3.
Open

    public function up()
    {
        Schema::create('model_fields_values', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->timestamps();

ShortMethodName

Since: 0.2

Detects when very short method names are used.

Example

class ShortMethod {
    public function a( $index ) { // Violation
    }
}

Source https://phpmd.org/rules/naming.html#shortmethodname

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 [];
Severity: Minor
Found in src/Services/ModelFieldsService.php - About 1 hr to fix

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class CreateModelFieldsMetadataTable extends Migration

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class CreateModelFieldsValuesTable extends Migration

    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
    Severity: Major
    Found in src/Services/ModelFieldsService.php - About 50 mins to fix

      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;
      Severity: Major
      Found in src/Services/Contracts/ModelFieldsServiceContract.php - About 50 mins to fix

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                if ($instance = $query->first()) {
                    foreach ($additionalAttributes as $key => $value) {
                        $query = $query->whereHas('fields', function ($query) use ($key, $value){
                            return $query->where([
                                ['name', '=', $key],
        Severity: Minor
        Found in src/Models/Model.php and 1 other location - About 50 mins to fix
        src/Traits/ModelFields.php on lines 125..138

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 97.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                if ($instance = $query->first()) {
                    foreach ($additionalAttributes as $key => $value) {
                        $query = $query->whereHas('fields', function ($query) use ($key, $value){
                            return $query->where([
                                ['name', '=', $key],
        Severity: Minor
        Found in src/Traits/ModelFields.php and 1 other location - About 50 mins to fix
        src/Models/Model.php on lines 145..158

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 97.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        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;

        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 removeMetaField(string $class_type, string $name): bool
            {
                $bool = Metadata::where(
                    ['class_type' => $class_type, 'name' => $name]
                )->delete();
        Severity: Minor
        Found in src/Services/ModelFieldsService.php by phpmd

        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;

        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;

        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;

        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 removeMetaField(string $class_type, string $name): bool;

        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()))],
        Severity: Minor
        Found in src/Services/ModelFieldsService.php by phpmd

        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');
        Severity: Minor
        Found in src/Services/ModelFieldsService.php by phpmd

        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([]);
                }
        Severity: Minor
        Found in src/Services/ModelFieldsService.php by phpmd

        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'] : []])
        Severity: Minor
        Found in src/Services/ModelFieldsService.php by phpmd

        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

        Severity
        Category
        Status
        Source
        Language