AccessToken::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the slince/shopify-api-php
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Slince\Shopify;
13
14
use Slince\Shopify\Exception\InvalidArgumentException;
15
16
class AccessToken
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $token;
22
23
    public function __construct($token)
24
    {
25
        if (0 === preg_match('/^([a-zA-Z0-9_]{10,100})$/', $token)) {
26
            throw new InvalidArgumentException('Access token should be between 10 and 100 letters and numbers');
27
        }
28
        $this->token = $token;
29
    }
30
31
    /**
32
     * Transform the token to string.
33
     *
34
     * @return string
35
     */
36
    public function __toString()
37
    {
38
        return $this->token;
39
    }
40
}
41