Passed
Push — master ( 98a532...ac68ab )
by Alain
02:36
created
src/ConfigSchema.php 1 patch
Indentation   +136 added lines, -136 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,132 +25,132 @@  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, $data);
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
-     * @param mixed  $data The data associated with the key.
109
-     */
110
-    protected function parseDefined($key, $data)
111
-    {
112
-        $this->defined[] = $key;
113
-    }
114
-
115
-    /**
116
-     * Parse the set of required values.
117
-     *
118
-     * @since 0.1.0
119
-     *
120
-     * @param string $key  The key of the schema data.
121
-     * @param mixed  $data The data associated with the key.
122
-     */
123
-    protected function parseRequired($key, $data)
124
-    {
125
-        if ($this->isTruthy($data)) {
126
-            $this->required[] = $key;
127
-        }
128
-    }
129
-
130
-    /**
131
-     * Parse the set of default values.
132
-     *
133
-     * @since 0.1.0
134
-     *
135
-     * @param string $key  The key of the schema data.
136
-     * @param mixed  $data The data associated with the key.
137
-     */
138
-    protected function parseDefault($key, $data)
139
-    {
140
-        $this->defaults[$key] = $data;
141
-    }
142
-
143
-    /**
144
-     * Return a boolean true or false for an arbitrary set of data. Recognizes
145
-     * several different string values that should be valued as true.
146
-     *
147
-     * @since 0.1.0
148
-     *
149
-     * @param mixed $data The data to evaluate.
150
-     * @return bool
151
-     */
152
-    protected function isTruthy($data)
153
-    {
154
-        return in_array($data, self::TRUTHY_VALUES, true);
155
-    }
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, $data);
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
+	 * @param mixed  $data The data associated with the key.
109
+	 */
110
+	protected function parseDefined($key, $data)
111
+	{
112
+		$this->defined[] = $key;
113
+	}
114
+
115
+	/**
116
+	 * Parse the set of required values.
117
+	 *
118
+	 * @since 0.1.0
119
+	 *
120
+	 * @param string $key  The key of the schema data.
121
+	 * @param mixed  $data The data associated with the key.
122
+	 */
123
+	protected function parseRequired($key, $data)
124
+	{
125
+		if ($this->isTruthy($data)) {
126
+			$this->required[] = $key;
127
+		}
128
+	}
129
+
130
+	/**
131
+	 * Parse the set of default values.
132
+	 *
133
+	 * @since 0.1.0
134
+	 *
135
+	 * @param string $key  The key of the schema data.
136
+	 * @param mixed  $data The data associated with the key.
137
+	 */
138
+	protected function parseDefault($key, $data)
139
+	{
140
+		$this->defaults[$key] = $data;
141
+	}
142
+
143
+	/**
144
+	 * Return a boolean true or false for an arbitrary set of data. Recognizes
145
+	 * several different string values that should be valued as true.
146
+	 *
147
+	 * @since 0.1.0
148
+	 *
149
+	 * @param mixed $data The data to evaluate.
150
+	 * @return bool
151
+	 */
152
+	protected function isTruthy($data)
153
+	{
154
+		return in_array($data, self::TRUTHY_VALUES, true);
155
+	}
156 156
 }
Please login to merge, or discard this patch.