| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 105 | public function testAddQuads() |
||
| 106 | { |
||
| 107 | // check data at the beginning |
||
| 108 | $res = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}'); |
||
| 109 | $this->assertCount(0, $res['result']['rows']); |
||
| 110 | |||
| 111 | /* |
||
| 112 | * add quads |
||
| 113 | */ |
||
| 114 | $df = new DataFactory(); |
||
| 115 | $graph = 'http://graph'; |
||
| 116 | |||
| 117 | // q1 |
||
| 118 | $q1 = $df->quad( |
||
| 119 | $df->namedNode('http://a'), |
||
| 120 | $df->namedNode('http://b'), |
||
| 121 | $df->namedNode('http://c'), |
||
| 122 | $df->namedNode($graph) |
||
| 123 | ); |
||
| 124 | |||
| 125 | // q2 |
||
| 126 | $q2 = $df->quad( |
||
| 127 | $df->blankNode('123'), |
||
| 128 | $df->namedNode('http://b'), |
||
| 129 | $df->literal('foobar', 'de'), |
||
| 130 | $df->namedNode($graph) |
||
| 131 | ); |
||
| 132 | |||
| 133 | $quads = [$q1, $q2]; |
||
| 134 | |||
| 135 | $this->subjectUnderTest->addQuads($quads); |
||
| 136 | |||
| 137 | // check after quads were added |
||
| 138 | $res = $this->subjectUnderTest->query('SELECT * FROM <'.$graph.'> WHERE {?s ?p ?o.}'); |
||
| 139 | $this->assertEquals( |
||
| 140 | [ |
||
| 141 | [ |
||
| 142 | 's' => 'http://a', |
||
| 143 | 's type' => 'uri', |
||
| 144 | 'p' => 'http://b', |
||
| 145 | 'p type' => 'uri', |
||
| 146 | 'o' => 'http://c', |
||
| 147 | 'o type' => 'uri', |
||
| 148 | ], |
||
| 149 | [ |
||
| 150 | 's' => $res['result']['rows'][1]['s'], // dynamic value |
||
| 151 | 's type' => 'bnode', |
||
| 152 | 'p' => 'http://b', |
||
| 153 | 'p type' => 'uri', |
||
| 154 | 'o' => 'foobar', |
||
| 155 | 'o type' => 'literal', |
||
| 156 | 'o lang' => 'de', |
||
| 157 | ], |
||
| 158 | ], |
||
| 159 | $res['result']['rows'] |
||
| 160 | ); |
||
| 163 |