Conditions | 2 |
Paths | 2 |
Total Lines | 57 |
Code Lines | 29 |
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 |
||
28 | public function testAdminEmailsDashboardAction() |
||
29 | { |
||
30 | $this->checkApplication(); |
||
31 | |||
32 | // Create a new client to browse the application |
||
33 | $client = static::createClient(); |
||
34 | $client->followRedirects(); |
||
35 | |||
36 | $manager = $this->getEntityManager(); |
||
37 | $sentEmailRep = $manager->getRepository("Azine\EmailBundle\Entity\SentEmail"); |
||
38 | |||
39 | $testSentEmails = $sentEmailRep->search(['recipients' => TestHelper::TEST_EMAIL]); |
||
40 | |||
41 | |||
42 | if (count($testSentEmails) == 0) { |
||
43 | |||
44 | TestHelper::addSentEmails($manager); |
||
45 | } |
||
46 | |||
47 | $listUrl = substr($this->getRouter()->generate("azine_admin_email_dashboard", array('_locale' => "en")), 13); |
||
48 | $crawler = $this->loginUserIfRequired($client, $listUrl); |
||
49 | |||
50 | //click on an email web view link to get to the web page |
||
51 | $link = $crawler->filter(".sentEmail:contains('".EmailTemplateProvider::NEWSLETTER_TEMPLATE."')")->first()->filter("td")->last()->filter("a")->first()->link(); |
||
52 | $crawler = $client->click($link); |
||
53 | |||
54 | $this->assertEquals(1, $crawler->filter("span:contains('_az.email.hello')")->count(), " div with hello message expected."); |
||
55 | |||
56 | $crawler = $this->loginUserIfRequired($client, $listUrl); |
||
57 | |||
58 | //Test filtering by email |
||
59 | $crawler = $crawler->selectButton('sentEmail[save]'); |
||
60 | $form = $crawler->form(); |
||
61 | $form['sentEmail[recipients]'] = TestHelper::TEST_EMAIL; |
||
62 | $crawler = $client->submit($form); |
||
63 | |||
64 | $this->assertEquals($crawler->filter(".sentEmail")->count(), $crawler->filter("tr:contains('".TestHelper::TEST_EMAIL."')")->count(),"Table rows only with ".TestHelper::TEST_EMAIL." email are expected"); |
||
65 | |||
66 | |||
67 | //click on email details view link to get to the details page |
||
68 | $link = $crawler->filter(".sentEmail:contains('".TestHelper::TEST_EMAIL."')")->first()->filter("td")->last()->filter("a")->last()->link(); |
||
69 | $crawler = $client->click($link); |
||
70 | |||
71 | $this->assertEquals(1, $crawler->filter("tr:contains('".TestHelper::TEST_EMAIL."')")->count(),"Table cell with ".TestHelper::TEST_EMAIL." expected"); |
||
72 | |||
73 | $crawler = $this->loginUserIfRequired($client, $listUrl); |
||
|
|||
74 | |||
75 | $form['sentEmail[recipients]'] = ''; |
||
76 | $crawler = $client->submit($form); |
||
77 | |||
78 | //Test filtering by token |
||
79 | $form['sentEmail[token]'] = TestHelper::TEST_TOKEN; |
||
80 | $crawler = $client->submit($form); |
||
81 | |||
82 | $this->assertEquals($crawler->filter(".sentEmail")->count(), $crawler->filter(".sentEmail:contains('".TestHelper::TEST_TOKEN."')")->count(),"Table row only with ".TestHelper::TEST_TOKEN." token is expected"); |
||
83 | |||
84 | } |
||
85 | |||
178 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.