Completed
Push — master ( 6d849d...f9dc97 )
by Michal
02:55 queued 57s
created

DevelopersTable::saveFromGithub()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 9
cts 10
cp 0.9
rs 9.4285
cc 3
eloc 9
nc 4
nop 3
crap 3.009
1
<?php
2
3
/* vim: set expandtab sw=4 ts=4 sts=4: */
4
/**
5
 * A developer who has access to the system.
6
 *
7
 * phpMyAdmin Error reporting server
8
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
9
 *
10
 * Licensed under The MIT License
11
 * For full copyright and license information, please see the LICENSE.txt
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright     Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
15
 * @license       https://opensource.org/licenses/mit-license.php MIT License
16
 *
17
 * @see          https://www.phpmyadmin.net/
18
 */
19
20
namespace App\Model\Table;
21
22
use Cake\ORM\Table;
23
24
/**
25
 * A developer who has access to the system.
26
 */
27
class DevelopersTable extends Table
28
{
29
    /**
30
     * creates a developer record given his github info and his access token.
31
     *
32
     * @param array  $githubInfo  the data gitub has on this developer
33
     * @param string $accessToken this developer's access token
34
     * @param mixed  $developer
35
     *
36
     * @return bool true if the developer was correctly saved otherwise false
37
     */
38 2
    public function saveFromGithub($githubInfo, $accessToken, $developer)
39
    {
40 2
        $developer->full_name = $githubInfo['name'];
41 2
        $developer->gravatar_id = $githubInfo['gravatar_id'];
42 2
        $developer->email = $githubInfo['email'];
43 2
        $developer->github_id = $githubInfo['id'];
44 2
        $developer->access_token = $accessToken;
45 2
        $developer->has_commit_access = $githubInfo['has_commit_access'] ? 1 : 0;
46 2
        if ($this->save($developer)) {
47 2
            return $developer->id;
48
        }
49
    }
50
}
51