GMPEncoder::encode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Riimu\Kit\PHPEncoder\Encoder;
4
5
/**
6
 * Encoder for GMP number types.
7
 * @author Riikka Kalliomäki <[email protected]>
8
 * @copyright Copyright (c) 2014-2020 Riikka Kalliomäki
9
 * @license http://opensource.org/licenses/mit-license.php MIT License
10
 */
11
class GMPEncoder implements Encoder
12
{
13
    public function getDefaultOptions()
14
    {
15
        return [];
16
    }
17
18
    public function supports($value)
19
    {
20
        return \is_object($value) && \get_class($value) === \GMP::class;
21
    }
22
23
    public function encode($value, $depth, array $options, callable $encode)
24
    {
25
        return sprintf('gmp_init(%s)', $encode(gmp_strval($value)));
26
    }
27
}
28