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

ArrayDefinition::modelProperty()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 0
dl 0
loc 16
ccs 0
cts 14
cp 0
crap 12
rs 9.9
c 0
b 0
f 0
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