Conditions | 1 |
Paths | 1 |
Total Lines | 80 |
Code Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
55 | public static function setUpProperties($properties, Schema $ownerSchema) |
||
56 | { |
||
57 | $properties->tags = Schema::arr(); |
||
58 | $properties->tags->items = Schema::string(); |
||
59 | $properties->tags->uniqueItems = true; |
||
60 | $properties->summary = Schema::string(); |
||
61 | $properties->summary->description = 'A brief summary of the operation.'; |
||
62 | $properties->description = Schema::string(); |
||
63 | $properties->description->description = 'A longer description of the operation, GitHub Flavored Markdown is allowed.'; |
||
64 | $properties->externalDocs = ExternalDocs::schema(); |
||
65 | $properties->operationId = Schema::string(); |
||
66 | $properties->operationId->description = 'A unique identifier of the operation.'; |
||
67 | $properties->produces = new Schema(); |
||
68 | $properties->produces->allOf[0] = Schema::arr(); |
||
69 | $properties->produces->allOf[0]->items = Schema::string(); |
||
70 | $properties->produces->allOf[0]->items->description = 'The MIME type of the HTTP message.'; |
||
71 | $properties->produces->allOf[0]->uniqueItems = true; |
||
72 | $properties->produces->description = 'A list of MIME types the API can produce.'; |
||
73 | $properties->consumes = new Schema(); |
||
74 | $properties->consumes->allOf[0] = Schema::arr(); |
||
75 | $properties->consumes->allOf[0]->items = Schema::string(); |
||
76 | $properties->consumes->allOf[0]->items->description = 'The MIME type of the HTTP message.'; |
||
77 | $properties->consumes->allOf[0]->uniqueItems = true; |
||
78 | $properties->consumes->description = 'A list of MIME types the API can consume.'; |
||
79 | $properties->parameters = Schema::arr(); |
||
80 | $properties->parameters->items = new Schema(); |
||
81 | $properties->parameters->items->oneOf[0] = new Schema(); |
||
82 | $properties->parameters->items->oneOf[0]->oneOf[0] = BodyParameter::schema(); |
||
83 | $properties->parameters->items->oneOf[0]->oneOf[1] = Schema::object(); |
||
84 | $properties->parameters->items->oneOf[0]->oneOf[1]->oneOf[0] = HeaderParameterSubSchema::schema(); |
||
85 | $properties->parameters->items->oneOf[0]->oneOf[1]->oneOf[1] = FormDataParameterSubSchema::schema(); |
||
86 | $properties->parameters->items->oneOf[0]->oneOf[1]->oneOf[2] = QueryParameterSubSchema::schema(); |
||
87 | $properties->parameters->items->oneOf[0]->oneOf[1]->oneOf[3] = PathParameterSubSchema::schema(); |
||
88 | $properties->parameters->items->oneOf[0]->oneOf[1]->required = array ( |
||
89 | 0 => 'name', |
||
90 | 1 => 'in', |
||
91 | 2 => 'type', |
||
92 | ); |
||
93 | $properties->parameters->items->oneOf[1] = JsonReference::schema(); |
||
94 | $properties->parameters->description = 'The parameters needed to send a valid API call.'; |
||
95 | $properties->parameters->uniqueItems = true; |
||
96 | $properties->responses = Schema::object(); |
||
97 | $properties->responses->additionalProperties = false; |
||
98 | $properties->responses->patternProperties['^([0-9]{3})$|^(default)$'] = new Schema(); |
||
99 | $properties->responses->patternProperties['^([0-9]{3})$|^(default)$']->oneOf[0] = Response::schema(); |
||
100 | $properties->responses->patternProperties['^([0-9]{3})$|^(default)$']->oneOf[1] = JsonReference::schema(); |
||
101 | $properties->responses->patternProperties['^x-'] = new Schema(); |
||
102 | $properties->responses->patternProperties['^x-']->description = 'Any property starting with x- is valid.'; |
||
103 | $properties->responses->not = Schema::object(); |
||
104 | $properties->responses->not->additionalProperties = false; |
||
105 | $properties->responses->not->patternProperties['^x-'] = new Schema(); |
||
106 | $properties->responses->not->patternProperties['^x-']->description = 'Any property starting with x- is valid.'; |
||
107 | $properties->responses->description = 'Response objects names can either be any valid HTTP status code or \'default\'.'; |
||
108 | $properties->responses->minProperties = 1; |
||
109 | $properties->schemes = Schema::arr(); |
||
110 | $properties->schemes->items = Schema::string(); |
||
111 | $properties->schemes->items->enum = array ( |
||
112 | 0 => 'http', |
||
113 | 1 => 'https', |
||
114 | 2 => 'ws', |
||
115 | 3 => 'wss', |
||
116 | ); |
||
117 | $properties->schemes->description = 'The transfer protocol of the API.'; |
||
118 | $properties->schemes->uniqueItems = true; |
||
119 | $properties->deprecated = Schema::boolean(); |
||
120 | $properties->deprecated->default = false; |
||
121 | $properties->security = Schema::arr(); |
||
122 | $properties->security->items = Schema::object(); |
||
123 | $properties->security->items->additionalProperties = Schema::arr(); |
||
124 | $properties->security->items->additionalProperties->items = Schema::string(); |
||
125 | $properties->security->items->additionalProperties->uniqueItems = true; |
||
126 | $properties->security->uniqueItems = true; |
||
127 | $ownerSchema->type = 'object'; |
||
128 | $ownerSchema->additionalProperties = false; |
||
129 | $ownerSchema->patternProperties['^x-'] = new Schema(); |
||
130 | $ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.'; |
||
131 | $ownerSchema->required = array ( |
||
132 | 0 => 'responses', |
||
133 | ); |
||
134 | } |
||
135 | } |
||
137 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: