Conditions | 5 |
Paths | 3 |
Total Lines | 62 |
Code Lines | 26 |
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 |
||
21 | public function write(SchemaRdfaData $schemaData) |
||
22 | { |
||
23 | foreach ($schemaData->getClassesWithPropertyNames() as $class) { |
||
24 | $className = $class->name; |
||
25 | $methods = []; |
||
26 | |||
27 | if (!empty($class->properties)) { |
||
28 | foreach ($class->properties as $property) { |
||
29 | $propertyName = $property['name']; |
||
30 | $propertyNameMethodName = $propertyName; |
||
31 | $propertyNameMethodName[0] = strtoupper($propertyNameMethodName[0]); |
||
32 | |||
33 | if (empty($usableProperties[$propertyNameMethodName])) { |
||
34 | $methods[$propertyName] = <<<PHP |
||
35 | public function test{$propertyNameMethodName}WillReturnMappingObject() |
||
36 | { |
||
37 | \$this->assertInstanceOf(Mapping::class, {$className}::{$propertyName}()); |
||
38 | } |
||
39 | PHP; |
||
40 | } |
||
41 | } |
||
42 | } |
||
43 | |||
44 | ksort($methods, SORT_REGULAR); |
||
45 | $methods = implode("\n\n", $methods); |
||
46 | |||
47 | $schemaData = (array) $class; |
||
48 | |||
49 | $phpCode = <<<PHP |
||
50 | <?php |
||
51 | /** |
||
52 | * Author: Nil Portugués Calderó <[email protected]> |
||
53 | * Date: 12/18/15 |
||
54 | * Time: 11:36 PM. |
||
55 | * |
||
56 | * For the full copyright and license information, please view the LICENSE |
||
57 | * file that was distributed with this source code. |
||
58 | */ |
||
59 | |||
60 | namespace NilPortugues\Tests\SchemaOrg\Classes; |
||
61 | |||
62 | use NilPortugues\\SchemaOrg\\Classes\\{$schemaData['name']}; |
||
63 | use NilPortugues\\SchemaOrg\\Mapping; |
||
64 | |||
65 | /** |
||
66 | * Classes {$schemaData['name']}Test |
||
67 | * @package NilPortugues\\Tests\\SchemaOrg\\Classes |
||
68 | */ |
||
69 | class {$schemaData['name']}Test extends \PHPUnit_Framework_TestCase |
||
70 | { |
||
71 | public function testSchemaUrlReturnsExpectedUrl() |
||
72 | { |
||
73 | \$this->assertEquals({$schemaData['name']}::schemaUrl(), "{$schemaData['url']}"); |
||
74 | } |
||
75 | |||
76 | $methods |
||
77 | } |
||
78 | PHP; |
||
79 | |||
80 | $this->fileSystem->write($this->savePath.DIRECTORY_SEPARATOR.$className.'Test.php', $phpCode); |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 |