| Conditions | 2 |
| Paths | 2 |
| Total Lines | 55 |
| Code Lines | 36 |
| 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 |
||
| 78 | public function testWithResult() { |
||
| 79 | $query = new Query('Hemelinger', array( |
||
| 80 | Document::FIELD_TYPE => array( |
||
| 81 | '\StingerSoft\TestBundle\Entity\Test' |
||
| 82 | ) |
||
| 83 | ), array( |
||
| 84 | Document::FIELD_TYPE |
||
| 85 | )); |
||
| 86 | |||
| 87 | $result = new ResultSetAdapter(); |
||
| 88 | $typeFacets = new FacetSetAdapter(); |
||
| 89 | $typeFacets->addFacetValue(Document::FIELD_TYPE, '\StingerSoft\TestBundle\Entity\Test'); |
||
| 90 | $typeFacets->addFacetValue(Document::FIELD_TYPE, '\StingerSoft\TestBundle\Entity\TestNew'); |
||
| 91 | $result->setFacets($typeFacets); |
||
| 92 | |||
| 93 | $form = $this->factory->create(QueryType::class, $query, array( |
||
| 94 | 'used_facets' => $query->getUsedFacets(), |
||
| 95 | 'result' => $result |
||
| 96 | )); |
||
| 97 | |||
| 98 | $expectedQuery = new Query('Hemelinger', array( |
||
| 99 | Document::FIELD_TYPE => array( |
||
| 100 | '\StingerSoft\TestBundle\Entity\Test' |
||
| 101 | ) |
||
| 102 | ), array( |
||
| 103 | Document::FIELD_TYPE |
||
| 104 | )); |
||
| 105 | |||
| 106 | $formData = array( |
||
| 107 | 'searchTerm' => 'Hemelinger', |
||
| 108 | 'facet_type' => array( |
||
| 109 | '\StingerSoft\TestBundle\Entity\Test' |
||
| 110 | ) |
||
| 111 | ); |
||
| 112 | |||
| 113 | // submit the data to the form directly |
||
| 114 | $form->submit($formData); |
||
| 115 | |||
| 116 | $this->assertTrue($form->isSynchronized()); |
||
| 117 | $this->assertTrue($form->isValid()); |
||
| 118 | $this->assertCount(0, $form->getErrors(true, true)); |
||
| 119 | $this->assertEquals($expectedQuery, $form->getData()); |
||
| 120 | |||
| 121 | $view = $form->createView(); |
||
| 122 | $children = $view->children; |
||
| 123 | |||
| 124 | foreach(array_keys($formData) as $key) { |
||
| 125 | $this->assertArrayHasKey($key, $children); |
||
| 126 | } |
||
| 127 | |||
| 128 | $typeForm = $view->offsetGet('facet_type'); |
||
| 129 | $this->assertEquals(2, $typeForm->count()); |
||
| 130 | $this->assertContains('\StingerSoft\TestBundle\Entity\Test', $typeForm->vars['value']); |
||
| 131 | $this->assertCount(2, $typeForm->vars['choices']); |
||
| 132 | } |
||
| 133 | |||
| 169 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: