Completed
Push — master ( 62cb27...c16962 )
by mains
03:25
created

php/Requests/CreateUser.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class CreateUser extends AbstractRequest {
4
    /**
5
     * @var Location
6
     */
7
    private $location;
8
    private $deviceUid;
9
    /**
10
     * @return Location
11
     */
12
    private function getLocation()
13
    {
14
        return $this->location;
15
    }
16
    /**
17
     * @param Location $location
18
     */
19
    public function setLocation(Location $location)
20
    {
21
        $this->location = $location;
22
    }
23
    private function getDeviceUid()
24
    {
25
		return $this->deviceUid;
26
	}
27
	public function setDeviceUid($deviceUid)
28
    {
29
			$this->deviceUid = $deviceUid;
30
	}
31
    private function generateDeviceUid()
32
    {
33
        return $this->random_str(64, 'abcdef0123456789');
34
    }
35
    
36
    private function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
37
    {
38
        $str = '';
39
        $max = mb_strlen($keyspace, '8bit') - 1;
40
        for ($i = 0; $i < $length; ++$i) {
41
            $str .= $keyspace[rand(0, $max)];
42
        }
43
        return $str;
44
    }
45
    public function getApiEndPoint()
46
    {
47
        return '/v2/users';
48
    }
49
    public function getPayload()
50
    {
51
			if(!isset($this->deviceUid))
52
			{
53
				$this->setDeviceUid($this->generateDeviceUid());
54
			}
55
56
			return array(
57
					"location" => $this->getLocation()->toArray(),
58
					"client_id" => self::CLIENTID,
59
					"device_uid" => $this->getDeviceUid(),
60
			);
61
    }
62
    public function getMethod()
63
    {
64
        return 'POST';
65
    }
66
}
0 ignored issues
show
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
67