Passed
Pull Request — master (#7)
by Raúl
01:30
created

Missing   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 44
dl 0
loc 105
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDNI() 0 10 1
A run() 0 78 5
1
<?php
2
3
namespace Pagantis\SeleniumFormUtils\Step;
4
5
use Facebook\WebDriver\WebDriverBy;
6
use Facebook\WebDriver\WebDriverSelect;
7
use Faker\Factory;
8
use Pagantis\SeleniumFormUtils\SeleniumHelper;
9
use Pagantis\SeleniumFormUtils\Step\AbstractStep;
10
11
/**
12
 * Class Missing
13
 * @package Pagantis\SeleniumFormUtils\Step\Result\Status
14
 */
15
class Missing extends AbstractStep
16
{
17
    /**
18
     * Handler step
19
     */
20
    const STEP = 'Missing';
21
22
    /**
23
     * @return string
24
     */
25
    protected function getDNI()
26
    {
27
        $dni = '0000' . rand(pow(10, 4-1), pow(10, 4)-1);
28
        $value = (int) ($dni / 23);
29
        $value *= 23;
30
        $value= $dni - $value;
31
        $letter= "TRWAGMYFPDXBNJZSQVHLCKEO";
32
        $dniLetter= substr($letter, $value, 1);
33
34
        return $dni.$dniLetter;
35
    }
36
37
    /**
38
     * Pass from confirm-data to next step in Application Form
39
     *
40
     * @throws \Exception
41
     */
42
    public function run()
43
    {
44
        $this->validateStep(self::STEP);
45
46
        /*
47
         * Mandatory DNI:
48
         */
49
        $name = $this->webDriver->findElement(WebDriverBy::name('dni'));
50
        $name->clear()->sendKeys($this->getDNI());
51
52
        /*
53
         * Mandatory BirthDate:
54
         */
55
        $dob = $this->webDriver->findElement(WebDriverBy::name('dob'));
56
        $dob->clear()->sendKeys(
57
            $this->faker->numberBetween(1, 28).
0 ignored issues
show
Bug introduced by
The method numberBetween() does not exist on Faker\Factory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
            $this->faker->/** @scrutinizer ignore-call */ 
58
                          numberBetween(1, 28).

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
            $this->faker->numberBetween(1, 12).
59
            '1975'
60
        );
61
62
        /*
63
         * Mandatory address:
64
         */
65
        $name = $this->webDriver->findElement(WebDriverBy::name('address'));
66
        $name->clear()->sendKeys($this->faker->address. ' ' . $this->faker->city);
0 ignored issues
show
Bug introduced by
The property city does not seem to exist on Faker\Factory.
Loading history...
Bug introduced by
The property address does not seem to exist on Faker\Factory.
Loading history...
67
68
        /*
69
         * Optional city:
70
         */
71
        $name = $this->webDriver->findElement(WebDriverBy::name('city'));
72
        $name->clear()->sendKeys($this->faker->city);
73
74
        /*
75
         * Optional zipcode:
76
         */
77
        $name = $this->webDriver->findElement(WebDriverBy::name('zipcode'));
78
        $name->clear()->sendKeys('28045');
79
80
        /*
81
         * Optional Phone:
82
         */
83
        $name = $this->webDriver->findElement(WebDriverBy::name('mobilePhone'));
84
        $name->clear()->sendKeys('6' . $this->faker->randomNumber(8));
0 ignored issues
show
Bug introduced by
The method randomNumber() does not exist on Faker\Factory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
        $name->clear()->sendKeys('6' . $this->faker->/** @scrutinizer ignore-call */ randomNumber(8));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
86
        /*
87
         * Optional Full Name:
88
         */
89
        try {
90
            $name = $this->webDriver->findElement(WebDriverBy::name('name'));
91
            $name->clear()->sendKeys(
92
                $this->faker->firstName . ' ' . $this->faker->lastName
0 ignored issues
show
Bug introduced by
The property lastName does not seem to exist on Faker\Factory.
Loading history...
Bug introduced by
The property firstName does not seem to exist on Faker\Factory.
Loading history...
93
            );
94
        } catch (\Exception $exception) {
95
            unset($exception);
96
        }
97
98
        /*
99
         * Optional password:
100
         */
101
        try {
102
            $name = $this->webDriver->findElement(WebDriverBy::name('password'));
103
            if (null === SeleniumHelper::$mobilePhone) {
0 ignored issues
show
introduced by
The condition null === Pagantis\Seleni...niumHelper::mobilePhone is always false.
Loading history...
104
                throw new \Exception('Please provide mobile phone for returning customer');
105
            } else {
106
                $name->clear()->sendKeys(substr(SeleniumHelper::$mobilePhone, -4));
107
            }
108
        } catch (\Exception $exception) {
109
            unset($exception);
110
        }
111
112
        /*
113
         * Click form continue
114
         */
115
        try {
116
            $formContinue = $this->webDriver->findElement(WebDriverBy::name('continue_button'));
117
            $formContinue->click();
118
        } catch (\Exception $exception) {
119
            unset($exception);
120
        }
121
    }
122
}
123