SignInWithTwitter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
3
namespace Magium\Twitter\Actions;
4
5
use Facebook\WebDriver\Exception\NoSuchElementException;
6
use Magium\Twitter\Themes\Twitter;
7
use Magium\Twitter\Identities\Twitter as TwitterIdentity;
8
use Magium\WebDriver\WebDriver;
9
10
class SignInWithTwitter
11
{
12
    const ACTION = 'Magium\Twitter\Actions\SignInWithTwitter';
13
    
14
    protected $webDriver;
15
    protected $theme;
16
    protected $identity;
17
    
18
    public function __construct(
19
        WebDriver $webDriver,
20
        Twitter $theme,
21
        TwitterIdentity $identity
22
    )
23
    {
24
        $this->webDriver    = $webDriver;
25
        $this->theme        = $theme;
26
        $this->identity     = $identity;
27
    }
28
    
29
    public function execute($remember = false)
30
    {
31
        try {
32
            $element = $this->webDriver->byXpath($this->theme->getUsernameXpath());
33
            $element->clear();
34
            $element->sendKeys($this->identity->getUsername());
35
36
            $element = $this->webDriver->byXpath($this->theme->getPasswordXpath());
37
            $element->clear();
38
            $element->sendKeys($this->identity->getPassword());
39
40
            if ($remember) {
41
                $element = $this->webDriver->byXpath($this->theme->getRememberXpath());
42
                $element->click();
43
            }
44
45
        } catch (NoSuchElementException $e) {
46
            // Presuming that we're logged in
47
        }
48
        $element = $this->webDriver->byXpath($this->theme->getSignInXpath());
49
        $element->click();
50
    }
51
52
}