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

Missing   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 44
dl 0
loc 106
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
     * Second step fill the form data (dni, address...)
39
     *
40
     * @param bool $rejected
41
     * @throws \Exception
42
     */
43
    public function run($rejected = false)
44
    {
45
        $this->validateStep(self::STEP);
46
47
        /*
48
         * Mandatory DNI:
49
         */
50
        $name = $this->webDriver->findElement(WebDriverBy::name('dni'));
51
        $name->clear()->sendKeys($this->getDNI());
52
53
        /*
54
         * Mandatory BirthDate:
55
         */
56
        $dob = $this->webDriver->findElement(WebDriverBy::name('dob'));
57
        $dob->clear()->sendKeys(
58
            $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

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

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