Completed
Push — master ( 0e1017...87dcd8 )
by Nazar
04:21
created

Social_integration::set_contacts()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 30
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 2
nop 3
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package   HybridAuth
4
 * @category  modules
5
 * @author    Nazar Mokrynskyi <[email protected]>
6
 * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
7
 * @license   MIT License, see license.txt
8
 */
9
namespace cs\modules\HybridAuth;
10
use
11
	cs\Config,
12
	cs\DB\Accessor,
13
	cs\Singleton;
14
15
/**
16
 * @method static $this instance($check = false)
17
 */
18
class Social_integration {
19
	use
20
		Accessor,
21
		Singleton;
22
	protected function cdb () {
23
		return Config::instance()->module('HybridAuth')->db('integration');
24
	}
25
	/**
26
	 * Add social integration
27
	 *
28
	 * @param int    $user_id
29
	 * @param string $provider
30
	 * @param string $identifier
31
	 * @param string $profile
32
	 *
33
	 * @return false|int|string
0 ignored issues
show
Documentation introduced by
Should the return type not be false|object|resource?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
34
	 */
35
	function add ($user_id, $provider, $identifier, $profile) {
36
		return $this->db_prime()->q(
37
			"REPLACE INTO `[prefix]users_social_integration`
38
				(
39
					`id`,
40
					`provider`,
41
					`identifier`,
42
					`profile`
43
				) VALUES (
44
					'%s',
45
					'%s',
46
					'%s',
47
					'%s'
48
				)",
49
			$user_id,
50
			$provider,
51
			$identifier,
52
			$profile
53
		);
54
	}
55
	/**
56
	 * Find user id by provider name and identifier
57
	 *
58
	 * @param string $provider
59
	 * @param string $identifier
60
	 *
61
	 * @return false|int User id or `false` if not found
62
	 */
63
	function find_integration ($provider, $identifier) {
64
		return $this->db()->qfs(
65
			"SELECT `id`
66
			FROM `[prefix]users_social_integration`
67
			WHERE
68
				`provider`		= '%s' AND
69
				`identifier`	= '%s'
70
			LIMIT 1",
71
			$provider,
72
			$identifier
73
		);
74
	}
75
}
76