Conditions | 2 |
Paths | 2 |
Total Lines | 54 |
Code Lines | 35 |
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 |
||
74 | public function testWithResult() { |
||
75 | $query = new Query('Hemelinger', array( |
||
76 | Document::FIELD_TYPE => array( |
||
77 | '\StingerSoft\TestBundle\Entity\Test' |
||
78 | ) |
||
79 | ), array( |
||
80 | Document::FIELD_TYPE |
||
81 | )); |
||
82 | |||
83 | $result = new ResultSetAdapter(); |
||
84 | $typeFacets = new FacetSetAdapter(); |
||
85 | $typeFacets->addFacetValue(Document::FIELD_TYPE, '\StingerSoft\TestBundle\Entity\Test'); |
||
86 | $typeFacets->addFacetValue(Document::FIELD_TYPE, '\StingerSoft\TestBundle\Entity\TestNew'); |
||
87 | $result->setFacets($typeFacets); |
||
88 | |||
89 | $form = $this->factory->create(QueryType::class, $query, array( |
||
90 | 'used_facets' => $query->getUsedFacets(), |
||
91 | 'result' => $result |
||
92 | )); |
||
93 | |||
94 | $expectedQuery = new Query('Hemelinger', array( |
||
95 | Document::FIELD_TYPE => array( |
||
96 | '\StingerSoft\TestBundle\Entity\Test' |
||
97 | ) |
||
98 | ), array( |
||
99 | Document::FIELD_TYPE |
||
100 | )); |
||
101 | |||
102 | $formData = array( |
||
103 | 'searchTerm' => 'Hemelinger', |
||
104 | 'facet_type' => array( |
||
105 | '\StingerSoft\TestBundle\Entity\Test' |
||
106 | ) |
||
107 | ); |
||
108 | |||
109 | // submit the data to the form directly |
||
110 | $form->submit($formData); |
||
111 | |||
112 | $this->assertTrue($form->isSynchronized()); |
||
113 | $this->assertTrue($form->isValid()); |
||
114 | $this->assertEquals($expectedQuery, $form->getData()); |
||
115 | |||
116 | $view = $form->createView(); |
||
117 | $children = $view->children; |
||
118 | |||
119 | foreach(array_keys($formData) as $key) { |
||
120 | $this->assertArrayHasKey($key, $children); |
||
121 | } |
||
122 | |||
123 | $typeForm = $view->offsetGet('facet_type'); |
||
124 | $this->assertEquals(2, $typeForm->count()); |
||
125 | $this->assertContains('\StingerSoft\TestBundle\Entity\Test', $typeForm->vars['value']); |
||
126 | $this->assertCount(2, $typeForm->vars['choices']); |
||
127 | } |
||
128 | |||
143 | } |