Completed
Push — dev ( a407a0...93ff54 )
by Jakob
01:34
created

StringContainer::checkMember()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php declare(strict_types = 1);
2
3
namespace JSKOS;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Common methods of Containers with string members (Listing, LanguageMapOfStrings).
9
 */
10
trait StringContainer
11
{
12
    /**
13
     * Stringify if value is a scalar, throw an expection otherwise.
14
     */
15
    protected static function checkMember($value)
16
    {
17
        if (is_scalar($value)) {
18
            return "$value";
19
        } else {
20
            throw new InvalidArgumentException(
21
                get_called_class() . ' may only contain strings'
22
            );
23
        }
24
    }
25
    
26
    /**
27
     * Check whether an equal member alredy exists in this Listing.
28
     */
29
    public function contains($member): bool
30
    {
31
        return in_array($member, $this->members);
0 ignored issues
show
Bug introduced by
The property members does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
    }
33
}
34