Passed
Pull Request — master (#8)
by
unknown
05:39
created

ArrayDefinition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 43
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A modelGetter() 0 16 3
A modelProperty() 0 16 3
1
<?php
2
3
namespace Distilleries\Contentful\Commands\Generators\Definitions;
4
5
use Exception;
6
7
class ArrayDefinition extends BaseDefinition
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12
    public function modelGetter()
13
    {
14
        switch ($this->field['items']['type']) {
15
            case 'Link':
16
                $stubPath = __DIR__ . '/stubs/entries.stub';
17
                break;
18
            case 'Symbol':
19
                $stubPath = __DIR__ . '/stubs/string.stub';
20
                break;
21
            default:
22
                throw new Exception('Unknown Array items type "' . $this->field['items']['type'] . '"');
23
        }
24
25
        return self::getStub($stubPath, [
26
            'field' => $this->id(),
27
            'field_studly' => $this->studlyId(),
28
        ]);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function modelProperty()
35
    {
36
        $property = ' * @property ';
37
38
        switch ($this->field['items']['type']) {
39
            case 'Link':
40
                $property .= '\Illuminate\Support\Collection';
41
                break;
42
            case 'Symbol':
43
                $property .= 'string';
44
                break;
45
            default:
46
                throw new Exception('Unknown Array items type "' . $this->field['items']['type'] . '"');
47
        }
48
49
        return $property . ' $' . $this->snakeId();
50
    }
51
}
52