Completed
Push — master ( 3f99c9...f99ebc )
by Quentin
8s
created

TranslatableCollectionTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setLocale() 0 10 1
A setDefaultLocale() 0 10 1
1
<?php
2
3
namespace Majora\Framework\Model;
4
5
/**
6
 * Trait for translatable object collections
7
 *
8
 * @method forAll(Closure $p)
9
 */
10
trait TranslatableCollectionTrait
11
{
12
    /**
13
     * @see TranslatableInterface::setLocale()
14
     */
15
    public function setLocale($locale)
16
    {
17
        $this->forAll(function ($key, TranslatableInterface $element) use ($locale) {
0 ignored issues
show
Documentation introduced by
function ($key, \Majora\...le); return true; } is of type object<Closure>, but the function expects a object<Majora\Framework\Model\Closure>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
18
            $element->setLocale($locale);
19
20
            return true;
21
        });
22
23
        return $this;
24
    }
25
26
    /**
27
     * @see TranslatableInterface::setDefaultLocale()
28
     */
29
    public function setDefaultLocale($defaultLocale)
30
    {
31
        $this->forAll(function ($key, TranslatableInterface $element) use ($defaultLocale) {
0 ignored issues
show
Documentation introduced by
function ($key, \Majora\...le); return true; } is of type object<Closure>, but the function expects a object<Majora\Framework\Model\Closure>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
            $element->setDefaultLocale($defaultLocale);
33
34
            return true;
35
        });
36
37
        return $this;
38
    }
39
}
40