Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
7 / 7
SingleOptin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
7 / 7
 setStatus
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
7 / 7
1<?php
2
3namespace LDC\LDCCRM\Models;
4
5use LDC\LDCCRM\Enums\ApiStatus;
6use LDC\LDCCRM\Utils;
7
8/**
9 * This class allows to handle single opt in
10 *
11 * @category Api Models
12 * @package LDCCrmClient
13 * @subpackage models
14 * @author Jérémy Munsch <jeremy.munsch@ldc.fr>
15 */
16abstract class SingleOptin extends CrmClientModel
17{
18    /**
19     * Validation rules
20     *
21     * @var array
22     */
23    protected static $validation = [
24        'email' => 'required|email',
25        'opt_in' => 'required|bool',
26    ];
27
28    /**
29     * Set the single opt in status for an email
30     *
31     * @param string  $email
32     * @param boolean $opt_in
33     * @return boolean true if succeeded
34     * @throws \LDC\LDCCRM\Exceptions\ValidationException If a field email could not be validated.
35     * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response.
36     * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs.
37     * Possibles are : - singleOptinCustomerExists, If a customer exists with this email.
38     * @phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
39     */
40    public static function setStatus(string $email, bool $opt_in): bool
41    {
42        self::validateValue('email', $email);
43        static::setUpApiInterface();
44        $request = Utils::getResquest('apiV2.optin', [], [
45            'email' => $email,
46            'opt_in' => $opt_in
47        ]);
48
49        $response = static::$apiInterface->call($request);
50        return $response->status->equals(ApiStatus::OK());
51    }
52}