Passed
Push — master ( 137960...4d87d9 )
by Sys
11:11
created

Encoder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toJson() 0 6 2
A toYaml() 0 3 1
1
<?php
2
3
namespace TgScraper\Common;
4
5
use Symfony\Component\Yaml\Yaml;
6
7
class Encoder
8
{
9
    /**
10
     * @param mixed $data
11
     * @param int $options
12
     * @param bool $readable
13
     * @return string
14
     */
15
    public static function toJson(mixed $data, int $options = 0, bool $readable = false): string
16
    {
17
        if ($readable) {
18
            $options |= JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
19
        }
20
        return json_encode($data, $options);
21
    }
22
23
    /**
24
     * @param mixed $data
25
     * @param int $inline
26
     * @param int $indent
27
     * @param int $flags
28
     * @return string
29
     */
30
    public static function toYaml(mixed $data, int $inline = 12, int $indent = 4, int $flags = 0): string
31
    {
32
        return Yaml::dump($data, $inline, $indent, $flags);
33
    }
34
}