Passed
Push — master ( 289cbe...3ce129 )
by Anton
03:29
created

SEO::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @package Cadmium\System\Utils
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Utils {
11
12
	use Dataset;
13
14
	abstract class SEO {
15
16
		private static $dataset = null;
17
18
		/**
19
		 * Initialize the SEO data
20
		 */
21
22
		public static function init() {
23
24
			self::$dataset = new Dataset(['title' => '', 'description' => '', 'keywords' => '',
25
26
				'robots_index' => false, 'robots_follow' => false, 'canonical' => '']);
27
		}
28
29
		/**
30
		 * Set a param value
31
		 *
32
		 * @return bool : true on success or false on error
33
		 */
34
35
		public static function set(string $name, $value) : bool {
36
37
			if (null === self::$dataset) self::init();
38
39
			return (self::$dataset->set($name, $value) ?? false);
40
		}
41
42
		/**
43
		 * Get a param value
44
		 *
45
		 * @return mixed|false : the value or false if the param does not exist
46
		 */
47
48
		public static function get(string $name) {
49
50
			if (null === self::$dataset) self::init();
51
52
			return (self::$dataset->get($name) ?? false);
53
		}
54
55
		/**
56
		 * Get a robots string
57
		 */
58
59
		public static function getRobots() {
60
61
			if (null === self::$dataset) self::init();
62
63
			return ((self::get('robots_index') ? 'INDEX' : 'NOINDEX') . ',' . (self::get('robots_follow') ? 'FOLLOW' : 'NOFOLLOW'));
64
		}
65
	}
66
}
67