| Conditions | 4 |
| Paths | 4 |
| Total Lines | 55 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| 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 |
||
| 21 | public function write(SchemaRdfaData $schemaData) |
||
| 22 | { |
||
| 23 | foreach ($schemaData->getProperties() as $property) { |
||
| 24 | $className = $property['name']; |
||
| 25 | $className[0] = strtoupper($className[0]); |
||
| 26 | |||
| 27 | $allowed = []; |
||
| 28 | foreach ($property['usedOnClass'] as $belongs) { |
||
| 29 | if ('Type' === substr($belongs, -4)) { |
||
| 30 | $belongs = substr($belongs, 0, -4); |
||
| 31 | } |
||
| 32 | |||
| 33 | $allowed[] = "\t\t'".'http://schema.org/'.$belongs."'"; |
||
| 34 | } |
||
| 35 | $allowed = implode(",\n", $allowed); |
||
| 36 | |||
| 37 | $phpPropertyCode = <<<PHP |
||
| 38 | <?php |
||
| 39 | /** |
||
| 40 | * Author: Nil Portugués Calderó <[email protected]> |
||
| 41 | * Date: 12/18/15 |
||
| 42 | * Time: 11:36 PM. |
||
| 43 | * |
||
| 44 | * For the full copyright and license information, please view the LICENSE |
||
| 45 | * file that was distributed with this source code. |
||
| 46 | */ |
||
| 47 | |||
| 48 | namespace NilPortugues\SchemaOrg\Properties; |
||
| 49 | |||
| 50 | use NilPortugues\SchemaOrg\SchemaProperty; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {$property['doc']} |
||
| 54 | */ |
||
| 55 | class {$className}Property extends SchemaProperty |
||
| 56 | { |
||
| 57 | const SCHEMA_URL = "{$property['url']}"; |
||
| 58 | const PROPERTY_NAME = "{$property['name']}"; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * A list of schemas allowed to use this property. |
||
| 62 | * |
||
| 63 | * @var array |
||
| 64 | */ |
||
| 65 | protected static \$allowedSchemas = [ |
||
| 66 | {$allowed} |
||
| 67 | ]; |
||
| 68 | } |
||
| 69 | PHP; |
||
| 70 | $this->fileSystem->write( |
||
| 71 | $this->savePath.DIRECTORY_SEPARATOR.$className.'Property.php', |
||
| 72 | $phpPropertyCode |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 |