StringContainer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkMember() 0 10 2
A contains() 0 4 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