FoxyIntegrationsExtension::addIntegrations()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 11
c 2
b 0
f 1
dl 0
loc 21
rs 9.9
cc 4
nc 6
nop 1
1
<?php
2
3
namespace Dynamic\Foxy\Integrations\Extension;
4
5
use Dynamic\Foxy\Model\Setting;
6
use GuzzleHttp\Client;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Client was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Psr\Log\LoggerInterface;
8
use SilverStripe\Core\Injector\Injector;
9
use SilverStripe\Core\Extension;
10
11
class FoxyIntegrationsExtension extends Extension
12
{
13
    /**
14
     * @param $FoxyData
15
     * @throws \SilverStripe\ORM\ValidationException
16
     */
17
    public function addIntegrations(&$encryptedData)
18
    {
19
        $config = Setting::current_foxy_setting();
20
21
        if (!$config->Integrations()->exists()) {
22
            Injector::inst()->get(LoggerInterface::class)->debug("No integrations at this time.");
23
        }
24
25
        foreach ($config->Integrations() as $integration) {
26
            // relay Datafeed to each Integration via guzzle
27
            $client = new Client();
28
            $response = $client->request('POST', $integration->URL, [
29
                'form_params' => ['FoxyData' => $encryptedData],
30
            ]);
31
32
            if ($response->getBody() != 'foxy') {
33
                echo '<p>' . $integration->Title . ' failed</p>';
34
            }
35
36
            Injector::inst()->get(LoggerInterface::class)
37
                ->debug($integration->Title . " responded " . $response->getBody());
38
        }
39
    }
40
}
41