Passed
Push — master ( 8e8597...ac1311 )
by Alain
02:41
created
src/View/Support/FinderInterface.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -22,23 +22,23 @@
 block discarded – undo
22 22
 interface FinderInterface
23 23
 {
24 24
 
25
-    /**
26
-     * Find a result based on a specific criteria.
27
-     *
28
-     * @since 0.1.0
29
-     *
30
-     * @param array $criteria Criteria to search for.
31
-     *
32
-     * @return mixed Result of the search.
33
-     */
34
-    public function find(array $criteria);
25
+	/**
26
+	 * Find a result based on a specific criteria.
27
+	 *
28
+	 * @since 0.1.0
29
+	 *
30
+	 * @param array $criteria Criteria to search for.
31
+	 *
32
+	 * @return mixed Result of the search.
33
+	 */
34
+	public function find(array $criteria);
35 35
 
36
-    /**
37
-     * Get the NullObject.
38
-     *
39
-     * @since 0.1.1
40
-     *
41
-     * @return NullObject NullObject for the current Finder.
42
-     */
43
-    public function getNullObject();
36
+	/**
37
+	 * Get the NullObject.
38
+	 *
39
+	 * @since 0.1.1
40
+	 *
41
+	 * @return NullObject NullObject for the current Finder.
42
+	 */
43
+	public function getNullObject();
44 44
 }
Please login to merge, or discard this patch.
src/View/ViewBuilder.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @since 0.1.0
92 92
      *
93 93
      * @param string $view View identifier to create a view for.
94
-     * @param mixed  $type Type of view to create.
94
+     * @param string|null  $type Type of view to create.
95 95
      *
96 96
      * @return ViewInterface Instance of the requested view.
97 97
      */
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      *
191 191
      * @since 0.1.0
192 192
      *
193
-     * @param array $criteria Criteria to match.
193
+     * @param string[] $criteria Criteria to match.
194 194
      *
195 195
      * @return string|false URI of the requested view, or false if not found.
196 196
      */
Please login to merge, or discard this patch.
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -34,227 +34,227 @@
 block discarded – undo
34 34
 class ViewBuilder
35 35
 {
36 36
 
37
-    use ConfigTrait;
37
+	use ConfigTrait;
38 38
 
39
-    const ENGINE_FINDER_KEY = 'EngineFinder';
40
-    const VIEW_FINDER_KEY   = 'ViewFinder';
39
+	const ENGINE_FINDER_KEY = 'EngineFinder';
40
+	const VIEW_FINDER_KEY   = 'ViewFinder';
41 41
 
42
-    /**
43
-     * ViewFinder instance.
44
-     *
45
-     * @since 0.1.0
46
-     *
47
-     * @var ViewFinderInterface
48
-     */
49
-    protected $viewFinder;
42
+	/**
43
+	 * ViewFinder instance.
44
+	 *
45
+	 * @since 0.1.0
46
+	 *
47
+	 * @var ViewFinderInterface
48
+	 */
49
+	protected $viewFinder;
50 50
 
51
-    /**
52
-     * EngineFinder instance.
53
-     *
54
-     * @since 0.1.0
55
-     *
56
-     * @var EngineFinderInterface
57
-     */
58
-    protected $engineFinder;
51
+	/**
52
+	 * EngineFinder instance.
53
+	 *
54
+	 * @since 0.1.0
55
+	 *
56
+	 * @var EngineFinderInterface
57
+	 */
58
+	protected $engineFinder;
59 59
 
60
-    /**
61
-     * Locations to scan for views.
62
-     *
63
-     * @since 0.1.0
64
-     *
65
-     * @var LocationCollection
66
-     */
67
-    protected $locations;
60
+	/**
61
+	 * Locations to scan for views.
62
+	 *
63
+	 * @since 0.1.0
64
+	 *
65
+	 * @var LocationCollection
66
+	 */
67
+	protected $locations;
68 68
 
69
-    /**
70
-     * Instantiate a ViewBuilder object.
71
-     *
72
-     * @since 0.1.0
73
-     *
74
-     * @param ConfigInterface            $config       Configuration settings.
75
-     * @param ViewFinderInterface|null   $viewFinder   ViewFinder instance.
76
-     * @param EngineFinderInterface|null $engineFinder EngineFinder instance.
77
-     *
78
-     * @throws FailedToProcessConfigException If the config could not be processed.
79
-     */
80
-    public function __construct(
81
-        ConfigInterface $config,
82
-        ViewFinderInterface $viewFinder = null,
83
-        EngineFinderInterface $engineFinder = null
84
-    ) {
85
-        $this->processConfig($config);
86
-        $this->viewFinder   = $viewFinder;
87
-        $this->engineFinder = $engineFinder;
88
-        $this->locations    = new LocationCollection();
89
-    }
69
+	/**
70
+	 * Instantiate a ViewBuilder object.
71
+	 *
72
+	 * @since 0.1.0
73
+	 *
74
+	 * @param ConfigInterface            $config       Configuration settings.
75
+	 * @param ViewFinderInterface|null   $viewFinder   ViewFinder instance.
76
+	 * @param EngineFinderInterface|null $engineFinder EngineFinder instance.
77
+	 *
78
+	 * @throws FailedToProcessConfigException If the config could not be processed.
79
+	 */
80
+	public function __construct(
81
+		ConfigInterface $config,
82
+		ViewFinderInterface $viewFinder = null,
83
+		EngineFinderInterface $engineFinder = null
84
+	) {
85
+		$this->processConfig($config);
86
+		$this->viewFinder   = $viewFinder;
87
+		$this->engineFinder = $engineFinder;
88
+		$this->locations    = new LocationCollection();
89
+	}
90 90
 
91
-    /**
92
-     * Create a new view for a given URI.
93
-     *
94
-     * @since 0.1.0
95
-     *
96
-     * @param string $view View identifier to create a view for.
97
-     * @param mixed  $type Type of view to create.
98
-     *
99
-     * @return ViewInterface Instance of the requested view.
100
-     */
101
-    public function create($view, $type = null)
102
-    {
103
-        $uri    = $this->scanLocations([$view]);
104
-        $engine = $this->getEngine($uri);
91
+	/**
92
+	 * Create a new view for a given URI.
93
+	 *
94
+	 * @since 0.1.0
95
+	 *
96
+	 * @param string $view View identifier to create a view for.
97
+	 * @param mixed  $type Type of view to create.
98
+	 *
99
+	 * @return ViewInterface Instance of the requested view.
100
+	 */
101
+	public function create($view, $type = null)
102
+	{
103
+		$uri    = $this->scanLocations([$view]);
104
+		$engine = $this->getEngine($uri);
105 105
 
106
-        return $uri
107
-            ? $this->getView($uri, $engine, $type)
108
-            : $this->getViewFinder()->getNullObject();
109
-    }
106
+		return $uri
107
+			? $this->getView($uri, $engine, $type)
108
+			: $this->getViewFinder()->getNullObject();
109
+	}
110 110
 
111
-    /**
112
-     * Get an Engine that can deal with the given URI.
113
-     *
114
-     * @since 0.1.0
115
-     *
116
-     * @param string|false $uri URI to get an engine for.
117
-     *
118
-     * @return EngineInterface Instance of an engine that can deal with the given URI.
119
-     */
120
-    public function getEngine($uri)
121
-    {
122
-        return $this->getEngineFinder()->find([$uri]);
123
-    }
111
+	/**
112
+	 * Get an Engine that can deal with the given URI.
113
+	 *
114
+	 * @since 0.1.0
115
+	 *
116
+	 * @param string|false $uri URI to get an engine for.
117
+	 *
118
+	 * @return EngineInterface Instance of an engine that can deal with the given URI.
119
+	 */
120
+	public function getEngine($uri)
121
+	{
122
+		return $this->getEngineFinder()->find([$uri]);
123
+	}
124 124
 
125
-    /**
126
-     * Get a view for a given URI, engine and type.
127
-     *
128
-     * @since 0.1.0
129
-     *
130
-     * @param string          $uri    URI to get a view for.
131
-     * @param EngineInterface $engine Engine to use for the view.
132
-     * @param mixed           $type   Type of view to get.
133
-     *
134
-     * @return ViewInterface View that matches the given requirements.
135
-     */
136
-    public function getView($uri, EngineInterface $engine, $type = null)
137
-    {
138
-        if (null === $type) {
139
-            return $this->getViewFinder()->find([$uri], $engine);
140
-        }
125
+	/**
126
+	 * Get a view for a given URI, engine and type.
127
+	 *
128
+	 * @since 0.1.0
129
+	 *
130
+	 * @param string          $uri    URI to get a view for.
131
+	 * @param EngineInterface $engine Engine to use for the view.
132
+	 * @param mixed           $type   Type of view to get.
133
+	 *
134
+	 * @return ViewInterface View that matches the given requirements.
135
+	 */
136
+	public function getView($uri, EngineInterface $engine, $type = null)
137
+	{
138
+		if (null === $type) {
139
+			return $this->getViewFinder()->find([$uri], $engine);
140
+		}
141 141
 
142
-        return $this->resolveType($type, $uri, $engine);
143
-    }
142
+		return $this->resolveType($type, $uri, $engine);
143
+	}
144 144
 
145
-    /**
146
-     * Get the ViewFinder instance.
147
-     *
148
-     * @since 0.1.0
149
-     *
150
-     * @return ViewFinderInterface Instance of a ViewFinder.
151
-     */
152
-    public function getViewFinder()
153
-    {
154
-        return $this->getFinder($this->viewFinder, static::VIEW_FINDER_KEY);
155
-    }
145
+	/**
146
+	 * Get the ViewFinder instance.
147
+	 *
148
+	 * @since 0.1.0
149
+	 *
150
+	 * @return ViewFinderInterface Instance of a ViewFinder.
151
+	 */
152
+	public function getViewFinder()
153
+	{
154
+		return $this->getFinder($this->viewFinder, static::VIEW_FINDER_KEY);
155
+	}
156 156
 
157
-    /**
158
-     * Get the EngineFinder instance.
159
-     *
160
-     * @since 0.1.0
161
-     *
162
-     * @return EngineFinderInterface Instance of a EngineFinder.
163
-     */
164
-    public function getEngineFinder()
165
-    {
166
-        return $this->getFinder($this->engineFinder, static::ENGINE_FINDER_KEY);
167
-    }
157
+	/**
158
+	 * Get the EngineFinder instance.
159
+	 *
160
+	 * @since 0.1.0
161
+	 *
162
+	 * @return EngineFinderInterface Instance of a EngineFinder.
163
+	 */
164
+	public function getEngineFinder()
165
+	{
166
+		return $this->getFinder($this->engineFinder, static::ENGINE_FINDER_KEY);
167
+	}
168 168
 
169
-    /**
170
-     * Add a location to scan with the ViewFinder.
171
-     *
172
-     * @since 0.1.0
173
-     *
174
-     * @param LocationInterface $location Location to scan with the ViewFinder.
175
-     */
176
-    public function addLocation(LocationInterface $location)
177
-    {
178
-        $this->locations->add($location);
179
-    }
169
+	/**
170
+	 * Add a location to scan with the ViewFinder.
171
+	 *
172
+	 * @since 0.1.0
173
+	 *
174
+	 * @param LocationInterface $location Location to scan with the ViewFinder.
175
+	 */
176
+	public function addLocation(LocationInterface $location)
177
+	{
178
+		$this->locations->add($location);
179
+	}
180 180
 
181
-    /**
182
-     * Scan Locations for an URI that matches the specified criteria.
183
-     *
184
-     * @since 0.1.0
185
-     *
186
-     * @param array $criteria Criteria to match.
187
-     *
188
-     * @return string|false URI of the requested view, or false if not found.
189
-     */
190
-    public function scanLocations(array $criteria)
191
-    {
192
-        return $this->locations->map(function ($location) use ($criteria) {
193
-            /** @var LocationInterface $location */
194
-            return $location->getURI($criteria);
195
-        })->filter(function ($uri) {
196
-            return false !== $uri;
197
-        })->first() ?: false;
198
-    }
181
+	/**
182
+	 * Scan Locations for an URI that matches the specified criteria.
183
+	 *
184
+	 * @since 0.1.0
185
+	 *
186
+	 * @param array $criteria Criteria to match.
187
+	 *
188
+	 * @return string|false URI of the requested view, or false if not found.
189
+	 */
190
+	public function scanLocations(array $criteria)
191
+	{
192
+		return $this->locations->map(function ($location) use ($criteria) {
193
+			/** @var LocationInterface $location */
194
+			return $location->getURI($criteria);
195
+		})->filter(function ($uri) {
196
+			return false !== $uri;
197
+		})->first() ?: false;
198
+	}
199 199
 
200
-    /**
201
-     * Get a finder instance.
202
-     *
203
-     * @since 0.1.1
204
-     *
205
-     * @param mixed  $property Property to use.
206
-     * @param string $key      Configuration key to use.
207
-     *
208
-     * @return FinderInterface The requested finder instance.
209
-     */
210
-    protected function getFinder(&$property, $key)
211
-    {
212
-        if (null === $property) {
213
-            $engineFinderClass = $this->config->getKey($key, 'ClassName');
214
-            $property          = new $engineFinderClass($this->config->getSubConfig($key));
215
-        }
200
+	/**
201
+	 * Get a finder instance.
202
+	 *
203
+	 * @since 0.1.1
204
+	 *
205
+	 * @param mixed  $property Property to use.
206
+	 * @param string $key      Configuration key to use.
207
+	 *
208
+	 * @return FinderInterface The requested finder instance.
209
+	 */
210
+	protected function getFinder(&$property, $key)
211
+	{
212
+		if (null === $property) {
213
+			$engineFinderClass = $this->config->getKey($key, 'ClassName');
214
+			$property          = new $engineFinderClass($this->config->getSubConfig($key));
215
+		}
216 216
 
217
-        return $property;
218
-    }
217
+		return $property;
218
+	}
219 219
 
220
-    /**
221
-     * Resolve the view type.
222
-     *
223
-     * @since 0.1.0
224
-     *
225
-     * @param mixed                $type   Type of view that was requested.
226
-     * @param string               $uri    URI to get a view for.
227
-     * @param EngineInterface|null $engine Engine to use for the view.
228
-     *
229
-     * @return ViewInterface Resolved View object.
230
-     * @throws FailedToInstantiateViewException If the view type could not be resolved.
231
-     */
232
-    protected function resolveType($type, $uri, EngineInterface $engine = null)
233
-    {
234
-        $configKey = [static::VIEW_FINDER_KEY, 'Views', $type];
220
+	/**
221
+	 * Resolve the view type.
222
+	 *
223
+	 * @since 0.1.0
224
+	 *
225
+	 * @param mixed                $type   Type of view that was requested.
226
+	 * @param string               $uri    URI to get a view for.
227
+	 * @param EngineInterface|null $engine Engine to use for the view.
228
+	 *
229
+	 * @return ViewInterface Resolved View object.
230
+	 * @throws FailedToInstantiateViewException If the view type could not be resolved.
231
+	 */
232
+	protected function resolveType($type, $uri, EngineInterface $engine = null)
233
+	{
234
+		$configKey = [static::VIEW_FINDER_KEY, 'Views', $type];
235 235
 
236
-        if (is_string($type) && $this->config->hasKey($configKey)) {
237
-            $className = $this->config->getKey($configKey);
238
-            $type      = new $className($uri, $engine);
239
-        }
236
+		if (is_string($type) && $this->config->hasKey($configKey)) {
237
+			$className = $this->config->getKey($configKey);
238
+			$type      = new $className($uri, $engine);
239
+		}
240 240
 
241
-        if (is_string($type)) {
242
-            $type = new $type($uri, $engine);
243
-        }
241
+		if (is_string($type)) {
242
+			$type = new $type($uri, $engine);
243
+		}
244 244
 
245
-        if (is_callable($type)) {
246
-            $type = $type($uri, $engine);
247
-        }
245
+		if (is_callable($type)) {
246
+			$type = $type($uri, $engine);
247
+		}
248 248
 
249
-        if (! $type instanceof ViewInterface) {
250
-            throw new FailedToInstantiateViewException(
251
-                sprintf(
252
-                    _('Could not instantiate view "%s".'),
253
-                    serialize($type)
254
-                )
255
-            );
256
-        }
249
+		if (! $type instanceof ViewInterface) {
250
+			throw new FailedToInstantiateViewException(
251
+				sprintf(
252
+					_('Could not instantiate view "%s".'),
253
+					serialize($type)
254
+				)
255
+			);
256
+		}
257 257
 
258
-        return $type;
259
-    }
258
+		return $type;
259
+	}
260 260
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -189,10 +189,10 @@  discard block
 block discarded – undo
189 189
      */
190 190
     public function scanLocations(array $criteria)
191 191
     {
192
-        return $this->locations->map(function ($location) use ($criteria) {
192
+        return $this->locations->map(function($location) use ($criteria) {
193 193
             /** @var LocationInterface $location */
194 194
             return $location->getURI($criteria);
195
-        })->filter(function ($uri) {
195
+        })->filter(function($uri) {
196 196
             return false !== $uri;
197 197
         })->first() ?: false;
198 198
     }
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
             $type = $type($uri, $engine);
247 247
         }
248 248
 
249
-        if (! $type instanceof ViewInterface) {
249
+        if ( ! $type instanceof ViewInterface) {
250 250
             throw new FailedToInstantiateViewException(
251 251
                 sprintf(
252 252
                     _('Could not instantiate view "%s".'),
Please login to merge, or discard this patch.
src/View/View/NullView.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
      */
37 37
     public function render(array $context = [], $echo = false)
38 38
     {
39
-        if (! $echo) {
39
+        if ( ! $echo) {
40 40
             return '';
41 41
         }
42 42
     }
Please login to merge, or discard this patch.
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -25,34 +25,34 @@
 block discarded – undo
25 25
 class NullView implements ViewInterface, NullObject, Findable
26 26
 {
27 27
 
28
-    /**
29
-     * Check whether the Findable can handle an individual criterion.
30
-     *
31
-     * @since 0.1.0
32
-     *
33
-     * @param mixed $criterion Criterion to check.
34
-     *
35
-     * @return bool Whether the Findable can handle the criterion.
36
-     */
37
-    public function canHandle($criterion)
38
-    {
39
-        return true;
40
-    }
28
+	/**
29
+	 * Check whether the Findable can handle an individual criterion.
30
+	 *
31
+	 * @since 0.1.0
32
+	 *
33
+	 * @param mixed $criterion Criterion to check.
34
+	 *
35
+	 * @return bool Whether the Findable can handle the criterion.
36
+	 */
37
+	public function canHandle($criterion)
38
+	{
39
+		return true;
40
+	}
41 41
 
42
-    /**
43
-     * Render the view.
44
-     *
45
-     * @since 0.1.0
46
-     *
47
-     * @param array $context Optional. The context in which to render the view.
48
-     * @param bool  $echo    Optional. Whether to echo the output immediately. Defaults to false.
49
-     *
50
-     * @return string|void Rendered HTML or nothing, depending on $echo argument.
51
-     */
52
-    public function render(array $context = [], $echo = false)
53
-    {
54
-        if (! $echo) {
55
-            return '';
56
-        }
57
-    }
42
+	/**
43
+	 * Render the view.
44
+	 *
45
+	 * @since 0.1.0
46
+	 *
47
+	 * @param array $context Optional. The context in which to render the view.
48
+	 * @param bool  $echo    Optional. Whether to echo the output immediately. Defaults to false.
49
+	 *
50
+	 * @return string|void Rendered HTML or nothing, depending on $echo argument.
51
+	 */
52
+	public function render(array $context = [], $echo = false)
53
+	{
54
+		if (! $echo) {
55
+			return '';
56
+		}
57
+	}
58 58
 }
Please login to merge, or discard this patch.
src/View/View/ViewFinderInterface.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -25,15 +25,15 @@
 block discarded – undo
25 25
 interface ViewFinderInterface extends FinderInterface
26 26
 {
27 27
 
28
-    /**
29
-     * Find a result based on a specific criteria.
30
-     *
31
-     * @since 0.1.0
32
-     *
33
-     * @param array                $criteria Criteria to search for.
34
-     * @param EngineInterface|null $engine   Optional. Engine to use with the view.
35
-     *
36
-     * @return ViewInterface View that was found.
37
-     */
38
-    public function find(array $criteria, EngineInterface $engine = null);
28
+	/**
29
+	 * Find a result based on a specific criteria.
30
+	 *
31
+	 * @since 0.1.0
32
+	 *
33
+	 * @param array                $criteria Criteria to search for.
34
+	 * @param EngineInterface|null $engine   Optional. Engine to use with the view.
35
+	 *
36
+	 * @return ViewInterface View that was found.
37
+	 */
38
+	public function find(array $criteria, EngineInterface $engine = null);
39 39
 }
Please login to merge, or discard this patch.
src/View/Location/LocationInterface.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -22,25 +22,25 @@
 block discarded – undo
22 22
 interface LocationInterface
23 23
 {
24 24
 
25
-    /**
26
-     * Get the first URI that matches the given criteria.
27
-     *
28
-     * @since 0.1.0
29
-     *
30
-     * @param array $criteria Criteria to match.
31
-     *
32
-     * @return string|false URI that matches the criteria or false if none found.
33
-     */
34
-    public function getURI(array $criteria);
25
+	/**
26
+	 * Get the first URI that matches the given criteria.
27
+	 *
28
+	 * @since 0.1.0
29
+	 *
30
+	 * @param array $criteria Criteria to match.
31
+	 *
32
+	 * @return string|false URI that matches the criteria or false if none found.
33
+	 */
34
+	public function getURI(array $criteria);
35 35
 
36
-    /**
37
-     * Get all URIs that match the given criteria.
38
-     *
39
-     * @since 0.1.1
40
-     *
41
-     * @param array $criteria Criteria to match.
42
-     *
43
-     * @return array URI that matches the criteria or false if none found.
44
-     */
45
-    public function getURIs(array $criteria);
36
+	/**
37
+	 * Get all URIs that match the given criteria.
38
+	 *
39
+	 * @since 0.1.1
40
+	 *
41
+	 * @param array $criteria Criteria to match.
42
+	 *
43
+	 * @return array URI that matches the criteria or false if none found.
44
+	 */
45
+	public function getURIs(array $criteria);
46 46
 }
Please login to merge, or discard this patch.
src/View/Engine/EngineFinder.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -24,39 +24,39 @@
 block discarded – undo
24 24
 class EngineFinder extends AbstractFinder
25 25
 {
26 26
 
27
-    /**
28
-     * Find a result based on a specific criteria.
29
-     *
30
-     * @since 0.1.0
31
-     *
32
-     * @param array $criteria Criteria to search for.
33
-     *
34
-     * @return EngineInterface Result of the search.
35
-     */
36
-    public function find(array $criteria)
37
-    {
38
-        $this->initializeFindables();
27
+	/**
28
+	 * Find a result based on a specific criteria.
29
+	 *
30
+	 * @since 0.1.0
31
+	 *
32
+	 * @param array $criteria Criteria to search for.
33
+	 *
34
+	 * @return EngineInterface Result of the search.
35
+	 */
36
+	public function find(array $criteria)
37
+	{
38
+		$this->initializeFindables();
39 39
 
40
-        foreach ($criteria as $entry) {
41
-            foreach ($this->findables as $engine) {
42
-                if ($engine->canHandle($entry)) {
43
-                    return $engine;
44
-                }
45
-            }
46
-        }
40
+		foreach ($criteria as $entry) {
41
+			foreach ($this->findables as $engine) {
42
+				if ($engine->canHandle($entry)) {
43
+					return $engine;
44
+				}
45
+			}
46
+		}
47 47
 
48
-        return $this->getNullObject();
49
-    }
48
+		return $this->getNullObject();
49
+	}
50 50
 
51
-    /**
52
-     * Get the config key for the Findables definitions.
53
-     *
54
-     * @since 0.1.0
55
-     *
56
-     * @return string Config key use to define the Findables.
57
-     */
58
-    protected function getFindablesConfigKey()
59
-    {
60
-        return 'Engines';
61
-    }
51
+	/**
52
+	 * Get the config key for the Findables definitions.
53
+	 *
54
+	 * @since 0.1.0
55
+	 *
56
+	 * @return string Config key use to define the Findables.
57
+	 */
58
+	protected function getFindablesConfigKey()
59
+	{
60
+		return 'Engines';
61
+	}
62 62
 }
Please login to merge, or discard this patch.
src/View/View/ViewFinder.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -25,42 +25,42 @@
 block discarded – undo
25 25
 class ViewFinder extends AbstractFinder
26 26
 {
27 27
 
28
-    /**
29
-     * Find a result based on a specific criteria.
30
-     *
31
-     * @since 0.1.0
32
-     *
33
-     * @param array                $criteria Criteria to search for.
34
-     * @param EngineInterface|null $engine   Optional. Engine to use with the view.
35
-     *
36
-     * @return ViewInterface View that was found.
37
-     */
38
-    public function find(array $criteria, EngineInterface $engine = null)
39
-    {
40
-        $uri = $criteria[0];
28
+	/**
29
+	 * Find a result based on a specific criteria.
30
+	 *
31
+	 * @since 0.1.0
32
+	 *
33
+	 * @param array                $criteria Criteria to search for.
34
+	 * @param EngineInterface|null $engine   Optional. Engine to use with the view.
35
+	 *
36
+	 * @return ViewInterface View that was found.
37
+	 */
38
+	public function find(array $criteria, EngineInterface $engine = null)
39
+	{
40
+		$uri = $criteria[0];
41 41
 
42
-        $this->initializeFindables([$uri, $engine]);
42
+		$this->initializeFindables([$uri, $engine]);
43 43
 
44
-        foreach ($criteria as $entry) {
45
-            foreach ($this->findables as $viewObject) {
46
-                if ($viewObject->canHandle($entry)) {
47
-                    return $viewObject;
48
-                }
49
-            }
50
-        }
44
+		foreach ($criteria as $entry) {
45
+			foreach ($this->findables as $viewObject) {
46
+				if ($viewObject->canHandle($entry)) {
47
+					return $viewObject;
48
+				}
49
+			}
50
+		}
51 51
 
52
-        return $this->getNullObject();
53
-    }
52
+		return $this->getNullObject();
53
+	}
54 54
 
55
-    /**
56
-     * Get the config key for the Findables definitions.
57
-     *
58
-     * @since 0.1.0
59
-     *
60
-     * @return string Config key use to define the Findables.
61
-     */
62
-    protected function getFindablesConfigKey()
63
-    {
64
-        return 'Views';
65
-    }
55
+	/**
56
+	 * Get the config key for the Findables definitions.
57
+	 *
58
+	 * @since 0.1.0
59
+	 *
60
+	 * @return string Config key use to define the Findables.
61
+	 */
62
+	protected function getFindablesConfigKey()
63
+	{
64
+		return 'Views';
65
+	}
66 66
 }
Please login to merge, or discard this patch.
src/View/Location/FilesystemLocation.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 
93 93
         foreach ($criteria as $entry) {
94 94
             if ($uri = $this->transform($entry, false)) {
95
-                $uris = array_merge($uris, (array)$uri);
95
+                $uris = array_merge($uris, (array) $uri);
96 96
             }
97 97
         }
98 98
 
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
      */
111 111
     protected function validateExtensions($extensions)
112 112
     {
113
-        if (! $extensions instanceof ExtensionCollection) {
114
-            $extensions = new ExtensionCollection((array)$extensions);
113
+        if ( ! $extensions instanceof ExtensionCollection) {
114
+            $extensions = new ExtensionCollection((array) $extensions);
115 115
         }
116 116
         $extensions->add('');
117 117
 
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
     {
165 165
         $variants = [];
166 166
 
167
-        $this->extensions->map(function ($extension) use ($entry, &$variants) {
168
-            $variants[] = $entry . $extension;
169
-            $variants[] = $this->path . DIRECTORY_SEPARATOR . $entry . $extension;
167
+        $this->extensions->map(function($extension) use ($entry, &$variants) {
168
+            $variants[] = $entry.$extension;
169
+            $variants[] = $this->path.DIRECTORY_SEPARATOR.$entry.$extension;
170 170
         });
171 171
 
172 172
         return $variants;
Please login to merge, or discard this patch.
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -25,150 +25,150 @@
 block discarded – undo
25 25
 class FilesystemLocation implements LocationInterface
26 26
 {
27 27
 
28
-    /**
29
-     * Path that this location points to.
30
-     *
31
-     * @since 0.1.0
32
-     *
33
-     * @var string
34
-     */
35
-    protected $path;
36
-
37
-    /**
38
-     * Extensions that this location can accept.
39
-     *
40
-     * @since 0.1.0
41
-     *
42
-     * @var ExtensionCollection
43
-     */
44
-    protected $extensions;
45
-
46
-    /**
47
-     * Instantiate a FilesystemLocation object.
48
-     *
49
-     * @since 0.1.0
50
-     *
51
-     * @param string                                $path       Path that this location points to.
52
-     * @param ExtensionCollection|array|string|null $extensions Optional. Extensions that this location can accept.
53
-     */
54
-    public function __construct($path, $extensions = null)
55
-    {
56
-        $this->path       = $path;
57
-        $this->extensions = $this->validateExtensions($extensions);
58
-    }
59
-
60
-    /**
61
-     * Get the first URI that matches the given criteria.
62
-     *
63
-     * @since 0.1.0
64
-     *
65
-     * @param array $criteria Criteria to match.
66
-     *
67
-     * @return string|false URI that matches the criteria or false if none found.
68
-     */
69
-    public function getURI(array $criteria)
70
-    {
71
-        foreach ($criteria as $entry) {
72
-            if ($uri = $this->transform($entry, true)) {
73
-                return $uri;
74
-            }
75
-        }
76
-
77
-        return false;
78
-    }
79
-
80
-    /**
81
-     * Get all URIs that match the given criteria.
82
-     *
83
-     * @since 0.1.1
84
-     *
85
-     * @param array $criteria Criteria to match.
86
-     *
87
-     * @return array URIs that match the criteria or empty array if none found.
88
-     */
89
-    public function getURIs(array $criteria)
90
-    {
91
-        $uris = [];
92
-
93
-        foreach ($criteria as $entry) {
94
-            if ($uri = $this->transform($entry, false)) {
95
-                $uris = array_merge($uris, (array)$uri);
96
-            }
97
-        }
98
-
99
-        return $uris;
100
-    }
101
-
102
-    /**
103
-     * Validate the extensions and return a collection.
104
-     *
105
-     * @since 0.1.1
106
-     *
107
-     * @param ExtensionCollection|array|string|null $extensions Extensions to validate.
108
-     *
109
-     * @return ExtensionCollection Validated extensions collection.
110
-     */
111
-    protected function validateExtensions($extensions)
112
-    {
113
-        if (! $extensions instanceof ExtensionCollection) {
114
-            $extensions = new ExtensionCollection((array)$extensions);
115
-        }
116
-        $extensions->add('');
117
-
118
-        return $extensions;
119
-    }
120
-
121
-    /**
122
-     * Try to transform the entry into possible URIs.
123
-     *
124
-     * @since 0.1.0
125
-     *
126
-     * @param string $entry     Entry to transform.
127
-     * @param bool   $firstOnly Return the first result only.
128
-     *
129
-     * @return array|string|false If $firstOnly is true, returns a string with the URI of the view, or false if none
130
-     *                            found.
131
-     *                            If $firstOnly is false, returns an array with all matching URIs, or an empty array if
132
-     *                            none found.
133
-     */
134
-    protected function transform($entry, $firstOnly = true)
135
-    {
136
-        $uris = [];
137
-
138
-        try {
139
-            foreach ($this->getVariants($entry) as $uri) {
140
-                if (is_readable($uri)) {
141
-                    if ($firstOnly) {
142
-                        return $uri;
143
-                    }
144
-                    $uris [] = $uri;
145
-                }
146
-            }
147
-        } catch (Exception $exception) {
148
-            // Fail silently.
149
-        }
150
-
151
-        return $firstOnly ? false : $uris;
152
-    }
153
-
154
-    /**
155
-     * Get the individual variants that could be matched for the location.
156
-     *
157
-     * @since 0.1.1
158
-     *
159
-     * @param string $entry Entry to get the variants for.
160
-     *
161
-     * @return array Array of variants to check.
162
-     */
163
-    protected function getVariants($entry)
164
-    {
165
-        $variants = [];
166
-
167
-        $this->extensions->map(function ($extension) use ($entry, &$variants) {
168
-            $variants[] = $entry . $extension;
169
-            $variants[] = $this->path . DIRECTORY_SEPARATOR . $entry . $extension;
170
-        });
171
-
172
-        return $variants;
173
-    }
28
+	/**
29
+	 * Path that this location points to.
30
+	 *
31
+	 * @since 0.1.0
32
+	 *
33
+	 * @var string
34
+	 */
35
+	protected $path;
36
+
37
+	/**
38
+	 * Extensions that this location can accept.
39
+	 *
40
+	 * @since 0.1.0
41
+	 *
42
+	 * @var ExtensionCollection
43
+	 */
44
+	protected $extensions;
45
+
46
+	/**
47
+	 * Instantiate a FilesystemLocation object.
48
+	 *
49
+	 * @since 0.1.0
50
+	 *
51
+	 * @param string                                $path       Path that this location points to.
52
+	 * @param ExtensionCollection|array|string|null $extensions Optional. Extensions that this location can accept.
53
+	 */
54
+	public function __construct($path, $extensions = null)
55
+	{
56
+		$this->path       = $path;
57
+		$this->extensions = $this->validateExtensions($extensions);
58
+	}
59
+
60
+	/**
61
+	 * Get the first URI that matches the given criteria.
62
+	 *
63
+	 * @since 0.1.0
64
+	 *
65
+	 * @param array $criteria Criteria to match.
66
+	 *
67
+	 * @return string|false URI that matches the criteria or false if none found.
68
+	 */
69
+	public function getURI(array $criteria)
70
+	{
71
+		foreach ($criteria as $entry) {
72
+			if ($uri = $this->transform($entry, true)) {
73
+				return $uri;
74
+			}
75
+		}
76
+
77
+		return false;
78
+	}
79
+
80
+	/**
81
+	 * Get all URIs that match the given criteria.
82
+	 *
83
+	 * @since 0.1.1
84
+	 *
85
+	 * @param array $criteria Criteria to match.
86
+	 *
87
+	 * @return array URIs that match the criteria or empty array if none found.
88
+	 */
89
+	public function getURIs(array $criteria)
90
+	{
91
+		$uris = [];
92
+
93
+		foreach ($criteria as $entry) {
94
+			if ($uri = $this->transform($entry, false)) {
95
+				$uris = array_merge($uris, (array)$uri);
96
+			}
97
+		}
98
+
99
+		return $uris;
100
+	}
101
+
102
+	/**
103
+	 * Validate the extensions and return a collection.
104
+	 *
105
+	 * @since 0.1.1
106
+	 *
107
+	 * @param ExtensionCollection|array|string|null $extensions Extensions to validate.
108
+	 *
109
+	 * @return ExtensionCollection Validated extensions collection.
110
+	 */
111
+	protected function validateExtensions($extensions)
112
+	{
113
+		if (! $extensions instanceof ExtensionCollection) {
114
+			$extensions = new ExtensionCollection((array)$extensions);
115
+		}
116
+		$extensions->add('');
117
+
118
+		return $extensions;
119
+	}
120
+
121
+	/**
122
+	 * Try to transform the entry into possible URIs.
123
+	 *
124
+	 * @since 0.1.0
125
+	 *
126
+	 * @param string $entry     Entry to transform.
127
+	 * @param bool   $firstOnly Return the first result only.
128
+	 *
129
+	 * @return array|string|false If $firstOnly is true, returns a string with the URI of the view, or false if none
130
+	 *                            found.
131
+	 *                            If $firstOnly is false, returns an array with all matching URIs, or an empty array if
132
+	 *                            none found.
133
+	 */
134
+	protected function transform($entry, $firstOnly = true)
135
+	{
136
+		$uris = [];
137
+
138
+		try {
139
+			foreach ($this->getVariants($entry) as $uri) {
140
+				if (is_readable($uri)) {
141
+					if ($firstOnly) {
142
+						return $uri;
143
+					}
144
+					$uris [] = $uri;
145
+				}
146
+			}
147
+		} catch (Exception $exception) {
148
+			// Fail silently.
149
+		}
150
+
151
+		return $firstOnly ? false : $uris;
152
+	}
153
+
154
+	/**
155
+	 * Get the individual variants that could be matched for the location.
156
+	 *
157
+	 * @since 0.1.1
158
+	 *
159
+	 * @param string $entry Entry to get the variants for.
160
+	 *
161
+	 * @return array Array of variants to check.
162
+	 */
163
+	protected function getVariants($entry)
164
+	{
165
+		$variants = [];
166
+
167
+		$this->extensions->map(function ($extension) use ($entry, &$variants) {
168
+			$variants[] = $entry . $extension;
169
+			$variants[] = $this->path . DIRECTORY_SEPARATOR . $entry . $extension;
170
+		});
171
+
172
+		return $variants;
173
+	}
174 174
 }
Please login to merge, or discard this patch.
src/View/Support/AbstractFinder.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
      */
151 151
     protected function initializeFindables($arguments = null)
152 152
     {
153
-        $this->findables = $this->findables->map(function ($findable) use ($arguments) {
153
+        $this->findables = $this->findables->map(function($findable) use ($arguments) {
154 154
             return $this->initializeFindable($findable, $arguments);
155 155
         });
156 156
     }
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
             $findable = $this->instantiateFindableFromCallable($findable, $arguments);
192 192
         }
193 193
 
194
-        if (! $findable instanceof Findable) {
194
+        if ( ! $findable instanceof Findable) {
195 195
             throw new FailedToInstantiateFindableException(
196 196
                 sprintf(
197 197
                     _('Could not instantiate Findable "%s".'),
Please login to merge, or discard this patch.
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -27,209 +27,209 @@
 block discarded – undo
27 27
 abstract class AbstractFinder implements FinderInterface
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 FindableCollection
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 FindableCollection();
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
-        foreach ($config->getKey($this->getFindablesConfigKey()) as $findableKey => $findableObject) {
77
-            $this->findables->set($findableKey, $findableObject);
78
-        }
79
-    }
80
-
81
-    /**
82
-     * Register the NullObject defined in the given configuration.
83
-     *
84
-     * @since 0.1.0
85
-     *
86
-     * @param ConfigInterface $config Configuration to register the NullObject from.
87
-     */
88
-    public function registerNullObject(ConfigInterface $config)
89
-    {
90
-        $this->nullObject = $config->getKey($this->getNullObjectConfigKey());
91
-    }
92
-
93
-    /**
94
-     * Get the NullObject.
95
-     *
96
-     * @since 0.1.1
97
-     *
98
-     * @return NullFindable NullObject for the current Finder.
99
-     */
100
-    public function getNullObject()
101
-    {
102
-        $this->initializeNullObject();
103
-
104
-        return $this->nullObject;
105
-    }
106
-
107
-    /**
108
-     * Get the config key for the Findables definitions.
109
-     *
110
-     * @since 0.1.0
111
-     *
112
-     * @return string Config key use to define the Findables.
113
-     */
114
-    protected function getFindablesConfigKey()
115
-    {
116
-        return 'Findables';
117
-    }
118
-
119
-    /**
120
-     * Get the config key for the NullObject definitions.
121
-     *
122
-     * @since 0.1.0
123
-     *
124
-     * @return string Config key use to define the NullObject.
125
-     */
126
-    protected function getNullObjectConfigKey()
127
-    {
128
-        return 'NullObject';
129
-    }
130
-
131
-    /**
132
-     * Initialize the NullObject.
133
-     *
134
-     * @since 0.1.1
135
-     *
136
-     * @param mixed $arguments Optional. Arguments to use.
137
-     */
138
-    protected function initializeNullObject($arguments = null)
139
-    {
140
-        $this->nullObject = $this->maybeInstantiateFindable($this->nullObject, $arguments);
141
-    }
142
-
143
-    /**
144
-     * Initialize the Findables that can be iterated.
145
-     *
146
-     * @param mixed $arguments Optional. Arguments to use.
147
-     *
148
-     * @since 0.1.0
149
-     *
150
-     */
151
-    protected function initializeFindables($arguments = null)
152
-    {
153
-        $this->findables = $this->findables->map(function ($findable) use ($arguments) {
154
-            return $this->initializeFindable($findable, $arguments);
155
-        });
156
-    }
157
-
158
-    /**
159
-     * Initialize a single findable by instantiating class name strings and calling closures.
160
-     *
161
-     * @since 0.1.0
162
-     *
163
-     * @param mixed $findable  Findable to instantiate.
164
-     * @param mixed $arguments Optional. Arguments to use.
165
-     *
166
-     * @return Findable Instantiated findable.
167
-     */
168
-    protected function initializeFindable($findable, $arguments = null)
169
-    {
170
-        return $this->maybeInstantiateFindable($findable, $arguments);
171
-    }
172
-
173
-    /**
174
-     * Maybe instantiate a Findable if it is not yet an object.
175
-     *
176
-     * @since 0.1.1
177
-     *
178
-     * @param mixed $findable  Findable to instantiate.
179
-     * @param mixed $arguments Optional. Arguments to use.
180
-     *
181
-     * @return Findable Instantiated findable.
182
-     * @throws FailedToInstantiateFindableException If the findable could not be instantiated.
183
-     */
184
-    protected function maybeInstantiateFindable($findable, $arguments = null)
185
-    {
186
-        if (is_string($findable)) {
187
-            $findable = $this->instantiateFindableFromString($findable, $arguments);
188
-        }
189
-
190
-        if (is_callable($findable)) {
191
-            $findable = $this->instantiateFindableFromCallable($findable, $arguments);
192
-        }
193
-
194
-        if (! $findable instanceof Findable) {
195
-            throw new FailedToInstantiateFindableException(
196
-                sprintf(
197
-                    _('Could not instantiate Findable "%s".'),
198
-                    serialize($findable)
199
-                )
200
-            );
201
-        }
202
-
203
-        return $findable;
204
-    }
205
-
206
-    /**
207
-     * Instantiate a Findable from a string.
208
-     *
209
-     * @since 0.1.1
210
-     *
211
-     * @param string $string    String to use for instantiation.
212
-     * @param mixed  $arguments Optional. Arguments to use for instantiation.
213
-     *
214
-     * @return Findable Instantiated Findable.
215
-     */
216
-    protected function instantiateFindableFromString($string, $arguments = null)
217
-    {
218
-        return new $string(...$arguments);
219
-    }
220
-
221
-    /**
222
-     * Instantiate a Findable from a callable.
223
-     *
224
-     * @since 0.1.1
225
-     *
226
-     * @param callable $callable  Callable to use for instantiation.
227
-     * @param mixed    $arguments Optional. Arguments to use for instantiation.
228
-     *
229
-     * @return Findable Instantiated Findable.
230
-     */
231
-    protected function instantiateFindableFromCallable($callable, $arguments = null)
232
-    {
233
-        return $callable(...$arguments);
234
-    }
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 FindableCollection
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 FindableCollection();
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
+		foreach ($config->getKey($this->getFindablesConfigKey()) as $findableKey => $findableObject) {
77
+			$this->findables->set($findableKey, $findableObject);
78
+		}
79
+	}
80
+
81
+	/**
82
+	 * Register the NullObject defined in the given configuration.
83
+	 *
84
+	 * @since 0.1.0
85
+	 *
86
+	 * @param ConfigInterface $config Configuration to register the NullObject from.
87
+	 */
88
+	public function registerNullObject(ConfigInterface $config)
89
+	{
90
+		$this->nullObject = $config->getKey($this->getNullObjectConfigKey());
91
+	}
92
+
93
+	/**
94
+	 * Get the NullObject.
95
+	 *
96
+	 * @since 0.1.1
97
+	 *
98
+	 * @return NullFindable NullObject for the current Finder.
99
+	 */
100
+	public function getNullObject()
101
+	{
102
+		$this->initializeNullObject();
103
+
104
+		return $this->nullObject;
105
+	}
106
+
107
+	/**
108
+	 * Get the config key for the Findables definitions.
109
+	 *
110
+	 * @since 0.1.0
111
+	 *
112
+	 * @return string Config key use to define the Findables.
113
+	 */
114
+	protected function getFindablesConfigKey()
115
+	{
116
+		return 'Findables';
117
+	}
118
+
119
+	/**
120
+	 * Get the config key for the NullObject definitions.
121
+	 *
122
+	 * @since 0.1.0
123
+	 *
124
+	 * @return string Config key use to define the NullObject.
125
+	 */
126
+	protected function getNullObjectConfigKey()
127
+	{
128
+		return 'NullObject';
129
+	}
130
+
131
+	/**
132
+	 * Initialize the NullObject.
133
+	 *
134
+	 * @since 0.1.1
135
+	 *
136
+	 * @param mixed $arguments Optional. Arguments to use.
137
+	 */
138
+	protected function initializeNullObject($arguments = null)
139
+	{
140
+		$this->nullObject = $this->maybeInstantiateFindable($this->nullObject, $arguments);
141
+	}
142
+
143
+	/**
144
+	 * Initialize the Findables that can be iterated.
145
+	 *
146
+	 * @param mixed $arguments Optional. Arguments to use.
147
+	 *
148
+	 * @since 0.1.0
149
+	 *
150
+	 */
151
+	protected function initializeFindables($arguments = null)
152
+	{
153
+		$this->findables = $this->findables->map(function ($findable) use ($arguments) {
154
+			return $this->initializeFindable($findable, $arguments);
155
+		});
156
+	}
157
+
158
+	/**
159
+	 * Initialize a single findable by instantiating class name strings and calling closures.
160
+	 *
161
+	 * @since 0.1.0
162
+	 *
163
+	 * @param mixed $findable  Findable to instantiate.
164
+	 * @param mixed $arguments Optional. Arguments to use.
165
+	 *
166
+	 * @return Findable Instantiated findable.
167
+	 */
168
+	protected function initializeFindable($findable, $arguments = null)
169
+	{
170
+		return $this->maybeInstantiateFindable($findable, $arguments);
171
+	}
172
+
173
+	/**
174
+	 * Maybe instantiate a Findable if it is not yet an object.
175
+	 *
176
+	 * @since 0.1.1
177
+	 *
178
+	 * @param mixed $findable  Findable to instantiate.
179
+	 * @param mixed $arguments Optional. Arguments to use.
180
+	 *
181
+	 * @return Findable Instantiated findable.
182
+	 * @throws FailedToInstantiateFindableException If the findable could not be instantiated.
183
+	 */
184
+	protected function maybeInstantiateFindable($findable, $arguments = null)
185
+	{
186
+		if (is_string($findable)) {
187
+			$findable = $this->instantiateFindableFromString($findable, $arguments);
188
+		}
189
+
190
+		if (is_callable($findable)) {
191
+			$findable = $this->instantiateFindableFromCallable($findable, $arguments);
192
+		}
193
+
194
+		if (! $findable instanceof Findable) {
195
+			throw new FailedToInstantiateFindableException(
196
+				sprintf(
197
+					_('Could not instantiate Findable "%s".'),
198
+					serialize($findable)
199
+				)
200
+			);
201
+		}
202
+
203
+		return $findable;
204
+	}
205
+
206
+	/**
207
+	 * Instantiate a Findable from a string.
208
+	 *
209
+	 * @since 0.1.1
210
+	 *
211
+	 * @param string $string    String to use for instantiation.
212
+	 * @param mixed  $arguments Optional. Arguments to use for instantiation.
213
+	 *
214
+	 * @return Findable Instantiated Findable.
215
+	 */
216
+	protected function instantiateFindableFromString($string, $arguments = null)
217
+	{
218
+		return new $string(...$arguments);
219
+	}
220
+
221
+	/**
222
+	 * Instantiate a Findable from a callable.
223
+	 *
224
+	 * @since 0.1.1
225
+	 *
226
+	 * @param callable $callable  Callable to use for instantiation.
227
+	 * @param mixed    $arguments Optional. Arguments to use for instantiation.
228
+	 *
229
+	 * @return Findable Instantiated Findable.
230
+	 */
231
+	protected function instantiateFindableFromCallable($callable, $arguments = null)
232
+	{
233
+		return $callable(...$arguments);
234
+	}
235 235
 }
Please login to merge, or discard this patch.