Completed
Pull Request — development (#692)
by Thomas
06:40
created

QrCodeController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B getReportsAction() 0 27 2
1
<?php
2
3
namespace Oc\GeoCache\Controller;
4
5
use Endroid\QrCode\ErrorCorrectionLevel;
6
use Endroid\QrCode\LabelAlignment;
7
use Endroid\QrCode\QrCode;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
13
class QrCodeController extends Controller
14
{
15
    /**
16
     * @param Request $request
17
     * @return Response
18
     * @Route("/api/geocache/qrCodes")
19
     */
20
    public function getReportsAction(Request $request)
21
    {
22
        $wp = $request->get('wp');
23
24
        if (preg_match('/(OC|GC)[A-Za-z0-9]{1,5}/', $wp) !== 1) {
25
            die('the waypoint is not valid!');
0 ignored issues
show
Coding Style Compatibility introduced by
The method getReportsAction() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
26
        }
27
28
        $qrCode = new QrCode('https://www.opencaching.de/' . $wp);
29
        $qrCode->setSize(300);
30
31
        $qrCode
32
            ->setWriterByName('png')
33
            ->setMargin(10)
34
            ->setEncoding('UTF-8')
35
            ->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH)
36
            ->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0])
37
            ->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255])
38
            ->setLabel('www.opencaching.de', 16, null, LabelAlignment::CENTER)
39
            ->setLogoPath(__DIR__ . '/../../../../theme/img/logo/oc-logo.png')
40
            ->setLogoWidth(250)
41
            ->setValidateResult(false);
42
43
        return new Response(
44
            $qrCode->writeString(), Response::HTTP_OK, ['Content-Type' => $qrCode->getContentType()]
45
        );
46
    }
47
}
48