| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 63 |
| 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 |
||
| 81 | public static function setUpProperties($properties, Schema $ownerSchema) |
||
| 82 | { |
||
| 83 | $properties->required = Schema::boolean(); |
||
| 84 | $properties->required->description = 'Determines whether or not this parameter is required or optional.'; |
||
| 85 | $properties->required->default = false; |
||
| 86 | $properties->in = Schema::string(); |
||
| 87 | $properties->in->description = 'Determines the location of the parameter.'; |
||
| 88 | $properties->in->enum = array ( |
||
| 89 | 0 => 'header', |
||
| 90 | ); |
||
| 91 | $properties->description = Schema::string(); |
||
| 92 | $properties->description->description = 'A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed.'; |
||
| 93 | $properties->name = Schema::string(); |
||
| 94 | $properties->name->description = 'The name of the parameter.'; |
||
| 95 | $properties->type = Schema::string(); |
||
| 96 | $properties->type->enum = array ( |
||
| 97 | 0 => 'string', |
||
| 98 | 1 => 'number', |
||
| 99 | 2 => 'boolean', |
||
| 100 | 3 => 'integer', |
||
| 101 | 4 => 'array', |
||
| 102 | ); |
||
| 103 | $properties->format = Schema::string(); |
||
| 104 | $properties->items = PrimitivesItems::schema(); |
||
| 105 | $properties->collectionFormat = Schema::string(); |
||
| 106 | $properties->collectionFormat->default = 'csv'; |
||
| 107 | $properties->collectionFormat->enum = array ( |
||
| 108 | 0 => 'csv', |
||
| 109 | 1 => 'ssv', |
||
| 110 | 2 => 'tsv', |
||
| 111 | 3 => 'pipes', |
||
| 112 | ); |
||
| 113 | $properties->default = new Schema(); |
||
| 114 | $properties->maximum = Schema::number(); |
||
| 115 | $properties->exclusiveMaximum = Schema::boolean(); |
||
| 116 | $properties->exclusiveMaximum->default = false; |
||
| 117 | $properties->minimum = Schema::number(); |
||
| 118 | $properties->exclusiveMinimum = Schema::boolean(); |
||
| 119 | $properties->exclusiveMinimum->default = false; |
||
| 120 | $properties->maxLength = Schema::integer(); |
||
| 121 | $properties->maxLength->minimum = 0; |
||
| 122 | $properties->minLength = new Schema(); |
||
| 123 | $properties->minLength->allOf[0] = Schema::integer(); |
||
| 124 | $properties->minLength->allOf[0]->minimum = 0; |
||
| 125 | $properties->minLength->allOf[1] = new Schema(); |
||
| 126 | $properties->minLength->allOf[1]->default = 0; |
||
| 127 | $properties->pattern = Schema::string(); |
||
| 128 | $properties->pattern->format = 'regex'; |
||
| 129 | $properties->maxItems = Schema::integer(); |
||
| 130 | $properties->maxItems->minimum = 0; |
||
| 131 | $properties->minItems = new Schema(); |
||
| 132 | $properties->minItems->allOf[0] = Schema::integer(); |
||
| 133 | $properties->minItems->allOf[0]->minimum = 0; |
||
| 134 | $properties->minItems->allOf[1] = new Schema(); |
||
| 135 | $properties->minItems->allOf[1]->default = 0; |
||
| 136 | $properties->uniqueItems = Schema::boolean(); |
||
| 137 | $properties->uniqueItems->default = false; |
||
| 138 | $properties->enum = Schema::arr(); |
||
| 139 | $properties->enum->minItems = 1; |
||
| 140 | $properties->enum->uniqueItems = true; |
||
| 141 | $properties->multipleOf = Schema::number(); |
||
| 142 | $properties->multipleOf->minimum = 0; |
||
| 143 | $properties->multipleOf->exclusiveMinimum = true; |
||
| 144 | $ownerSchema = new Schema(); |
||
| 145 | $ownerSchema->additionalProperties = false; |
||
| 146 | $ownerSchema->patternProperties['^x-'] = new Schema(); |
||
| 147 | $ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.'; |
||
| 148 | } |
||
| 149 | } |
||
| 151 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: