Completed
Push — allow-no-default-tax-zone-in-c... ( 67cea0 )
by Kamil
06:23
created

IndexPage::getField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Behat\Page\Admin\Shipment;
15
16
use Behat\Mink\Element\NodeElement;
17
use Sylius\Behat\Page\Admin\Crud\IndexPage as BaseIndexPage;
18
19
class IndexPage extends BaseIndexPage implements IndexPageInterface
20
{
21
    public function chooseStateToFilter(string $shipmentState): void
22
    {
23
        $this->getElement('filter_state')->selectOption($shipmentState);
24
    }
25
26
    public function shipShipmentOfOrderWithNumber(string $orderNumber): void
27
    {
28
        $this->getField($orderNumber, 'actions')->pressButton('Ship');
29
    }
30
31
    public function getShipmentStatusByOrderNumber(string $orderNumber): string
32
    {
33
        return $this->getField($orderNumber, 'state')->getText();
34
    }
35
36
    private function getField(string $orderNumber, string $fieldName): NodeElement
37
    {
38
        $tableAccessor = $this->getTableAccessor();
39
        $table = $this->getElement('table');
40
41
        $row = $tableAccessor->getRowWithFields($table, ['number' => $orderNumber]);
42
43
        return $field = $tableAccessor->getFieldFromRow($table, $row, $fieldName);
0 ignored issues
show
Unused Code introduced by
$field is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
    }
45
46
    public function showOrderPageForNthShipment(int $shipmentNumber): void
47
    {
48
        $this->getActionsForRow($shipmentNumber)->clickLink('Show order details');
49
    }
50
51
    protected function getDefinedElements(): array
52
    {
53
        return array_merge(parent::getDefinedElements(), [
54
            'filter_state' => '#criteria_state',
55
        ]);
56
    }
57
58
    private function getActionsForRow(int $shipmentNumber): NodeElement
59
    {
60
        $tableAccessor = $this->getTableAccessor();
61
        $table = $this->getElement('table');
62
63
        $row = $tableAccessor->getRowsWithFields($table, [])[$shipmentNumber];
64
65
        return $field = $tableAccessor->getFieldFromRow($table, $row, 'actions');
0 ignored issues
show
Unused Code introduced by
$field is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
66
    }
67
}
68