RandomString   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 23
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A value() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Funivan\CabbageCore\String\StringObject\Random;
6
7
use Funivan\CabbageCore\String\StringList\StringListInterface;
8
use Funivan\CabbageCore\String\StringObject\StringInterface;
9
10
class RandomString implements StringInterface
11
{
12
    /**
13
     * @var StringListInterface
14
     */
15
    private $list;
16
17 1
    public function __construct(StringListInterface $list)
18
    {
19 1
        $this->list = $list;
20 1
    }
21
22 1
    public function value(): string
23
    {
24 1
        $items = \iterator_to_array($this->list->all());
25 1
        shuffle($items);
26 1
        $result = reset($items);
27 1
        if (!is_string($result)) {
28
            throw new \RuntimeException('Can not fetch random string from the list');
29
        }
30 1
        return $result;
31
    }
32
}
33