Completed
Push — master ( e600ef...7ac924 )
by Basenko
07:00
created

Properties   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 17
loc 17
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseValue() 14 14 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace MadWeb\Seoable\Fields\OpenGraph;
4
5
use MadWeb\Seoable\Fields\Field;
6
7 View Code Duplication
class Properties extends Field
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9 3
    protected function parseValue($value): array
10
    {
11 3
        foreach ($value as &$item) {
0 ignored issues
show
Bug introduced by
The expression $value of type array|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
12 3
            if (is_array($item['value'])) {
13 3
                foreach ($item['value'] as &$property_value) {
14 3
                    $property_value = $this->model->getAttribute($property_value);
15
                }
16
            } else {
17 3
                $item['value'] = $this->model->getAttribute($item['value']);
18
            }
19
        }
20
21 3
        return $value;
22
    }
23
}
24