Passed
Push — master ( a69298...5e6f16 )
by Zoilo
02:01
created

Compressor::gzip()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Helper;
4
5
final class Compressor
6
{
7
    /**
8
     * @param mixed $data
9
     *
10
     * @return string
11
     *
12
     * @throws \Exception
13
     */
14 2
    public static function gzip($data)
15
    {
16 2
        self::assert($data);
17
18 1
        return gzencode($data, -1, FORCE_GZIP);
19
    }
20
21
    /**
22
     * @param mixed $data
23
     *
24
     * @throws \Exception
25
     */
26 2
    private static function assert($data)
27
    {
28 2
        if (true === is_string($data) && 0 !== strlen($data)) {
29 1
            return;
30
        }
31
32 1
        throw new \Exception('Data is not valid. It must be of type string and contain at least one character.');
33
    }
34
}
35