Conditions | 1 |
Paths | 1 |
Total Lines | 60 |
Code Lines | 55 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
72 | public static function setUpProperties($properties, JsonBasicSchema $ownerSchema) |
||
73 | { |
||
74 | $properties->type = JsonBasicSchema::string(); |
||
75 | $properties->type->enum = array ( |
||
76 | 0 => 'string', |
||
77 | 1 => 'number', |
||
78 | 2 => 'integer', |
||
79 | 3 => 'boolean', |
||
80 | 4 => 'array', |
||
81 | ); |
||
82 | $properties->format = JsonBasicSchema::string(); |
||
83 | $properties->items = PrimitivesItems::schema(); |
||
84 | $properties->collectionFormat = JsonBasicSchema::string(); |
||
85 | $properties->collectionFormat->default = 'csv'; |
||
86 | $properties->collectionFormat->enum = array ( |
||
87 | 0 => 'csv', |
||
88 | 1 => 'ssv', |
||
89 | 2 => 'tsv', |
||
90 | 3 => 'pipes', |
||
91 | ); |
||
92 | $properties->default = new JsonBasicSchema(); |
||
93 | $properties->maximum = JsonBasicSchema::number(); |
||
94 | $properties->exclusiveMaximum = JsonBasicSchema::boolean(); |
||
95 | $properties->exclusiveMaximum->default = false; |
||
96 | $properties->minimum = JsonBasicSchema::number(); |
||
97 | $properties->exclusiveMinimum = JsonBasicSchema::boolean(); |
||
98 | $properties->exclusiveMinimum->default = false; |
||
99 | $properties->maxLength = JsonBasicSchema::integer(); |
||
100 | $properties->maxLength->minimum = 0; |
||
|
|||
101 | $properties->minLength = new JsonBasicSchema(); |
||
102 | $properties->minLength->allOf[0] = JsonBasicSchema::integer(); |
||
103 | $properties->minLength->allOf[0]->minimum = 0; |
||
104 | $properties->minLength->allOf[1] = new JsonBasicSchema(); |
||
105 | $properties->minLength->allOf[1]->default = 0; |
||
106 | $properties->pattern = JsonBasicSchema::string(); |
||
107 | $properties->pattern->format = 'regex'; |
||
108 | $properties->maxItems = JsonBasicSchema::integer(); |
||
109 | $properties->maxItems->minimum = 0; |
||
110 | $properties->minItems = new JsonBasicSchema(); |
||
111 | $properties->minItems->allOf[0] = JsonBasicSchema::integer(); |
||
112 | $properties->minItems->allOf[0]->minimum = 0; |
||
113 | $properties->minItems->allOf[1] = new JsonBasicSchema(); |
||
114 | $properties->minItems->allOf[1]->default = 0; |
||
115 | $properties->uniqueItems = JsonBasicSchema::boolean(); |
||
116 | $properties->uniqueItems->default = false; |
||
117 | $properties->enum = JsonBasicSchema::arr(); |
||
118 | $properties->enum->minItems = 1; |
||
119 | $properties->enum->uniqueItems = true; |
||
120 | $properties->multipleOf = JsonBasicSchema::number(); |
||
121 | $properties->multipleOf->minimum = 0; |
||
122 | $properties->multipleOf->exclusiveMinimum = true; |
||
123 | $properties->description = JsonBasicSchema::string(); |
||
124 | $ownerSchema->type = 'object'; |
||
125 | $ownerSchema->additionalProperties = false; |
||
126 | $ownerSchema->patternProperties['^x-'] = new JsonBasicSchema(); |
||
127 | $ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.'; |
||
128 | $ownerSchema->required = array ( |
||
129 | 0 => 'type', |
||
130 | ); |
||
131 | } |
||
132 | |||
314 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.