Test Failed
Push — master ( 147d4d...670e11 )
by Alain
03:28
created
src/View/Support/AbstractFinder.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -27,216 +27,216 @@
 block discarded – undo
27 27
 abstract class AbstractFinder implements Finder
28 28
 {
29 29
 
30
-    use ConfigTrait;
31
-
32
-    /**
33
-     * Findable collection that the Finder can iterate through to find a match.
34
-     *
35
-     * @since 0.1.0
36
-     *
37
-     * @var Findables
38
-     */
39
-    protected $findables;
40
-
41
-    /**
42
-     * NullObject that is returned if the Finder could not find a match.
43
-     *
44
-     * @since 0.1.0
45
-     *
46
-     * @var NullFindable
47
-     */
48
-    protected $nullObject;
49
-
50
-    /**
51
-     * Instantiate an AbstractFinder object.
52
-     *
53
-     * @since 0.1.0
54
-     *
55
-     * @param ConfigInterface $config Configuration of the AbstractFinder.
56
-     *
57
-     * @throws FailedToProcessConfigException If the config could not be processed.
58
-     */
59
-    public function __construct(ConfigInterface $config)
60
-    {
61
-        $this->processConfig($config);
62
-        $this->findables = new Findables();
63
-        $this->registerFindables($this->config);
64
-        $this->registerNullObject($this->config);
65
-    }
66
-
67
-    /**
68
-     * Register the Findables defined in the given configuration.
69
-     *
70
-     * @since 0.1.0
71
-     *
72
-     * @param ConfigInterface $config Configuration to register the Findables from.
73
-     */
74
-    public function registerFindables(ConfigInterface $config)
75
-    {
76
-        $findables = (array) $config->getKey($this->getFindablesConfigKey());
77
-        foreach ($findables as $findableKey => $findableObject) {
78
-            $this->findables->set($findableKey, $findableObject);
79
-        }
80
-    }
81
-
82
-    /**
83
-     * Register the NullObject defined in the given configuration.
84
-     *
85
-     * @since 0.1.0
86
-     *
87
-     * @param ConfigInterface $config Configuration to register the NullObject from.
88
-     */
89
-    public function registerNullObject(ConfigInterface $config)
90
-    {
91
-        $this->nullObject = $config->getKey($this->getNullObjectConfigKey());
92
-    }
93
-
94
-    /**
95
-     * Get the NullObject.
96
-     *
97
-     * @since 0.1.1
98
-     *
99
-     * @return NullFindable NullObject for the current Finder.
100
-     * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
101
-     */
102
-    public function getNullObject()
103
-    {
104
-        $this->initializeNullObject();
105
-
106
-        return $this->nullObject;
107
-    }
108
-
109
-    /**
110
-     * Get the config key for the Findables definitions.
111
-     *
112
-     * @since 0.1.0
113
-     *
114
-     * @return string Config key use to define the Findables.
115
-     */
116
-    protected function getFindablesConfigKey(): string
117
-    {
118
-        return 'Findables';
119
-    }
120
-
121
-    /**
122
-     * Get the config key for the NullObject definitions.
123
-     *
124
-     * @since 0.1.0
125
-     *
126
-     * @return string Config key use to define the NullObject.
127
-     */
128
-    protected function getNullObjectConfigKey(): string
129
-    {
130
-        return 'NullObject';
131
-    }
132
-
133
-    /**
134
-     * Initialize the NullObject.
135
-     *
136
-     * @since 0.1.1
137
-     *
138
-     * @param mixed $arguments Optional. Arguments to use.
139
-     *
140
-     * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
141
-     */
142
-    protected function initializeNullObject($arguments = null)
143
-    {
144
-        $this->nullObject = $this->maybeInstantiateFindable($this->nullObject, $arguments);
145
-    }
146
-
147
-    /**
148
-     * Initialize the Findables that can be iterated.
149
-     *
150
-     * @param mixed $arguments Optional. Arguments to use.
151
-     *
152
-     * @since 0.1.0
153
-     *
154
-     * @return Findables Collection of Findables.
155
-     * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
156
-     */
157
-    protected function initializeFindables($arguments = null): Findables
158
-    {
159
-        return $this->findables->map(function ($findable) use ($arguments) {
160
-            return $this->initializeFindable($findable, $arguments);
161
-        });
162
-    }
163
-
164
-    /**
165
-     * Initialize a single findable by instantiating class name strings and calling closures.
166
-     *
167
-     * @since 0.1.0
168
-     *
169
-     * @param mixed $findable  Findable to instantiate.
170
-     * @param mixed $arguments Optional. Arguments to use.
171
-     *
172
-     * @return Findable Instantiated findable.
173
-     * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
174
-     */
175
-    protected function initializeFindable($findable, $arguments = null): Findable
176
-    {
177
-        return $this->maybeInstantiateFindable($findable, $arguments);
178
-    }
179
-
180
-    /**
181
-     * Maybe instantiate a Findable if it is not yet an object.
182
-     *
183
-     * @since 0.1.1
184
-     *
185
-     * @param mixed $findable  Findable to instantiate.
186
-     * @param mixed $arguments Optional. Arguments to use.
187
-     *
188
-     * @return Findable Instantiated findable.
189
-     * @throws FailedToInstantiateFindable If the findable could not be instantiated.
190
-     */
191
-    protected function maybeInstantiateFindable($findable, $arguments = null): Findable
192
-    {
193
-        if (is_string($findable)) {
194
-            $findable = $this->instantiateFindableFromString($findable, $arguments);
195
-        }
196
-
197
-        if (is_callable($findable)) {
198
-            $findable = $this->instantiateFindableFromCallable($findable, $arguments);
199
-        }
200
-
201
-        if (! $findable instanceof Findable) {
202
-            throw new FailedToInstantiateFindable(
203
-                sprintf(
204
-                    _('Could not instantiate Findable "%s".'),
205
-                    serialize($findable)
206
-                )
207
-            );
208
-        }
209
-
210
-        return $findable;
211
-    }
212
-
213
-    /**
214
-     * Instantiate a Findable from a string.
215
-     *
216
-     * @since 0.1.1
217
-     *
218
-     * @param string $string    String to use for instantiation.
219
-     * @param mixed  $arguments Optional. Arguments to use for instantiation.
220
-     *
221
-     * @return Findable Instantiated Findable.
222
-     */
223
-    protected function instantiateFindableFromString(string $string, $arguments = []): Findable
224
-    {
225
-        return new $string(...(array)$arguments);
226
-    }
227
-
228
-    /**
229
-     * Instantiate a Findable from a callable.
230
-     *
231
-     * @since 0.1.1
232
-     *
233
-     * @param callable $callable  Callable to use for instantiation.
234
-     * @param mixed    $arguments Optional. Arguments to use for instantiation.
235
-     *
236
-     * @return Findable Instantiated Findable.
237
-     */
238
-    protected function instantiateFindableFromCallable(callable $callable, $arguments = []): Findable
239
-    {
240
-        return $callable(...(array)$arguments);
241
-    }
30
+	use ConfigTrait;
31
+
32
+	/**
33
+	 * Findable collection that the Finder can iterate through to find a match.
34
+	 *
35
+	 * @since 0.1.0
36
+	 *
37
+	 * @var Findables
38
+	 */
39
+	protected $findables;
40
+
41
+	/**
42
+	 * NullObject that is returned if the Finder could not find a match.
43
+	 *
44
+	 * @since 0.1.0
45
+	 *
46
+	 * @var NullFindable
47
+	 */
48
+	protected $nullObject;
49
+
50
+	/**
51
+	 * Instantiate an AbstractFinder object.
52
+	 *
53
+	 * @since 0.1.0
54
+	 *
55
+	 * @param ConfigInterface $config Configuration of the AbstractFinder.
56
+	 *
57
+	 * @throws FailedToProcessConfigException If the config could not be processed.
58
+	 */
59
+	public function __construct(ConfigInterface $config)
60
+	{
61
+		$this->processConfig($config);
62
+		$this->findables = new Findables();
63
+		$this->registerFindables($this->config);
64
+		$this->registerNullObject($this->config);
65
+	}
66
+
67
+	/**
68
+	 * Register the Findables defined in the given configuration.
69
+	 *
70
+	 * @since 0.1.0
71
+	 *
72
+	 * @param ConfigInterface $config Configuration to register the Findables from.
73
+	 */
74
+	public function registerFindables(ConfigInterface $config)
75
+	{
76
+		$findables = (array) $config->getKey($this->getFindablesConfigKey());
77
+		foreach ($findables as $findableKey => $findableObject) {
78
+			$this->findables->set($findableKey, $findableObject);
79
+		}
80
+	}
81
+
82
+	/**
83
+	 * Register the NullObject defined in the given configuration.
84
+	 *
85
+	 * @since 0.1.0
86
+	 *
87
+	 * @param ConfigInterface $config Configuration to register the NullObject from.
88
+	 */
89
+	public function registerNullObject(ConfigInterface $config)
90
+	{
91
+		$this->nullObject = $config->getKey($this->getNullObjectConfigKey());
92
+	}
93
+
94
+	/**
95
+	 * Get the NullObject.
96
+	 *
97
+	 * @since 0.1.1
98
+	 *
99
+	 * @return NullFindable NullObject for the current Finder.
100
+	 * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
101
+	 */
102
+	public function getNullObject()
103
+	{
104
+		$this->initializeNullObject();
105
+
106
+		return $this->nullObject;
107
+	}
108
+
109
+	/**
110
+	 * Get the config key for the Findables definitions.
111
+	 *
112
+	 * @since 0.1.0
113
+	 *
114
+	 * @return string Config key use to define the Findables.
115
+	 */
116
+	protected function getFindablesConfigKey(): string
117
+	{
118
+		return 'Findables';
119
+	}
120
+
121
+	/**
122
+	 * Get the config key for the NullObject definitions.
123
+	 *
124
+	 * @since 0.1.0
125
+	 *
126
+	 * @return string Config key use to define the NullObject.
127
+	 */
128
+	protected function getNullObjectConfigKey(): string
129
+	{
130
+		return 'NullObject';
131
+	}
132
+
133
+	/**
134
+	 * Initialize the NullObject.
135
+	 *
136
+	 * @since 0.1.1
137
+	 *
138
+	 * @param mixed $arguments Optional. Arguments to use.
139
+	 *
140
+	 * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
141
+	 */
142
+	protected function initializeNullObject($arguments = null)
143
+	{
144
+		$this->nullObject = $this->maybeInstantiateFindable($this->nullObject, $arguments);
145
+	}
146
+
147
+	/**
148
+	 * Initialize the Findables that can be iterated.
149
+	 *
150
+	 * @param mixed $arguments Optional. Arguments to use.
151
+	 *
152
+	 * @since 0.1.0
153
+	 *
154
+	 * @return Findables Collection of Findables.
155
+	 * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
156
+	 */
157
+	protected function initializeFindables($arguments = null): Findables
158
+	{
159
+		return $this->findables->map(function ($findable) use ($arguments) {
160
+			return $this->initializeFindable($findable, $arguments);
161
+		});
162
+	}
163
+
164
+	/**
165
+	 * Initialize a single findable by instantiating class name strings and calling closures.
166
+	 *
167
+	 * @since 0.1.0
168
+	 *
169
+	 * @param mixed $findable  Findable to instantiate.
170
+	 * @param mixed $arguments Optional. Arguments to use.
171
+	 *
172
+	 * @return Findable Instantiated findable.
173
+	 * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
174
+	 */
175
+	protected function initializeFindable($findable, $arguments = null): Findable
176
+	{
177
+		return $this->maybeInstantiateFindable($findable, $arguments);
178
+	}
179
+
180
+	/**
181
+	 * Maybe instantiate a Findable if it is not yet an object.
182
+	 *
183
+	 * @since 0.1.1
184
+	 *
185
+	 * @param mixed $findable  Findable to instantiate.
186
+	 * @param mixed $arguments Optional. Arguments to use.
187
+	 *
188
+	 * @return Findable Instantiated findable.
189
+	 * @throws FailedToInstantiateFindable If the findable could not be instantiated.
190
+	 */
191
+	protected function maybeInstantiateFindable($findable, $arguments = null): Findable
192
+	{
193
+		if (is_string($findable)) {
194
+			$findable = $this->instantiateFindableFromString($findable, $arguments);
195
+		}
196
+
197
+		if (is_callable($findable)) {
198
+			$findable = $this->instantiateFindableFromCallable($findable, $arguments);
199
+		}
200
+
201
+		if (! $findable instanceof Findable) {
202
+			throw new FailedToInstantiateFindable(
203
+				sprintf(
204
+					_('Could not instantiate Findable "%s".'),
205
+					serialize($findable)
206
+				)
207
+			);
208
+		}
209
+
210
+		return $findable;
211
+	}
212
+
213
+	/**
214
+	 * Instantiate a Findable from a string.
215
+	 *
216
+	 * @since 0.1.1
217
+	 *
218
+	 * @param string $string    String to use for instantiation.
219
+	 * @param mixed  $arguments Optional. Arguments to use for instantiation.
220
+	 *
221
+	 * @return Findable Instantiated Findable.
222
+	 */
223
+	protected function instantiateFindableFromString(string $string, $arguments = []): Findable
224
+	{
225
+		return new $string(...(array)$arguments);
226
+	}
227
+
228
+	/**
229
+	 * Instantiate a Findable from a callable.
230
+	 *
231
+	 * @since 0.1.1
232
+	 *
233
+	 * @param callable $callable  Callable to use for instantiation.
234
+	 * @param mixed    $arguments Optional. Arguments to use for instantiation.
235
+	 *
236
+	 * @return Findable Instantiated Findable.
237
+	 */
238
+	protected function instantiateFindableFromCallable(callable $callable, $arguments = []): Findable
239
+	{
240
+		return $callable(...(array)$arguments);
241
+	}
242 242
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      */
157 157
     protected function initializeFindables($arguments = null): Findables
158 158
     {
159
-        return $this->findables->map(function ($findable) use ($arguments) {
159
+        return $this->findables->map(function($findable) use ($arguments) {
160 160
             return $this->initializeFindable($findable, $arguments);
161 161
         });
162 162
     }
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
             $findable = $this->instantiateFindableFromCallable($findable, $arguments);
199 199
         }
200 200
 
201
-        if (! $findable instanceof Findable) {
201
+        if ( ! $findable instanceof Findable) {
202 202
             throw new FailedToInstantiateFindable(
203 203
                 sprintf(
204 204
                     _('Could not instantiate Findable "%s".'),
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
      */
223 223
     protected function instantiateFindableFromString(string $string, $arguments = []): Findable
224 224
     {
225
-        return new $string(...(array)$arguments);
225
+        return new $string(...(array) $arguments);
226 226
     }
227 227
 
228 228
     /**
@@ -237,6 +237,6 @@  discard block
 block discarded – undo
237 237
      */
238 238
     protected function instantiateFindableFromCallable(callable $callable, $arguments = []): Findable
239 239
     {
240
-        return $callable(...(array)$arguments);
240
+        return $callable(...(array) $arguments);
241 241
     }
242 242
 }
Please login to merge, or discard this patch.