| Conditions | 1 |
| Paths | 1 |
| Total Lines | 154 |
| Code Lines | 117 |
| 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 |
||
| 27 | public function validProvider() { |
||
| 28 | $withNameArrayFormatter = $this->getMock('PPP\Wikidata\ValueFormatters\JsonLd\JsonLdDataValueFormatter'); |
||
| 29 | $withNameArrayFormatter->expects($this->once()) |
||
| 30 | ->method('format') |
||
| 31 | ->with($this->equalTo(new EntityIdValue(new ItemId('Q1')))) |
||
| 32 | ->will($this->returnValue((object) array('@type' => 'Thing', 'name' => array('foo')))); |
||
| 33 | |||
| 34 | $withNameObjectFormatter = $this->getMock('PPP\Wikidata\ValueFormatters\JsonLd\JsonLdDataValueFormatter'); |
||
| 35 | $withNameObjectFormatter->expects($this->once()) |
||
| 36 | ->method('format') |
||
| 37 | ->with($this->equalTo(new EntityIdValue(new ItemId('Q1')))) |
||
| 38 | ->will($this->returnValue((object) array( |
||
| 39 | '@type' => 'Thing', |
||
| 40 | 'name' => (object) array('@language' => 'en', '@value' => 'foo'), |
||
| 41 | '@reverse' => (object) array() |
||
| 42 | ))); |
||
| 43 | |||
| 44 | $withOtherLanguageNameFormatter = $this->getMock('PPP\Wikidata\ValueFormatters\JsonLd\JsonLdDataValueFormatter'); |
||
| 45 | $withOtherLanguageNameFormatter->expects($this->once()) |
||
| 46 | ->method('format') |
||
| 47 | ->with($this->equalTo(new EntityIdValue(new ItemId('Q1')))) |
||
| 48 | ->will($this->returnValue((object) array( |
||
| 49 | '@type' => 'Thing', |
||
| 50 | 'name' => (object) array('@language' => 'fr', '@value' => 'foo') |
||
| 51 | ))); |
||
| 52 | |||
| 53 | $snakFormatterMock = $this->getMock('ValueFormatters\ValueFormatter'); |
||
| 54 | $snakFormatterMock->expects($this->any()) |
||
| 55 | ->method('format') |
||
| 56 | ->with($this->equalTo(new PropertyValueSnak(new PropertyId('P21'), new EntityIdValue(new ItemId('Q1'))))) |
||
| 57 | ->willReturn(array( |
||
| 58 | 'http://schema.org/gender' => (object) array('name' => 'foo') |
||
| 59 | )); |
||
| 60 | |||
| 61 | |||
| 62 | $snakEmptyFormatterMock = $this->getMock('ValueFormatters\ValueFormatter'); |
||
| 63 | $snakEmptyFormatterMock->expects($this->any()) |
||
| 64 | ->method('format') |
||
| 65 | ->with($this->equalTo(new PropertyValueSnak(new PropertyId('P21'), new EntityIdValue(new ItemId('Q1'))))) |
||
| 66 | ->willReturn(array()); |
||
| 67 | |||
| 68 | $withTypeLiteralFormatter = $this->getMock('PPP\Wikidata\ValueFormatters\JsonLd\JsonLdDataValueFormatter'); |
||
| 69 | $withTypeLiteralFormatter->expects($this->once()) |
||
| 70 | ->method('format') |
||
| 71 | ->with($this->equalTo(new TimeValue('+1952-03-11T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, 'http://www.wikidata.org/entity/Q1985786'))) |
||
| 72 | ->will($this->returnValue((object) array('@type' => 'Date', '@value' => '1952-03-11'))); |
||
| 73 | |||
| 74 | $withoutTypeLiteralFormatter = $this->getMock('PPP\Wikidata\ValueFormatters\JsonLd\JsonLdDataValueFormatter'); |
||
| 75 | $withoutTypeLiteralFormatter->expects($this->once()) |
||
| 76 | ->method('format') |
||
| 77 | ->with($this->equalTo(new MonolingualTextValue('en', 'foo'))) |
||
| 78 | ->will($this->returnValue((object) array('@language' => 'en', '@value' => 'foo'))); |
||
| 79 | |||
| 80 | return array( |
||
| 81 | array( |
||
| 82 | new WikibaseResourceNode( |
||
| 83 | '', |
||
| 84 | new EntityIdValue(new ItemId('Q1')), |
||
| 85 | new ItemId('Q1'), |
||
| 86 | new PropertyId('P21') |
||
| 87 | ), |
||
| 88 | new JsonLdResourceNode( |
||
| 89 | 'foo', |
||
| 90 | (object) array( |
||
| 91 | '@context' => 'http://schema.org', |
||
| 92 | '@type' => 'Thing', |
||
| 93 | 'name' => array('foo'), |
||
| 94 | '@reverse' => (object) array( |
||
| 95 | 'http://schema.org/gender' => array((object) array('name' => 'foo')) |
||
| 96 | ) |
||
| 97 | ) |
||
| 98 | ), |
||
| 99 | null, |
||
| 100 | new JsonLdResourceFormatter($withNameArrayFormatter, $snakFormatterMock, new FormatterOptions()) |
||
| 101 | ), |
||
| 102 | array( |
||
| 103 | new WikibaseResourceNode( |
||
| 104 | '', |
||
| 105 | new EntityIdValue(new ItemId('Q1')), |
||
| 106 | new ItemId('Q1'), |
||
| 107 | new PropertyId('P21') |
||
| 108 | ), |
||
| 109 | new JsonLdResourceNode( |
||
| 110 | 'foo', |
||
| 111 | (object) array( |
||
| 112 | '@context' => 'http://schema.org', |
||
| 113 | '@type' => 'Thing', |
||
| 114 | 'name' => (object) array('@language' => 'en', '@value' => 'foo'), |
||
| 115 | '@reverse' => (object) array( |
||
| 116 | 'http://schema.org/gender' => array((object) array('name' => 'foo')) |
||
| 117 | ) |
||
| 118 | ) |
||
| 119 | ), |
||
| 120 | null, |
||
| 121 | new JsonLdResourceFormatter($withNameObjectFormatter, $snakFormatterMock, new FormatterOptions()) |
||
| 122 | ), |
||
| 123 | array( |
||
| 124 | new WikibaseResourceNode( |
||
| 125 | '', |
||
| 126 | new EntityIdValue(new ItemId('Q1')) |
||
| 127 | ), |
||
| 128 | new JsonLdResourceNode( |
||
| 129 | 'foo', |
||
| 130 | (object) array( |
||
| 131 | '@context' => 'http://schema.org', |
||
| 132 | '@type' => 'Thing', |
||
| 133 | 'name' => (object) array('@language' => 'fr', '@value' => 'foo') |
||
| 134 | ) |
||
| 135 | ), |
||
| 136 | null, |
||
| 137 | new JsonLdResourceFormatter($withOtherLanguageNameFormatter, $snakFormatterMock, new FormatterOptions()) |
||
| 138 | ), |
||
| 139 | array( |
||
| 140 | new WikibaseResourceNode( |
||
| 141 | '', |
||
| 142 | new TimeValue('+1952-03-11T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, 'http://www.wikidata.org/entity/Q1985786') |
||
| 143 | ), |
||
| 144 | new JsonLdResourceNode( |
||
| 145 | '1952-03-11', |
||
| 146 | (object) array( |
||
| 147 | '@context' => 'http://schema.org', |
||
| 148 | '@type' => 'Date', |
||
| 149 | 'http://www.w3.org/1999/02/22-rdf-syntax-ns#value' => (object) array( |
||
| 150 | '@type' => 'Date', |
||
| 151 | '@value' => '1952-03-11' |
||
| 152 | ) |
||
| 153 | ) |
||
| 154 | ), |
||
| 155 | null, |
||
| 156 | new JsonLdResourceFormatter($withTypeLiteralFormatter, $snakFormatterMock, new FormatterOptions()) |
||
| 157 | ), |
||
| 158 | array( |
||
| 159 | new WikibaseResourceNode( |
||
| 160 | '', |
||
| 161 | new MonolingualTextValue('en', 'foo'), |
||
| 162 | new ItemId('Q1'), |
||
| 163 | new PropertyId('P21') |
||
| 164 | ), |
||
| 165 | new JsonLdResourceNode( |
||
| 166 | 'foo', |
||
| 167 | (object) array( |
||
| 168 | '@context' => 'http://schema.org', |
||
| 169 | '@type' => 'Text', |
||
| 170 | 'http://www.w3.org/1999/02/22-rdf-syntax-ns#value' => (object) array( |
||
| 171 | '@language' => 'en', |
||
| 172 | '@value' => 'foo' |
||
| 173 | ) |
||
| 174 | ) |
||
| 175 | ), |
||
| 176 | null, |
||
| 177 | new JsonLdResourceFormatter($withoutTypeLiteralFormatter, $snakEmptyFormatterMock, new FormatterOptions()) |
||
| 178 | ), |
||
| 179 | ); |
||
| 180 | } |
||
| 181 | |||
| 189 |