Passed
Push — master ( dc29a0...a908a1 )
by Alain
02:23
created
src/ConfigSchema.php 1 patch
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Generic Config Schema Class.
4
- *
5
- * @package   BrightNucleus\Config
6
- * @author    Alain Schlesser <[email protected]>
7
- * @license   GPL-2.0+
8
- * @link      http://www.brightnucleus.com/
9
- * @copyright 2016 Alain Schlesser, Bright Nucleus
10
- */
3
+	 * Generic Config Schema Class.
4
+	 *
5
+	 * @package   BrightNucleus\Config
6
+	 * @author    Alain Schlesser <[email protected]>
7
+	 * @license   GPL-2.0+
8
+	 * @link      http://www.brightnucleus.com/
9
+	 * @copyright 2016 Alain Schlesser, Bright Nucleus
10
+	 */
11 11
 
12 12
 namespace BrightNucleus\Config;
13 13
 
@@ -25,131 +25,131 @@  discard block
 block discarded – undo
25 25
 class ConfigSchema extends AbstractConfigSchema
26 26
 {
27 27
 
28
-    /**
29
-     * The key that is used in the schema to define a required value.
30
-     */
31
-    const REQUIRED_KEY = 'required';
32
-
33
-    /**
34
-     * The key that is used in the schema to define a default value.
35
-     */
36
-    const DEFAULT_VALUE = 'default';
37
-
38
-    /**
39
-     * The list of values that are recognized as true in the schema.
40
-     */
41
-    const TRUTHY_VALUES = [
42
-        true,
43
-        1,
44
-        'true',
45
-        'True',
46
-        'TRUE',
47
-        'y',
48
-        'Y',
49
-        'yes',
50
-        'Yes',
51
-        'YES',
52
-        '√',
53
-    ];
54
-
55
-    /**
56
-     * Instantiate a ConfigSchema object.
57
-     *
58
-     * @since 0.1.0
59
-     *
60
-     * @param ConfigInterface|array $schema The schema to parse.
61
-     * @throws InvalidArgumentException
62
-     */
63
-    public function __construct($schema)
64
-    {
65
-        if ($schema instanceof ConfigInterface) {
66
-            $schema = $schema->getArrayCopy();
67
-        }
68
-
69
-        if ( ! is_array($schema)) {
70
-            throw new InvalidArgumentException(sprintf(
71
-                _('Invalid schema source: %1$s'),
72
-                print_r($schema, true)
73
-            ));
74
-        }
75
-
76
-        array_walk($schema, [$this, 'parseSchema']);
77
-    }
78
-
79
-    /**
80
-     * Parse a single provided schema entry.
81
-     *
82
-     * @since 0.1.0
83
-     *
84
-     * @param mixed  $data The data associated with the key.
85
-     * @param string $key  The key of the schema data.
86
-     */
87
-    protected function parseSchema($data, $key)
88
-    {
89
-        $this->parseDefined($key);
90
-
91
-        if (array_key_exists(self::REQUIRED_KEY, $data)) {
92
-            $this->parseRequired($key,
93
-                $data[self::REQUIRED_KEY]);
94
-        }
95
-
96
-        if (array_key_exists(self::DEFAULT_VALUE, $data)) {
97
-            $this->parseDefault($key,
98
-                $data[self::DEFAULT_VALUE]);
99
-        }
100
-    }
101
-
102
-    /**
103
-     * Parse the set of defined values.
104
-     *
105
-     * @since 0.1.0
106
-     *
107
-     * @param string $key The key of the schema data.
108
-     */
109
-    protected function parseDefined($key)
110
-    {
111
-        $this->defined[] = $key;
112
-    }
113
-
114
-    /**
115
-     * Parse the set of required values.
116
-     *
117
-     * @since 0.1.0
118
-     *
119
-     * @param string $key  The key of the schema data.
120
-     * @param mixed  $data The data associated with the key.
121
-     */
122
-    protected function parseRequired($key, $data)
123
-    {
124
-        if ($this->isTruthy($data)) {
125
-            $this->required[] = $key;
126
-        }
127
-    }
128
-
129
-    /**
130
-     * Parse the set of default values.
131
-     *
132
-     * @since 0.1.0
133
-     *
134
-     * @param string $key  The key of the schema data.
135
-     * @param mixed  $data The data associated with the key.
136
-     */
137
-    protected function parseDefault($key, $data)
138
-    {
139
-        $this->defaults[$key] = $data;
140
-    }
141
-
142
-    /**
143
-     * Return a boolean true or false for an arbitrary set of data. Recognizes
144
-     * several different string values that should be valued as true.
145
-     *
146
-     * @since 0.1.0
147
-     *
148
-     * @param mixed $data The data to evaluate.
149
-     * @return bool
150
-     */
151
-    protected function isTruthy($data)
152
-    {
153
-        return in_array($data, self::TRUTHY_VALUES, true);
154
-    }
28
+	/**
29
+	 * The key that is used in the schema to define a required value.
30
+	 */
31
+	const REQUIRED_KEY = 'required';
32
+
33
+	/**
34
+	 * The key that is used in the schema to define a default value.
35
+	 */
36
+	const DEFAULT_VALUE = 'default';
37
+
38
+	/**
39
+	 * The list of values that are recognized as true in the schema.
40
+	 */
41
+	const TRUTHY_VALUES = [
42
+		true,
43
+		1,
44
+		'true',
45
+		'True',
46
+		'TRUE',
47
+		'y',
48
+		'Y',
49
+		'yes',
50
+		'Yes',
51
+		'YES',
52
+		'√',
53
+	];
54
+
55
+	/**
56
+	 * Instantiate a ConfigSchema object.
57
+	 *
58
+	 * @since 0.1.0
59
+	 *
60
+	 * @param ConfigInterface|array $schema The schema to parse.
61
+	 * @throws InvalidArgumentException
62
+	 */
63
+	public function __construct($schema)
64
+	{
65
+		if ($schema instanceof ConfigInterface) {
66
+			$schema = $schema->getArrayCopy();
67
+		}
68
+
69
+		if ( ! is_array($schema)) {
70
+			throw new InvalidArgumentException(sprintf(
71
+				_('Invalid schema source: %1$s'),
72
+				print_r($schema, true)
73
+			));
74
+		}
75
+
76
+		array_walk($schema, [$this, 'parseSchema']);
77
+	}
78
+
79
+	/**
80
+	 * Parse a single provided schema entry.
81
+	 *
82
+	 * @since 0.1.0
83
+	 *
84
+	 * @param mixed  $data The data associated with the key.
85
+	 * @param string $key  The key of the schema data.
86
+	 */
87
+	protected function parseSchema($data, $key)
88
+	{
89
+		$this->parseDefined($key);
90
+
91
+		if (array_key_exists(self::REQUIRED_KEY, $data)) {
92
+			$this->parseRequired($key,
93
+				$data[self::REQUIRED_KEY]);
94
+		}
95
+
96
+		if (array_key_exists(self::DEFAULT_VALUE, $data)) {
97
+			$this->parseDefault($key,
98
+				$data[self::DEFAULT_VALUE]);
99
+		}
100
+	}
101
+
102
+	/**
103
+	 * Parse the set of defined values.
104
+	 *
105
+	 * @since 0.1.0
106
+	 *
107
+	 * @param string $key The key of the schema data.
108
+	 */
109
+	protected function parseDefined($key)
110
+	{
111
+		$this->defined[] = $key;
112
+	}
113
+
114
+	/**
115
+	 * Parse the set of required values.
116
+	 *
117
+	 * @since 0.1.0
118
+	 *
119
+	 * @param string $key  The key of the schema data.
120
+	 * @param mixed  $data The data associated with the key.
121
+	 */
122
+	protected function parseRequired($key, $data)
123
+	{
124
+		if ($this->isTruthy($data)) {
125
+			$this->required[] = $key;
126
+		}
127
+	}
128
+
129
+	/**
130
+	 * Parse the set of default values.
131
+	 *
132
+	 * @since 0.1.0
133
+	 *
134
+	 * @param string $key  The key of the schema data.
135
+	 * @param mixed  $data The data associated with the key.
136
+	 */
137
+	protected function parseDefault($key, $data)
138
+	{
139
+		$this->defaults[$key] = $data;
140
+	}
141
+
142
+	/**
143
+	 * Return a boolean true or false for an arbitrary set of data. Recognizes
144
+	 * several different string values that should be valued as true.
145
+	 *
146
+	 * @since 0.1.0
147
+	 *
148
+	 * @param mixed $data The data to evaluate.
149
+	 * @return bool
150
+	 */
151
+	protected function isTruthy($data)
152
+	{
153
+		return in_array($data, self::TRUTHY_VALUES, true);
154
+	}
155 155
 }
Please login to merge, or discard this patch.