Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 37 |
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 |
||
107 | public function testWithPages() |
||
108 | { |
||
109 | $client = static::createClient(); |
||
110 | |||
111 | $category = new Category(); |
||
112 | $category |
||
113 | ->setSlug('default') |
||
114 | ->setName('Default Category') |
||
115 | ->setDescription('Hello world!') |
||
116 | ->setEnabled(true) |
||
117 | ; |
||
118 | |||
119 | /** @var EntityManager $em */ |
||
120 | $em = $client->getKernel()->getContainer()->get('doctrine')->getManager(); |
||
121 | $em->persist($category); |
||
122 | $em->flush(); |
||
123 | |||
124 | $page1 = new Page(); |
||
125 | $page1 |
||
126 | ->setEnabled(true) |
||
127 | ->setSlug('home') |
||
128 | ->setTitle('My homepage') |
||
129 | ->setHost('localhost') |
||
130 | ->setContent('Hello world!') |
||
131 | ->setCategory($category) |
||
132 | ; |
||
133 | |||
134 | $page2 = new Page(); |
||
135 | $page2 |
||
136 | ->setEnabled(true) |
||
137 | ->setSlug('about') |
||
138 | ->setTitle('About page') |
||
139 | ->setHost('localhost') |
||
140 | ->setContent('We.are.the.robots.') |
||
141 | ->setCategory($category) |
||
142 | ; |
||
143 | |||
144 | $em->persist($page1); |
||
145 | $em->persist($page2); |
||
146 | $em->flush(); |
||
147 | |||
148 | $crawler = $client->request('GET', '/category/'.$category->getTree()); |
||
149 | |||
150 | $section1 = $crawler->filter('section')->eq(0); |
||
151 | static::assertEquals($page1->getTitle(), trim($section1->filter('article > h2 > a')->html())); |
||
152 | static::assertContains($page1->getContent(), trim($section1->filter('article')->html())); |
||
153 | |||
154 | $section2 = $crawler->filter('section')->eq(1); |
||
155 | static::assertEquals($page2->getTitle(), trim($section2->filter('article > h2 > a')->html())); |
||
156 | static::assertContains($page2->getContent(), trim($section2->filter('article')->html())); |
||
157 | } |
||
158 | } |
||
159 |