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
- 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
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();
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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 [];
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class CreateModelFieldsMetadataTable extends Migration
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class CreateModelFieldsValuesTable extends Migration
- Exclude checks
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
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;
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],
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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],
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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;
- 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 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 getFieldsMetadataRules(string $class_type): array;
- 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;
- 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;
- 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 removeMetaField(string $class_type, string $name): bool;
- 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) {
}
}