Completed
Push — master ( 75a8a0...8053cf )
by Peter
02:57
created

LogResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 36
ccs 0
cts 19
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B logOffset() 0 22 4
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
10
namespace AnimeDb\Bundle\CatalogBundle\Service\Storage\Scan;
11
12
use Symfony\Component\HttpFoundation\JsonResponse;
13
14
class LogResponse extends JsonResponse
15
{
16
    // add option JSON_UNESCAPED_UNICODE
17
    // 271 === JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE
18
    protected $encodingOptions = 271;
19
20
    /**
21
     * @param string $log
22
     * @param int $offset
23
     * @param bool $is_end
24
     *
25
     * @return self
26
     */
27
    public static function logOffset($log, $offset = 0, $is_end = false)
28
    {
29
        if (is_numeric($offset) && $offset > 0) {
30
            $offset_log = (string) mb_substr($log, $offset, mb_strlen($log, 'UTF-8') - $offset, 'UTF-8');
31
32
            try {
33
                return new self([
34
                    'offset' => $offset,
35
                    'content' => $offset_log,
36
                    'end' => $is_end,
37
                ]);
38
            } catch (\Exception $e) {
39
                // use default condition
40
            }
41
        }
42
43
        return new self([
44
            'offset' => 0,
45
            'content' => $log,
46
            'end' => $is_end,
47
        ]);
48
    }
49
}
50