Completed
Push — master ( 58b9a0...03983a )
by Nazar
12:00 queued 07:10
created

Json_ld::Person()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 9.6666
1
<?php
2
/**
3
 * @package   Json_ld
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
10
namespace cs\modules\Json_ld;
11
use
12
	cs\User;
13
14
/**
15
 * Class generates array with structure, that is necessary for JSON-LD based on CleverStyle Framework-specific data
16
 *
17
 * Methods names are the same as on <http://schema.org/docs/full.html> except some utility methods which have `snake_case` formatting
18
 */
19
class Json_ld {
20
	const SCHEMA_ORG = 'https://schema.org';
21
	/**
22
	 * @param array $data
23
	 *
24
	 * @return string[]
25
	 */
26
	static function context_stub ($data = []) {
27
		$context = [
28
			'@vocab' => self::SCHEMA_ORG.'/'
29
		];
30
		$context += array_combine(
31
			array_keys($data),
32
			array_fill(0, count($data), null)
33
		);
34
		return $context;
35
	}
36
	/**
37
	 * @param int $timestamp
38
	 *
39
	 * @return string
40
	 */
41
	static function Date ($timestamp) {
42
		return date('c', $timestamp);
43
	}
44
	/**
45
	 * @param int $user_id
46
	 *
47
	 * @return string[]
48
	 */
49
	static function Person ($user_id) {
50
		$user_data = new User\Properties($user_id);
51
		return [
52
			'@context' => self::SCHEMA_ORG,
53
			'@type'    => 'Person',
54
			'name'     => $user_data->username(),
55
			'image'    => $user_data->avatar()
56
		];
57
	}
58
}
59