Completed
Push — master ( 49dc1a...1f58a4 )
by Yaro
06:59
created

BelongsToArray   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 28
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A belongsToArray() 0 4 1
A getAncestorName() 0 6 1
A getDescendantName() 0 6 1
A getDotPatternName() 0 4 1
name() 0 1 ?
1
<?php
2
3
namespace Yaro\Jarboe\Table\Fields\Traits;
4
5
trait BelongsToArray
6
{
7
    public function belongsToArray(): bool
8
    {
9
        return (bool) preg_match('~^[^\[\]]+\[[^\[\]]+\]$~', $this->name());
10
    }
11
12
    public function getAncestorName(): string
13
    {
14
        preg_match('~^([^\[\]]+)\[[^\[\]]+\]$~', $this->name(), $matches);
15
16
        return $matches[1];
17
    }
18
19
    public function getDescendantName(): string
20
    {
21
        preg_match('~^[^\[\]]+\[([^\[\]]+)\]$~', $this->name(), $matches);
22
23
        return $matches[1];
24
    }
25
26
    public function getDotPatternName(): string
27
    {
28
        return sprintf('%s.%s', $this->getAncestorName(), $this->getDescendantName());
29
    }
30
31
    abstract public function name(string $name = null);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
32
}
33