Completed
Push — master ( ee2c1a...5e9622 )
by Raúl
14s queued 11s
created

Missing::run()   F

Complexity

Conditions 11
Paths > 20000

Size

Total Lines 98
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 11
eloc 54
c 2
b 0
f 0
nc 26244
nop 1
dl 0
loc 98
rs 3.5236

How to fix   Long Method    Complexity   

Long Method

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:

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
     * @return bool
42
     * @throws \Exception
43
     */
44
    public function run($rejected = false)
45
    {
46
        $this->validateStep(self::STEP);
47
48
        /*
49
         * Field DNI:
50
         */
51
        try {
52
            $name = $this->webDriver->findElement(WebDriverBy::name('dni'));
53
            $name->clear()->sendKeys($this->getDNI());
54
        } catch (\Exception $exception) {
55
            unset($exception);
56
        }
57
        /*
58
         * Field BirthDate:
59
         */
60
        try {
61
            $dob = $this->webDriver->findElement(WebDriverBy::name('dob'));
62
            $dob->clear()->sendKeys(
63
                $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

63
                $this->faker->/** @scrutinizer ignore-call */ 
64
                              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...
64
                $this->faker->numberBetween(1, 12).
65
                '1975'
66
            );
67
        } catch (\Exception $exception) {
68
            unset($exception);
69
        }
70
        /*
71
         * Field address:
72
         */
73
        try {
74
            $name = $this->webDriver->findElement(WebDriverBy::name('address'));
75
            $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...
76
        } catch (\Exception $exception) {
77
            unset($exception);
78
        }
79
        /*
80
         * Field city:
81
         */
82
        try {
83
            $name = $this->webDriver->findElement(WebDriverBy::name('city'));
84
            $name->clear()->sendKeys($this->faker->city);
85
        } catch (\Exception $exception) {
86
            unset($exception);
87
        }
88
        /*
89
         * Field zipcode:
90
         */
91
        try {
92
            $name = $this->webDriver->findElement(WebDriverBy::name('zipcode'));
93
            $name->clear()->sendKeys('28045');
94
        } catch (\Exception $exception) {
95
            unset($exception);
96
        }
97
        /*
98
         * Field Phone:
99
         */
100
        try {
101
            $name = $this->webDriver->findElement(WebDriverBy::name('mobilePhone'));
102
            $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

102
            $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...
103
        } catch (\Exception $exception) {
104
            unset($exception);
105
        }
106
        /*
107
         * Field Full Name:
108
         */
109
        try {
110
            $name = $this->webDriver->findElement(WebDriverBy::name('name'));
111
            $name->clear()->sendKeys(
112
                $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...
113
            );
114
        } catch (\Exception $exception) {
115
            unset($exception);
116
        }
117
118
        /*
119
         * Field password:
120
         */
121
        try {
122
            $name = $this->webDriver->findElement(WebDriverBy::name('password'));
123
            if (null === SeleniumHelper::$mobilePhone) {
0 ignored issues
show
introduced by
The condition null === Pagantis\Seleni...niumHelper::mobilePhone is always false.
Loading history...
124
                throw new \Exception('Please provide mobile phone for returning customer');
125
            } else {
126
                $name->clear()->sendKeys(substr(SeleniumHelper::$mobilePhone, -4));
127
            }
128
        } catch (\Exception $exception) {
129
            unset($exception);
130
        }
131
132
        /*
133
         * Click form continue
134
         */
135
        try {
136
            $formContinue = $this->webDriver->findElement(WebDriverBy::name('continue_button'));
137
            $formContinue->click();
138
        } catch (\Exception $exception) {
139
            unset($exception);
140
        }
141
        return true;
142
    }
143
}
144