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

Compressor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 28
rs 10
ccs 7
cts 7
cp 1
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A gzip() 0 5 1
A assert() 0 7 3
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