Skip to content

Commit aea469b

Browse files
committed
Small refactor
1 parent bca756f commit aea469b

File tree

5 files changed

+30
-57
lines changed

5 files changed

+30
-57
lines changed

src/Loader/LoaderProvider.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ public function __construct($options, $default_loaders)
5858
*/
5959
private function makeLoaders($options, $default_loaders)
6060
{
61+
$loaders = $this->preParseLoaders($options, $default_loaders);
6162
$parsed_loaders = array();
6263

63-
foreach ($options['loaders'] as $loader) {
64+
foreach ($loaders as $loader) {
6465
if ($loader === 'default') {
6566
$parsed_loaders = array_merge($parsed_loaders, $default_loaders);
6667
} else {
@@ -74,14 +75,36 @@ private function makeLoaders($options, $default_loaders)
7475
$this->extensions = $this->makeExtensions($this->loaders);
7576
}
7677

78+
/**
79+
* Pre parse the loaders for use in make loaders
80+
*
81+
* @param array|null $options The options being used for Vars
82+
* @param array $default_loaders The default loaders for Vars
83+
*
84+
* @return array The pre parsed loaders
85+
*/
86+
private function preParseLoaders($options, $default_loaders)
87+
{
88+
$loaders = array();
89+
90+
if (is_array($options['loaders']) && !empty($options['loaders'])) {
91+
$loaders = $options['loaders'];
92+
} elseif (is_string($options['loaders'])) {
93+
$loaders[] = $options['loaders'];
94+
} else {
95+
$loaders = $default_loaders;
96+
}
97+
98+
return $loaders;
99+
}
100+
77101
/**
78102
* Makes namespace loaders from loader strings
79103
*
80104
* @param array $loaders The options being used for Vars
81105
* @param array $default_loaders The default loaders for Vars
82106
*
83107
* @throws \InvalidArgumentException If a loader from options isn't found
84-
* @throws \InvalidArgumentException If no loaders were loaded
85108
*
86109
* @return array The namespace loaders
87110
*/
@@ -101,13 +124,6 @@ private function makeNameSpaceLoaders($loaders, $default_loaders)
101124
$parsed_loaders[] = $loader;
102125
}
103126

104-
// @codeCoverageIgnoreStart
105-
if (empty($parsed_loaders)) {
106-
throw new \InvalidArgumentException('No loaders were loaded');
107-
}
108-
// @codeCoverageIgnoreEnd
109-
110-
111127
return $parsed_loaders;
112128
}
113129

src/Resource/FileResource.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,6 @@ private function createImportName($resource)
286286
$resource_pieces = array();
287287

288288
foreach ($resource as $r) {
289-
//$suppress = false;
290-
//$recursive = false;
291-
//
292-
////if ($this->checkSuppression($r)) {
293-
//// $suppress = true;
294-
//// $r = trim($r, "@");
295-
////}
296-
////
297-
////if ($this->checkRecursive($r)) {
298-
//// $recursive = true;
299-
//// $r = trim($r, "*");
300-
////}
301-
////
302-
////$r = $this->removeFlags($r);
303-
304289
$parsed_r = $this->trimFlags($r);
305290
$parsed_r = sprintf('%s/%s', dirname($this->file), $parsed_r);
306291
$parsed_r = $this->replicateFlags($parsed_r, $r);
@@ -309,7 +294,6 @@ private function createImportName($resource)
309294
}
310295

311296
return $this->implodeResourceIfElse($resource_pieces);
312-
313297
}
314298

315299
/**

src/Resource/ResourceProvider.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,21 +174,11 @@ private function processEntity($entity, $type)
174174
private function parseEntity($entity)
175175
{
176176
$files = $this->explodeResourceIfElse($entity);
177-
$recursive = $this->recursive;
178177

179178
foreach ($files as $f) {
180-
$this->suppress_file_exceptions = false;
181-
$this->recursive = $recursive;
182-
183-
if ($this->checkSuppression($f)) {
184-
$f = trim($f, "@");
185-
$this->suppress_file_exceptions = true;
186-
}
187-
188-
if ($this->checkRecursive($f)) {
189-
$f = trim($f, "*");
190-
$this->recursive = true;
191-
}
179+
$this->suppress_file_exceptions = $this->checkSuppression($f);
180+
$this->recursive = $this->checkRecursive($f);
181+
$f = $this->trimFlags($f);
192182

193183
if (file_exists($f) || !isset($files[1])) {
194184
return $f;

src/Vars.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,7 @@ public function __construct($resource, $options = array())
133133
private function parseOptions(array $options)
134134
{
135135
$parsed_options = array_merge($this->default_options, $options);
136-
137-
if (isset($options['loaders'])) {
138-
$loaders = array();
139-
140-
if (is_array($options['loaders']) && !empty($options['loaders'])) {
141-
$loaders = $options['loaders'];
142-
} elseif (is_string($options['loaders'])) {
143-
$loaders[] = $options['loaders'];
144-
} else {
145-
$loaders = $this->default_options['loaders'];
146-
}
147-
148-
$parsed_options['loaders'] = $loaders;
149-
} else {
150-
$parsed_options['loaders'] = $this->default_options['loaders'];
151-
}
152-
136+
$parsed_options['loaders'] = (isset($options['loaders'])) ? $options['loaders'] : $this->default_options['loaders'];
153137
return $parsed_options;
154138
}
155139

tests/VarsTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,7 @@ public function testImportDirImporting()
350350
{
351351
$expected = array(
352352
'test_key_1' => array(
353-
'test_key_2' => 'test_value_2',
354-
'test_key_3' => 'test_value_3',
353+
'test_key_2' => 'test_value_2'
355354
),
356355
);
357356

0 commit comments

Comments
 (0)