Completed
Push — master ( 8f5f7c...7faed5 )
by Basenko
04:23
created

Languages   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseValue() 0 8 2
1
<?php
2
3
namespace MadWeb\Seoable\Fields\Meta;
4
5
use MadWeb\Seoable\Fields\Field;
6
7
class Languages extends Field
8
{
9
    protected function parseValue($value): array
10
    {
11
        foreach ($value as &$language) {
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
            $language['url'] = $this->model->getAttribute($language['url']);
13
        }
14
15
        return $value;
16
    }
17
}
18