Completed
Pull Request — master (#127)
by Alexandr
04:03
created

NlpRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Request;
6
7
use GuzzleHttp\Psr7\Uri;
8
use Kerox\Messenger\Helper\UtilityTrait;
9
use Psr\Http\Message\RequestInterface;
10
11
class NlpRequest extends AbstractRequest implements QueryRequestInterface
12
{
13
    use UtilityTrait;
14
15
    /**
16
     * @var array
17
     */
18
    protected $configs;
19
20
    /**
21
     * CodeRequest constructor.
22
     *
23
     * @param string $path
24
     * @param array  $configs
25
     */
26 1
    public function __construct(string $path, array $configs)
27
    {
28 1
        parent::__construct($path);
29
30 1
        $this->configs = $configs;
31 1
    }
32
33
    /**
34
     * @param string|null $method
35
     *
36
     * @return RequestInterface
37
     */
38 1
    public function build(?string $method = null): RequestInterface
39
    {
40 1
        $uri = Uri::fromParts([
41 1
            'query' => $this->buildQuery(),
42
        ]);
43
44 1
        return $this->origin
45 1
            ->withMethod('post')
46 1
            ->withUri($uri);
47
    }
48
49
    /**
50
     * @return string
51
     */
52 1
    public function buildQuery(): string
53
    {
54
        $query = [
55 1
            'nlp_enabled' => $this->configs['nlp_enabled'] ?? null,
56 1
            'model' => $this->configs['model'] ?? null,
57 1
            'custom_token' => $this->configs['custom_token'] ?? null,
58 1
            'verbose' => $this->configs['verbose'] ?? null,
59 1
            'n_best' => $this->configs['n_best'] ?? null,
60
        ];
61
62 1
        return http_build_query($this->arrayFilter($query));
63
    }
64
}
65