Showing 23 of 24 total issues
File Form.php
has 394 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Nickwest\EloquentForms;
use Illuminate\Support\Facades\Request;
Form
has 32 functions (exceeds 20 allowed). Consider refactoring. Open
class Form
{
use HasFields, Themeable{
Themeable::setTheme as parentSetTheme;
}
Function setPostValues
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public function setPostValues(array $post_data): void
{
foreach ($post_data as $field_name => $value) {
// We don't throw Exceptions here because post fields come from users and could be anything
// We just silently ignore invalid post fields
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function setAllFormValues
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function setAllFormValues(): void
{
foreach ($this->Form()->getFields() as $Field) {
// Use the Model Field's value if it has the field
if (isset($this->{$Field->getOriginalName()})) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function fromJson
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function fromJson(string $json): self
{
$array = json_decode($json);
foreach ($array as $key => $value) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function setMultipartIfNeeded
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function setMultipartIfNeeded()
{
if (isset($this->attributes->enctype)) {
return;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function isValid
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function isValid(): bool
{
$rules = [];
foreach ($this->Fields as $Field) {
$rules[$Field->getOriginalName()] = [];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function isFormValid
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function isFormValid(): bool
{
// Add required fields to field_rules
$columns = $this->getAllColumns();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method fromJson
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function fromJson($json): void
{
$array = json_decode($json);
foreach ($array as $key => $value) {
switch ($key) {
Function getString
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getString(array $skip = []): string
{
$output = [];
$this->prepareClassAttribute();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function fromJson
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function fromJson($json): void
{
$array = json_decode($json);
foreach ($array as $key => $value) {
switch ($key) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function setTypes
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function setTypes(array $types): void
{
foreach ($types as $field_name => $type) {
if (isset($this->Fields[$field_name])) {
// If it's a custom type, it'll be an object
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getFieldReplacement
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getFieldReplacement(string $field, &$Object): string
{
$pattern = '/\{([a-zA-Z0-9_\?]+)\}/';
$results = [];
preg_match_all($pattern, $this->field_replacements[$field], $results, PREG_PATTERN_ORDER);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function addMaxRule
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function addMaxRule($column, array &$rules)
{
// Set max length rule based on column length if available
if (isset($column['length']) && $column['length'] != '') {
// Find existing max: rules
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method renameSubmitButton
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function renameSubmitButton(string $name, string $value, string $new_name, string $new_value = null, string $new_label = null): void
Method setMargins
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function setMargins(\Maatwebsite\Excel\Sheet &$sheet, float $top = 0.7, float $right = 0.25, float $left = 0.25, float $bottom = 0.25): void
Function makeView
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function makeView(bool $prev_inline = false, bool $view_only = false): \Illuminate\View\View
{
if ($this->error_message) {
$this->attributes->addClass('error');
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function renameSubmitButton
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function renameSubmitButton(string $name, string $value, string $new_name, string $new_value = null, string $new_label = null): void
{
if (! isset($this->SubmitFields[$name.$value])) {
throw new InvalidFieldException($name.$value.' is not part of the Form');
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getSQLEnumOptions
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function getSQLEnumOptions(string $type, bool $nullable = false)
{
if (strpos($type, 'enum') !== 0) {
return;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
Blade::directive('eloquentforms_component', function ($expression) {
return '<?php if(View::exists('.self::getViewFromExpression($expression).')){
$__env->startComponent('.$expression.');
}else{
$__env->startComponent(\''.DefaultTheme::getDefaultNamespace().'::'.substr($expression, strpos($expression, '::') + 2).');
- 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 91.
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