1515use ScriptFUSION \Porter \Provider \ProviderFactory ;
1616use ScriptFUSION \Porter \Provider \Resource \ProviderResource ;
1717use ScriptFUSION \Porter \Specification \ImportSpecification ;
18+ use ScriptFUSION \Porter \Transform \Transformer ;
1819use ScriptFUSION \Retry \ExceptionHandler \ExponentialBackoffExceptionHandler ;
1920
2021/**
@@ -72,13 +73,7 @@ public function import(ImportSpecification $specification)
7273 $ records = $ this ->createProviderRecords ($ records , $ specification ->getResource ());
7374 }
7475
75- foreach ($ specification ->getTransformers () as $ transformer ) {
76- if ($ transformer instanceof PorterAware) {
77- $ transformer ->setPorter ($ this );
78- }
79-
80- $ records = $ transformer ->transform ($ records , $ specification ->getContext ());
81- }
76+ $ records = $ this ->transformRecords ($ records , $ specification ->getTransformers (), $ specification ->getContext ());
8277
8378 return $ this ->createPorterRecords ($ records , $ specification );
8479 }
@@ -109,27 +104,10 @@ public function importOne(ImportSpecification $specification)
109104 return $ one ;
110105 }
111106
112- private function createProviderRecords (\Iterator $ records , ProviderResource $ resource )
113- {
114- if ($ records instanceof \Countable) {
115- return new CountableProviderRecords ($ records , count ($ records ), $ resource );
116- }
117-
118- return new ProviderRecords ($ records , $ resource );
119- }
120-
121- private function createPorterRecords (RecordCollection $ records , ImportSpecification $ specification )
122- {
123- if ($ records instanceof \Countable) {
124- return new CountablePorterRecords ($ records , count ($ records ), $ specification );
125- }
126-
127- return new PorterRecords ($ records , $ specification );
128- }
129-
130107 private function fetch (ProviderResource $ resource , CacheAdvice $ cacheAdvice = null )
131108 {
132109 $ provider = $ this ->getProvider ($ resource ->getProviderClassName (), $ resource ->getProviderTag ());
110+
133111 $ this ->applyCacheAdvice ($ provider , $ cacheAdvice ?: $ this ->defaultCacheAdvice );
134112
135113 if (($ records = \ScriptFUSION \Retry \retry (
@@ -152,6 +130,44 @@ function (\Exception $exception) {
152130 throw new ImportException (get_class ($ provider ) . '::fetch() did not return an Iterator. ' );
153131 }
154132
133+ /**
134+ * @param RecordCollection $records
135+ * @param Transformer[] $transformers
136+ * @param mixed $context
137+ *
138+ * @return RecordCollection
139+ */
140+ private function transformRecords (RecordCollection $ records , array $ transformers , $ context )
141+ {
142+ foreach ($ transformers as $ transformer ) {
143+ if ($ transformer instanceof PorterAware) {
144+ $ transformer ->setPorter ($ this );
145+ }
146+
147+ $ records = $ transformer ->transform ($ records , $ context );
148+ }
149+
150+ return $ records ;
151+ }
152+
153+ private function createProviderRecords (\Iterator $ records , ProviderResource $ resource )
154+ {
155+ if ($ records instanceof \Countable) {
156+ return new CountableProviderRecords ($ records , count ($ records ), $ resource );
157+ }
158+
159+ return new ProviderRecords ($ records , $ resource );
160+ }
161+
162+ private function createPorterRecords (RecordCollection $ records , ImportSpecification $ specification )
163+ {
164+ if ($ records instanceof \Countable) {
165+ return new CountablePorterRecords ($ records , count ($ records ), $ specification );
166+ }
167+
168+ return new PorterRecords ($ records , $ specification );
169+ }
170+
155171 private function applyCacheAdvice (Provider $ provider , CacheAdvice $ cacheAdvice )
156172 {
157173 try {
@@ -223,7 +239,7 @@ public function getProvider($name, $tag = null)
223239 return $ provider ;
224240 }
225241 } catch (ObjectNotCreatedException $ exception ) {
226- // Intentionally empty .
242+ // We will throw our own exception .
227243 }
228244
229245 throw new ProviderNotFoundException (
0 commit comments