Passed
Pull Request — master (#58)
by Nic
01:52
created

FoxyDataTestController::foxytestdata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Dynamic\Foxy\Orders\Tests\TestOnly\Controller;
4
5
use Dynamic\Foxy\Orders\Tests\Factory\OrderFactoryTest;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\Control\HTTPResponse;
9
use SilverStripe\Dev\TestOnly;
10
use SilverStripe\ORM\ArrayList;
11
use SilverStripe\Security\PasswordEncryptor;
12
use SilverStripe\Security\PasswordEncryptor_NotFoundException;
13
use SilverStripe\View\ArrayData;
14
15
/**
16
 * Class FoxyDataTestController
17
 * @package Dynamic\Foxy\Orders\Tests\TestOnly\Controller
18
 */
19
class FoxyDataTestController extends Controller implements TestOnly
20
{
21
    /**
22
     * @var string[]
23
     */
24
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
25
        'foxytestdata',
26
    ];
27
28
    /**
29
     * @param null $action
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $action is correct as it would always require null to be passed?
Loading history...
30
     * @return string|null
31
     */
32
    public function Link($action = null)
33
    {
34
        return '/foxytestdata';
35
    }
36
37
    /**
38
     * @param HTTPRequest $request
39
     * @return HTTPResponse
40
     * @throws PasswordEncryptor_NotFoundException
41
     */
42
    public function index(HTTPRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

42
    public function index(/** @scrutinizer ignore-unused */ HTTPRequest $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44
        return HTTPResponse::create()
45
            ->setBody($this->getTransactionData());
46
    }
47
48
    /**
49
     * @param HTTPRequest $request
50
     * @return HTTPResponse
51
     * @throws PasswordEncryptor_NotFoundException
52
     */
53
    public function foxytestdata(HTTPRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

53
    public function foxytestdata(/** @scrutinizer ignore-unused */ HTTPRequest $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        return HTTPResponse::create()
56
            ->setBody($this->getTransactionData());
57
    }
58
59
    /**
60
     * @return string
61
     * @throws PasswordEncryptor_NotFoundException
62
     */
63
    protected function getTransactionData()
64
    {
65
        return urlencode(\rc4crypt::encrypt(OrderFactoryTest::DUMMY_KEY, $this->getXML()));
66
    }
67
68
    /**
69
     * @return string
70
     * @throws PasswordEncryptor_NotFoundException
71
     */
72
    protected function getXML()
73
    {
74
        $xml = Controller::singleton()->renderWith(
75
            'TestData',
76
            [
77
                'OrderID' => 111111222222333333,
78
                'TransactionDate' => strtotime('now'),
79
                'Email' => '[email protected]',
80
                'HashType' => 'sha1_salted_suffix',
81
                'Salt' => 'faGgWXUTdZ7i42lpA6cljzKeGBeUwShBSNHECwsJmt',
82
                'HashedPassword' => PasswordEncryptor::create_for_algorithm('sha1_v2.4')
83
                    ->encrypt('MyF00p@$$w0Rd', 'faGgWXUTdZ7i42lpA6cljzKeGBeUwShBSNHECwsJmt'),
84
                'OrderDetails' => $this->getOrderDetails(),
85
            ]
86
        )->getValue();
87
88
        return <<<XML
89
{$xml}
90
XML;
91
    }
92
93
    /**
94
     * @return ArrayList
95
     */
96
    protected function getOrderDetails()
97
    {
98
        return ArrayList::create([
99
            ArrayData::create([
100
                'Options' => $this->getOptions(),
101
            ]),
102
        ]);
103
    }
104
105
    /**
106
     * @return ArrayList
107
     */
108
    protected function getOptions()
109
    {
110
        return ArrayList::create();
111
    }
112
}
113