Paraphraser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A paraphrase() 0 20 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ReliqArts\Scavenger\Service;
6
7
use GuzzleHttp\Client as GuzzleClient;
8
use Illuminate\Support\Facades\Log;
9
use ReliqArts\Scavenger\Contract\Paraphraser as ParaphraserContract;
10
use Throwable;
11
12
final class Paraphraser implements ParaphraserContract
13
{
14
    /**
15
     * Mapping of resources and url.
16
     *
17
     * @const array
18
     */
19
    private const API_URL = 'http://script4.prothemes.biz/php/process.php';
20
21
    /**
22
     * HTTP Client instance.
23
     */
24
    protected GuzzleClient $client;
25
26
    /**
27
     * Guzzle settings.
28
     *
29
     * @var array
30
     */
31
    private array $guzzleSettings = [
32
        'timeout' => -1,
33
        'defaults' => [
34
            'verify' => false,
35
        ],
36
    ];
37
38
    /**
39
     * Create a new seeker.
40
     */
41
    public function __construct()
42
    {
43
        $this->client = new GuzzleClient($this->guzzleSettings);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function paraphrase(string $text): string
50
    {
51
        try {
52
            $response = $this->client->request(
53
                'POST',
54
                self::API_URL,
55
                [
56
                    'form_params' => [
57
                        'lang' => 'en',
58
                        'data' => $text,
59
                    ],
60
                ]
61
            );
62
63
            return $response->getBody()->getContents();
64
        } catch (Throwable $exception) {
65
            Log::error($exception->getMessage());
66
        }
67
68
        return $text;
69
    }
70
}
71