QrCodeAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 38
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 13 3
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/qrcode-library project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\QrCode\Action;
13
14
use Da\QrCode\Component\QrCodeComponent;
15
use Yii;
16
use yii\base\Action;
17
use yii\web\Response;
18
19
class QrCodeAction extends Action
20
{
21
    /**
22
     * @var string the text to render if there are no parameter. Defaults to null, which means the component should
23
     *             render the text given as a parameter.
24
     */
25
    public $text;
26
    /**
27
     * @var string the parameter
28
     */
29
    public $param = 'text';
30
    /**
31
     * @var string whether the URL parameter is passed via GET or POST. Defaults to 'get'.
32
     */
33
    public $method = 'get';
34
    /**
35
     * @var string the qr component name configured on the Yii2 app. The component should have configured all the
36
     *             possible options like adding a logo, styling, labelling, etc.
37
     */
38
    public $component = 'qr';
39
40
    /**
41
     * Runs the action.
42
     */
43
    public function run()
44
    {
45
        $text = call_user_func([Yii::$app->request, $this->method], $this->param, $this->text);
46
47
        $qr = Yii::$app->get($this->component);
48
49
        if ($text && $qr instanceof QrCodeComponent) {
50
            Yii::$app->response->format = Response::FORMAT_RAW;
51
            Yii::$app->response->headers->add('Content-Type', $qr->getContentType());
52
53
            return $qr->setText((string)$text)->writeString();
54
        }
55
    }
56
}
57