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

Missing::run()   A

Complexity

Conditions 5
Paths 36

Size

Total Lines 80
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 36
nc 36
nop 1
dl 0
loc 80
rs 9.0328
c 1
b 0
f 0

How to fix   Long Method   

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
         * Mandatory DNI:
50
         */
51
        $name = $this->webDriver->findElement(WebDriverBy::name('dni'));
52
        $name->clear()->sendKeys($this->getDNI());
53
54
        /*
55
         * Mandatory BirthDate:
56
         */
57
        $dob = $this->webDriver->findElement(WebDriverBy::name('dob'));
58
        $dob->clear()->sendKeys(
59
            $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

59
            $this->faker->/** @scrutinizer ignore-call */ 
60
                          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...
60
            $this->faker->numberBetween(1, 12).
61
            '1975'
62
        );
63
64
        /*
65
         * Mandatory address:
66
         */
67
        $name = $this->webDriver->findElement(WebDriverBy::name('address'));
68
        $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...
69
70
        /*
71
         * Optional city:
72
         */
73
        $name = $this->webDriver->findElement(WebDriverBy::name('city'));
74
        $name->clear()->sendKeys($this->faker->city);
75
76
        /*
77
         * Optional zipcode:
78
         */
79
        $name = $this->webDriver->findElement(WebDriverBy::name('zipcode'));
80
        $name->clear()->sendKeys('28045');
81
82
        /*
83
         * Optional Phone:
84
         */
85
        $name = $this->webDriver->findElement(WebDriverBy::name('mobilePhone'));
86
        $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

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