Completed
Push — next ( 145999...7ad3ec )
by Thomas
15s
created

Util   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateIcsStringFromGeoCache() 0 20 2
A generateQrCodeFromString() 0 31 1
1
<?php
2
3
/***************************************************************************
4
 * for license information see LICENSE.md
5
 ***************************************************************************/
6
7
namespace Oc\GeoCache;
8
9
use Eluceo\iCal\Component\Calendar;
10
use Eluceo\iCal\Component\Event;
11
use Endroid\QrCode\ErrorCorrectionLevel;
12
use Endroid\QrCode\LabelAlignment;
13
use Endroid\QrCode\QrCode;
14
use Oc\GeoCache\Persistence\GeoCache\GeoCacheEntity;
15
16
class Util
17
{
18
    public function generateIcsStringFromGeoCache(GeoCacheEntity $geoCache): string
19
    {
20
        if ($geoCache->type !== 6) {
21
            throw new \InvalidArgumentException('the given geoCache is not an event cache!');
22
        }
23
24
        $vCalendar = new Calendar('https://www.opencaching.de/' . $geoCache->wpOc);
25
        $vEvent = new Event();
26
27
        $vEvent
28
            ->setDtStart($geoCache->dateHidden)
29
            ->setDtEnd($geoCache->dateHidden->add(new \DateInterval('PT1H')))
30
            ->setNoTime(true)
31
            ->setSummary($geoCache->name)
32
            ->setDescription('https://www.opencaching.de/viewcache.php?cacheid=' . $geoCache->cacheId);
33
34
        $vCalendar->addComponent($vEvent);
0 ignored issues
show
Documentation introduced by
$vEvent is of type object<Eluceo\iCal\Component\Event>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
36
        return $vCalendar->render();
37
    }
38
39
    public function generateQrCodeFromString(string $qrCodeValue): void
40
    {
41
        $qrCode = new QrCode($qrCodeValue);
42
        $qrCode->setSize(400);
43
44
        $qrCode->setWriterByName('png');
45
        $qrCode->setMargin(10);
46
        $qrCode->setEncoding('UTF-8');
47
        $qrCode->setErrorCorrectionLevel(new ErrorCorrectionLevel(ErrorCorrectionLevel::HIGH));
48
        $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0]);
49
        $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]);
50
        $qrCode->setLabel('www.opencaching.de', 16, null, LabelAlignment::CENTER);
51
        $qrCode->setValidateResult(false);
52
53
        $logo = imagecreatefrompng(__DIR__ . '/../../../theme/frontend/images/logo/qr-code-oc-logo.png');
54
        $qrCodeGenerated = imagecreatefromstring($qrCode->writeString());
55
56
        imagecopy(
57
            $qrCodeGenerated,
58
            $logo,
59
            150,
60
            150,
61
            0,
62
            0,
63
            imagesx($logo),
64
            imagesy($logo)
65
        );
66
67
        imagepng($qrCodeGenerated);
68
        imagedestroy($qrCodeGenerated);
69
    }
70
}
71