Completed
Push — master ( 8b1d39...e6cddd )
by Jakob
01:31
created

Listing::checkMember()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
nc 2
cc 2
eloc 5
nop 1
1
<?php declare(strict_types = 1);
2
3
namespace JSKOS;
4
5
use InvalidArgumentException;
6
7
/**
8
 * A JSKOS List as defined by JSKOS specification.
9
 */
10 View Code Duplication
class Listing extends Container
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...
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('JSKOS\Listing may only contain strings');
21
        }
22
    }
23
24
    /**
25
     * Check whether an equal member alredy exists in this Listing.
26
     */
27
    public function contains($member): bool
28
    {
29
        return in_array($member, $this->members);
30
    }
31
32
    /**
33
     * Join List members with a string
34
     * @param $glue string
35
     */
36
    public function implode(string $glue): string
37
    {
38
        return implode($glue, $this->members);
39
    }
40
}
41