Completed
Push — master ( 7a405c...245614 )
by Ben
02:22
created

StringUtils::encodeString()   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
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * BaconPdf
4
 *
5
 * @link      http://github.com/Bacon/BaconPdf For the canonical source repository
6
 * @copyright 2015 Ben Scholzen (DASPRiD)
7
 * @license   http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
8
 */
9
10
namespace Bacon\Pdf\Utils;
11
12
use DateTimeInterface;
13
14
final class StringUtils
15
{
16
    public function __construct()
17
    {
18
    }
19
20
    /**
21
     * Encodes a string according to section 3.8.1.
22
     *
23
     * @param  string $string
24
     * @return string
25
     */
26
    public static function encodeString($string)
27
    {
28
        return "\xfe\xff" . iconv('UTF-8', 'UTF-16BE', $string);
29
    }
30
31
    /**
32
     * Formats a date according to section 3.8.3.
33
     *
34
     * @param  DateTimeInterface $dateTime
35
     * @return string
36
     */
37
    public static function formatDateTime(DateTimeInterface $dateTime)
38
    {
39
        $timeString = $dateTime->format('\D\:YmdHis');
40
41
        if (0 === $dateTime->getTimezone()->getOffset()) {
42
            return $timeString . 'Z';
43
        }
44
45
        return $timeString . strtr(':', "'", $dateTime->format('P')) . "'";
46
    }
47
}
48