Passed
Push — v2.0 ( 6f66e6...442862 )
by Raza
01:59
created

JsonEncodeDecodeSelector   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 7
c 1
b 0
f 0
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonEncodeFunction() 0 5 3
A jsonDecodeFunction() 0 5 3
1
<?php
2
3
namespace Srmklive\PayPal\Traits;
4
5
trait JsonEncodeDecodeSelector
6
{
7
    /**
8
     * Decide the function to use for decoding json.
9
     *
10
     * @return string
11
     */
12
    protected function jsonEncodeFunction(): string
13
    {
14
        return class_exists(\GuzzleHttp\Utils::class) &&
15
        method_exists(\GuzzleHttp\Utils::class, 'jsonEncode') ?
16
            '\GuzzleHttp\Utils::jsonEncode' : '\GuzzleHttp\json_encode';
17
    }
18
19
    /**
20
     * Decide the function to use for decoding json.
21
     *
22
     * @return string
23
     */
24
    protected function jsonDecodeFunction(): string
25
    {
26
        return class_exists(\GuzzleHttp\Utils::class) &&
27
        method_exists(\GuzzleHttp\Utils::class, 'jsonDecode') ?
28
            '\GuzzleHttp\Utils::jsonDecode' : '\GuzzleHttp\json_decode';
29
    }
30
}
31