iCalFormat   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 42
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getText() 0 11 1
A unixToiCal() 0 4 1
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\Format;
13
14
/**
15
 * iCal creates a valid iCal format string
16
 *
17
 * @author Antonio Ramirez <[email protected]>
18
 * @link https://www.2amigos.us/
19
 * @package Da\QrCode\Format
20
 */
21
class iCalFormat extends AbstractFormat
22
{
23
    /**
24
     * @var string the event summary
25
     */
26
    public $summary;
27
    /**
28
     * @var integer the unix timestamp of the start date of the event
29
     */
30
    public $startTimestamp;
31
    /**
32
     * @var integer the unix timestamp of the end date of the event
33
     */
34
    public $endTimestamp;
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function getText(): string
40
    {
41
        $data = [];
42
        $data[] = 'BEGIN:VEVENT';
43
        $data[] = "SUMMARY:{$this->summary}";
44
        $data[] = "DTSTART:{$this->unixToiCal($this->startTimestamp)}";
45
        $data[] = "DTEND:{$this->unixToiCal($this->endTimestamp)}";
46
        $data[] = 'END:VEVENT';
47
48
        return implode("\n", $data);
49
    }
50
51
    /**
52
     * Converts a unix timestamp to iCal format. Timezones are assumed to be included into the timestamp.
53
     *
54
     * @param int $value the unix timestamp to convert
55
     *
56
     * @return bool|string the formatted date
57
     */
58
    protected function unixToiCal($value)
59
    {
60
        return date("Ymd\THis\Z", $value);
61
    }
62
}
63