| Conditions | 1 |
| Paths | 1 |
| Total Lines | 60 |
| Code Lines | 55 |
| 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 |
||
| 72 | public static function setUpProperties($properties, Schema $ownerSchema) |
||
| 73 | { |
||
| 74 | $properties->type = Schema::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 = Schema::string(); |
||
| 83 | $properties->items = PrimitivesItems::schema(); |
||
| 84 | $properties->collectionFormat = Schema::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 Schema(); |
||
| 93 | $properties->maximum = Schema::number(); |
||
| 94 | $properties->exclusiveMaximum = Schema::boolean(); |
||
| 95 | $properties->exclusiveMaximum->default = false; |
||
| 96 | $properties->minimum = Schema::number(); |
||
| 97 | $properties->exclusiveMinimum = Schema::boolean(); |
||
| 98 | $properties->exclusiveMinimum->default = false; |
||
| 99 | $properties->maxLength = Schema::integer(); |
||
| 100 | $properties->maxLength->minimum = 0; |
||
| 101 | $properties->minLength = new Schema(); |
||
| 102 | $properties->minLength->allOf[0] = Schema::integer(); |
||
| 103 | $properties->minLength->allOf[0]->minimum = 0; |
||
| 104 | $properties->minLength->allOf[1] = new Schema(); |
||
| 105 | $properties->minLength->allOf[1]->default = 0; |
||
| 106 | $properties->pattern = Schema::string(); |
||
| 107 | $properties->pattern->format = 'regex'; |
||
| 108 | $properties->maxItems = Schema::integer(); |
||
| 109 | $properties->maxItems->minimum = 0; |
||
| 110 | $properties->minItems = new Schema(); |
||
| 111 | $properties->minItems->allOf[0] = Schema::integer(); |
||
| 112 | $properties->minItems->allOf[0]->minimum = 0; |
||
| 113 | $properties->minItems->allOf[1] = new Schema(); |
||
| 114 | $properties->minItems->allOf[1]->default = 0; |
||
| 115 | $properties->uniqueItems = Schema::boolean(); |
||
| 116 | $properties->uniqueItems->default = false; |
||
| 117 | $properties->enum = Schema::arr(); |
||
| 118 | $properties->enum->minItems = 1; |
||
| 119 | $properties->enum->uniqueItems = true; |
||
| 120 | $properties->multipleOf = Schema::number(); |
||
| 121 | $properties->multipleOf->minimum = 0; |
||
| 122 | $properties->multipleOf->exclusiveMinimum = true; |
||
| 123 | $properties->description = Schema::string(); |
||
| 124 | $ownerSchema->type = 'object'; |
||
| 125 | $ownerSchema->additionalProperties = false; |
||
| 126 | $ownerSchema->patternProperties['^x-'] = new Schema(); |
||
| 127 | $ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.'; |
||
| 128 | $ownerSchema->required = array ( |
||
| 129 | 0 => 'type', |
||
| 130 | ); |
||
| 131 | } |
||
| 132 | } |
||
| 134 |
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: