Completed
Pull Request — master (#22)
by Sergey
23:00 queued 08:02
created

ElasticsearchCollectionParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 25
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A getIndex() 0 4 1
A getType() 0 4 1
1
<?php
2
3
namespace Isswp101\Persimmon\CollectionParser;
4
5
use Isswp101\Persimmon\Exceptions\IllegalCollectionException;
6
7
class ElasticsearchCollectionParser
8
{
9
    private $index;
10
    private $type;
11
12
    public function __construct(string $collection)
13
    {
14
        $keys = explode('/', $collection);
15
        $this->index = $keys[0] ?? null;
16
        $this->type = $keys[1] ?? null;
17
        if ($this->index == null || $this->type == null) {
18
            throw new IllegalCollectionException();
19
        }
20
    }
21
22
    public function getIndex(): string
23
    {
24
        return $this->index;
25
    }
26
27
    public function getType(): string
28
    {
29
        return $this->type;
30
    }
31
}