AssociateObject::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 12
cp 0
rs 9.7
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\actions\objects;
10
11
use flipbox\craft\hubspot\fields\ObjectsFieldInterface;
12
use flipbox\craft\integration\actions\objects\AssociateObject as AssociateIntegration;
13
use flipbox\craft\integration\records\IntegrationAssociation;
14
use Psr\Http\Message\ResponseInterface;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class AssociateObject extends AssociateIntegration
21
{
22
    /**
23
     * @inheritdoc
24
     * @param IntegrationAssociation $record
25
     */
26
    protected function validate(
27
        IntegrationAssociation $record
28
    ): bool {
29
30
        $field = $record->getField();
31
32
        if (!$field instanceof ObjectsFieldInterface) {
33
            return false;
34
        }
35
36
        /** @var ResponseInterface $response */
37
        $response = $field->readFromHubSpot(
38
            $record->objectId
39
        );
40
41
        return $response->getStatusCode() >= 200 && $response->getStatusCode() <= 299;
42
    }
43
}
44