Completed
Push — master ( 814431...bcdc84 )
by Viacheslav
10:46 queued 15s
created

BuilderOptions::makeGoBuilderOptions()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 18
nc 2
nop 0
dl 0
loc 23
rs 9.6666
c 1
b 0
f 0
1
<?php
2
3
namespace Swaggest\JsonCli\GenGo;
4
5
use Swaggest\GoCodeBuilder\JsonSchema\Options;
6
use Yaoi\Command\Option;
7
8
trait BuilderOptions
9
{
10
    /** @var bool */
11
    public $showConstProperties = false;
12
    /** @var bool */
13
    public $keepParentInPropertyNames = false;
14
    /** @var bool */
15
    public $ignoreNullable;
16
    /** @var bool */
17
    public $ignoreXGoType;
18
    /** @var bool */
19
    public $withZeroValues;
20
    /** @var bool */
21
    public $enableXNullable;
22
    /** @var bool */
23
    public $enableDefaultAdditionalProperties;
24
    /** @var bool */
25
    public $fluentSetters;
26
    /** @var bool */
27
    public $ignoreRequired = false;
28
29
    /** @var array<string, string> */
30
    public $renames = [];
31
32
    /** @var bool */
33
    public $requireXGenerate = false;
34
35
    /** @var bool */
36
    public $validateRequired = false;
37
38
    /** @var string[] */
39
    public $nameTags = [];
40
41
    /**
42
     * @param \stdClass|static $options
43
     */
44
    public static function setUpBuilderOptions($options)
45
    {
46
        $options->showConstProperties = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...es, hidden by default') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $showConstProperties.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47
            ->setDescription('Show properties with constant values, hidden by default');
48
49
        $options->keepParentInPropertyNames = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...e, removed by default') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $keepParentInPropertyNames.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
            ->setDescription('Keep parent prefix in property name, removed by default');
51
52
        $options->ignoreNullable = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...s, removed by default') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $ignoreNullable.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53
            ->setDescription('Add `omitempty` to nullable properties, removed by default');
54
55
        $options->ignoreXGoType = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...ma to skip generation') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $ignoreXGoType.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
            ->setName('ignore-x-go-type')
57
            ->setDescription('Ignore `x-go-type` in schema to skip generation');
58
59
        $options->withZeroValues = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre... zero value ambiguity') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $withZeroValues.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
            ->setDescription('Use pointer types to avoid zero value ambiguity');
61
62
        $options->enableXNullable = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...ullable` is available') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $enableXNullable.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
63
            ->setDescription('Add `null` to types if `x-nullable` or `nullable` is available');
64
65
        $options->enableDefaultAdditionalProperties = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...additionalProperties`') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $enableDefaultAdditionalProperties.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
66
            ->setDescription('Add field property for undefined `additionalProperties`');
67
68
        $options->fluentSetters = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...ters to struct fields') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $fluentSetters.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
69
            ->setDescription('Add fluent setters to struct fields');
70
71
        $options->ignoreRequired = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...ter type or omitempty') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $ignoreRequired.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
72
            ->setDescription('Ignore if property is required when deciding on pointer type or omitempty');
73
74
        $options->renames = Option::create()->setIsVariadic()->setType()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...ames, example From:To') of type Yaoi\Command\Option is incompatible with the declared type array<string,string> of property $renames.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
75
            ->setDescription('Map of exported symbol renames, example From:To');
76
77
        $options->requireXGenerate = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...-generate: true` only') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $requireXGenerate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
78
            ->setDescription('Generate properties with `x-generate: true` only');
79
80
        $options->validateRequired = Option::create()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre...ties during unmarshal') of type Yaoi\Command\Option is incompatible with the declared type boolean of property $validateRequired.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
81
            ->setDescription('Generate validation code to check required properties during unmarshal');
82
83
        $options->nameTags = Option::create()->setIsVariadic()->setType()
0 ignored issues
show
Documentation Bug introduced by
It seems like Yaoi\Command\Option::cre..., example "msgp bson"') of type Yaoi\Command\Option is incompatible with the declared type string[] of property $nameTags.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
84
            ->setDescription('Set additional field tags with property name, example "msgp bson"');
85
    }
86
87
    /**
88
     * @return Options
89
     */
90
    protected function makeGoBuilderOptions()
91
    {
92
        $options = new Options();
93
        $options->hideConstProperties = !$this->showConstProperties;
94
        $options->trimParentFromPropertyNames = !$this->keepParentInPropertyNames;
95
        $options->ignoreNullable = $this->ignoreNullable;
96
        $options->ignoreXGoType = $this->ignoreXGoType;
97
        $options->withZeroValues = $this->withZeroValues;
98
        $options->enableXNullable = $this->enableXNullable;
99
        $options->defaultAdditionalProperties = $this->enableDefaultAdditionalProperties;
100
        $options->fluentSetters = $this->fluentSetters;
101
        $options->ignoreRequired = $this->ignoreRequired;
102
        $options->requireXGenerate = $this->requireXGenerate;
103
        $options->validateRequired = $this->validateRequired;
104
        $options->nameTags = $this->nameTags;
105
        if (!empty($this->renames)) {
106
            foreach ($this->renames as $rename) {
107
                $rename = explode(':', $rename, 2);
108
                $options->renames[$rename[0]] = $rename[1];
109
            }
110
        }
111
112
        return $options;
113
    }
114
115
}