Skip to content

Commit c9b3308

Browse files
committed
Changed AnysyncTransformer to @internal.
Avoided exposing AynsyncTransformer on any public interface, using concrete Transformer types instead. Added and rewrote some public method docblocks.
1 parent fd79d5a commit c9b3308

15 files changed

+82
-79
lines changed

src/Connector/AsyncConnector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
use Amp\Promise;
77

88
/**
9-
* Provides a method for fetching data from a source asynchronously.
9+
* Provides a method for fetching data from a data source asynchronously.
1010
*/
1111
interface AsyncConnector
1212
{
1313
/**
14-
* Fetches data from the specified source.
14+
* Fetches data asynchronously from the specified data source.
1515
*
16-
* @param DataSource $source Source.
16+
* @param DataSource $source Data source.
1717
*
1818
* @return Promise<mixed> Data.
1919
*/

src/Connector/Connector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
namespace ScriptFUSION\Porter\Connector;
55

66
/**
7-
* Provides a method for fetching data from a source.
7+
* Provides a method for fetching data from a data source.
88
*/
99
interface Connector
1010
{
1111
/**
12-
* Fetches data from the specified source.
12+
* Fetches data from the specified data source.
1313
*
14-
* @param DataSource $source Source.
14+
* @param DataSource $source Data source.
1515
*
1616
* @return mixed Data.
1717
*/

src/Connector/ImportConnector.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ public function __construct(
6666
$this->maxFetchAttempts = $maxFetchAttempts;
6767
}
6868

69+
/**
70+
* Fetches data from the specified data source.
71+
*
72+
* @param DataSource $source Data source.
73+
*
74+
* @return mixed Data.
75+
*/
6976
public function fetch(DataSource $source)
7077
{
7178
return retry(
@@ -77,6 +84,13 @@ function () use ($source) {
7784
);
7885
}
7986

87+
/**
88+
* Fetches data asynchronously from the specified data source.
89+
*
90+
* @param DataSource $source Data source.
91+
*
92+
* @return Promise<mixed> Data.
93+
*/
8094
public function fetchAsync(DataSource $source): Promise
8195
{
8296
return retryAsync(
@@ -145,7 +159,7 @@ private static function invokeHandler(
145159
}
146160

147161
/**
148-
* Gets the wrapped connector. Useful for resources to reconfigure connector options during this import.
162+
* Gets the wrapped connector.
149163
*
150164
* @return Connector|AsyncConnector Wrapped connector.
151165
*/

src/Porter.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use function Amp\call;
2929

3030
/**
31-
* Imports data from a provider defined in the providers container or internal factory.
31+
* Imports data from a provider defined in the container of providers or the internal factory.
3232
*/
3333
class Porter
3434
{
@@ -53,11 +53,12 @@ public function __construct(ContainerInterface $providers)
5353
}
5454

5555
/**
56-
* Imports data according to the design of the specified import specification.
56+
* Imports a one or more records from the resource contained in the specified import specification.
5757
*
5858
* @param ImportSpecification $specification Import specification.
5959
*
60-
* @return PorterRecords|CountablePorterRecords
60+
* @return PorterRecords|CountablePorterRecords Collection of records. If the total size of the collection is known,
61+
* the collection may implement Countable, otherwise PorterRecords is returned.
6162
*/
6263
public function import(ImportSpecification $specification): PorterRecords
6364
{
@@ -75,7 +76,7 @@ public function import(ImportSpecification $specification): PorterRecords
7576
}
7677

7778
/**
78-
* Imports one record according to the design of the specified import specification.
79+
* Imports one record from the resource contained in the specified import specification.
7980
*
8081
* @param ImportSpecification $specification Import specification.
8182
*
@@ -122,11 +123,13 @@ private function fetch(ImportSpecification $specification): \Iterator
122123
}
123124

124125
/**
125-
* Imports data asynchronously according to the design of the specified asynchronous import specification.
126+
* Imports one or more records asynchronously from the resource contained in the specified asynchronous import
127+
* specification.
126128
*
127129
* @param AsyncImportSpecification $specification Asynchronous import specification.
128130
*
129-
* @return AsyncPorterRecords|CountableAsyncPorterRecords
131+
* @return AsyncPorterRecords|CountableAsyncPorterRecords Collection of records. If the total size of the
132+
* collection is known, the collection may implement Countable, otherwise AsyncPorterRecords is returned.
130133
*/
131134
public function importAsync(AsyncImportSpecification $specification): AsyncRecordCollection
132135
{
@@ -148,11 +151,11 @@ public function importAsync(AsyncImportSpecification $specification): AsyncRecor
148151
}
149152

150153
/**
151-
* Imports one record according to the design of the specified asynchronous import specification.
154+
* Imports one record from the resource contained in the specified asynchronous import specification.
152155
*
153156
* @param AsyncImportSpecification $specification Asynchronous import specification.
154157
*
155-
* @return Promise Promise that resolves to a record.
158+
* @return Promise<array|null> Record.
156159
*/
157160
public function importOneAsync(AsyncImportSpecification $specification): Promise
158161
{
@@ -265,7 +268,7 @@ private function createAsyncPorterRecords(
265268
*
266269
* @param string $name Provider name.
267270
*
268-
* @return Provider|AsyncProvider
271+
* @return Provider|AsyncProvider Provider.
269272
*
270273
* @throws ProviderNotFoundException The specified provider was not found.
271274
*/

src/Provider/AsyncProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
interface AsyncProvider
1212
{
1313
/**
14-
* Gets a connector for accessing resource data.
14+
* Gets an asynchronous connector compatible with this provider's resources.
1515
*/
1616
public function getAsyncConnector(): AsyncConnector;
1717
}

src/Provider/Provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
interface Provider
1212
{
1313
/**
14-
* Gets a connector for accessing resource data.
14+
* Gets a connector compatible with this provider's resources.
1515
*/
1616
public function getConnector(): Connector;
1717
}

src/Provider/Resource/AsyncResource.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Amp\Iterator;
77
use ScriptFUSION\Porter\Connector\ImportConnector;
88

9+
/**
10+
* Defines methods for fetching data.
11+
*/
912
interface AsyncResource
1013
{
1114
/**
@@ -16,7 +19,7 @@ interface AsyncResource
1619
public function getProviderClassName(): string;
1720

1821
/**
19-
* Fetches data from the provider using the the specified connector and presents its data as an enumerable series.
22+
* Fetches data using the the specified connector and presents its data as an enumerable series.
2023
*
2124
* @param ImportConnector $connector Connector.
2225
*

src/Provider/Resource/ProviderResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use ScriptFUSION\Porter\Connector\ImportConnector;
77

88
/**
9-
* Defines methods for fetching data from a specific provider resource.
9+
* Defines methods for fetching data.
1010
*/
1111
interface ProviderResource
1212
{
@@ -18,7 +18,7 @@ interface ProviderResource
1818
public function getProviderClassName(): string;
1919

2020
/**
21-
* Fetches data from the provider using the the specified connector and presents it as an iterable series.
21+
* Fetches data using the the specified connector and presents it as an iterable series.
2222
*
2323
* @param ImportConnector $connector Connector.
2424
*

src/Specification/AsyncImportSpecification.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
use ScriptFUSION\Porter\Connector\Recoverable\ExponentialAsyncDelayRecoverableExceptionHandler;
77
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableExceptionHandler;
88
use ScriptFUSION\Porter\Provider\Resource\AsyncResource;
9-
use ScriptFUSION\Porter\Transform\AnysyncTransformer;
109
use ScriptFUSION\Porter\Transform\AsyncTransformer;
1110

1211
/**
13-
* Specifies which resource to import asynchronously and how the data should be transformed.
12+
* Specifies which resource to import asynchronously, how it should be imported and how the data will be transformed.
1413
*/
1514
class AsyncImportSpecification extends Specification
1615
{
1716
private $asyncResource;
1817

18+
/**
19+
* Initializes this instance with the specified asynchronous resource.
20+
*
21+
* @param AsyncResource $resource Asynchronous resource.
22+
*/
1923
public function __construct(AsyncResource $resource)
2024
{
2125
$this->asyncResource = $resource;
@@ -30,20 +34,19 @@ public function __clone()
3034
parent::__clone();
3135
}
3236

37+
/**
38+
* Gets the asynchronous resource to import.
39+
*
40+
* @return AsyncResource Asynchronous resource.
41+
*/
3342
final public function getAsyncResource(): AsyncResource
3443
{
3544
return $this->asyncResource;
3645
}
3746

38-
final public function addTransformer(AnysyncTransformer $transformer): Specification
47+
final public function addTransformer(AsyncTransformer $transformer): self
3948
{
40-
if (!$transformer instanceof AsyncTransformer) {
41-
throw new IncompatibleTransformerException(
42-
'Transformer does not implement interface: ' . AsyncTransformer::class . '.'
43-
);
44-
}
45-
46-
return parent::addTransformer($transformer);
49+
return parent::addAnyTransformer($transformer);
4750
}
4851

4952
protected static function createDefaultRecoverableExceptionHandler(): RecoverableExceptionHandler

src/Specification/ImportSpecification.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
use ScriptFUSION\Porter\Connector\Recoverable\ExponentialSleepRecoverableExceptionHandler;
77
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableExceptionHandler;
88
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
9-
use ScriptFUSION\Porter\Transform\AnysyncTransformer;
109
use ScriptFUSION\Porter\Transform\Transformer;
1110

1211
/**
13-
* Specifies which resource to import and how the data should be transformed.
12+
* Specifies which resource to import, how it should be imported and how the data will be transformed.
1413
*/
1514
class ImportSpecification extends Specification
1615
{
17-
/**
18-
* @var ProviderResource
19-
*/
2016
private $resource;
2117

18+
/**
19+
* Initializes this instance with the specified resource.
20+
*
21+
* @param ProviderResource $resource Resource.
22+
*/
2223
public function __construct(ProviderResource $resource)
2324
{
2425
$this->resource = $resource;
@@ -34,22 +35,25 @@ public function __clone()
3435
}
3536

3637
/**
37-
* @return ProviderResource
38+
* Gets the resource to import.
39+
*
40+
* @return ProviderResource Resource.
3841
*/
3942
final public function getResource(): ProviderResource
4043
{
4144
return $this->resource;
4245
}
4346

44-
final public function addTransformer(AnysyncTransformer $transformer): Specification
47+
/**
48+
* Adds the specified transformer to the end of the transformers queue.
49+
*
50+
* @param Transformer $transformer Transformer.
51+
*
52+
* @return $this
53+
*/
54+
final public function addTransformer(Transformer $transformer): self
4555
{
46-
if (!$transformer instanceof Transformer) {
47-
throw new IncompatibleTransformerException(
48-
'Transformer does not implement interface: ' . Transformer::class . '.'
49-
);
50-
}
51-
52-
return parent::addTransformer($transformer);
56+
return parent::addAnyTransformer($transformer);
5357
}
5458

5559
protected static function createDefaultRecoverableExceptionHandler(): RecoverableExceptionHandler

src/Specification/IncompatibleTransformerException.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Specification/Specification.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,17 @@ abstract class Specification
1010
{
1111
public const DEFAULT_FETCH_ATTEMPTS = 5;
1212

13-
/**
14-
* @var string|null
15-
*/
13+
/** @var string|null */
1614
private $providerName;
1715

18-
/**
19-
* @var AnysyncTransformer[]
20-
*/
16+
/** @var AnysyncTransformer[] */
2117
private $transformers;
2218

23-
/**
24-
* @var mixed
25-
*/
19+
/** @var mixed */
2620
private $context;
2721

28-
/**
29-
* @var bool
30-
*/
3122
private $mustCache = false;
3223

33-
/**
34-
* @var int
35-
*/
3624
private $maxFetchAttempts = self::DEFAULT_FETCH_ATTEMPTS;
3725

3826
/**
@@ -95,13 +83,13 @@ final public function getTransformers(): array
9583
}
9684

9785
/**
98-
* Adds the specified transformer.
86+
* Adds the specified transformer of any sync type.
9987
*
10088
* @param AnysyncTransformer $transformer Transformer.
10189
*
10290
* @return $this
10391
*/
104-
protected function addTransformer(AnysyncTransformer $transformer): self
92+
final protected function addAnyTransformer(AnysyncTransformer $transformer): self
10593
{
10694
if ($this->hasTransformer($transformer)) {
10795
throw new DuplicateTransformerException('Transformer already added.');
@@ -122,7 +110,7 @@ protected function addTransformer(AnysyncTransformer $transformer): self
122110
final public function addTransformers(array $transformers): self
123111
{
124112
foreach ($transformers as $transformer) {
125-
$this->addTransformer($transformer);
113+
$this->addAnyTransformer($transformer);
126114
}
127115

128116
return $this;

src/Transform/AnysyncTransformer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
/**
77
* Marker interface that specifies a transformer that is synchronous, asynchronous or both.
8+
*
9+
* @internal
810
*/
911
interface AnysyncTransformer
1012
{

0 commit comments

Comments
 (0)