1 | <?php |
||
16 | class ReaderBuilder implements ReaderBuilderInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var EventDispatcherInterface |
||
20 | */ |
||
21 | protected $eventDispatcher; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $destinationDir; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $readerType; |
||
32 | |||
33 | /** |
||
34 | * @var array<string, ResourceTransformer[]> |
||
35 | */ |
||
36 | protected $transformers = []; |
||
37 | |||
38 | /** |
||
39 | * @param EventDispatcherInterface $dispatcher |
||
40 | * @param string $destinationDir |
||
41 | */ |
||
42 | 4 | public function __construct(EventDispatcherInterface $dispatcher, $destinationDir) |
|
47 | |||
48 | /** |
||
49 | * @inheritdoc |
||
50 | */ |
||
51 | 4 | public function build(ReaderTypeInterface $type, array $transportConfig, $resourceType, array $options) |
|
52 | { |
||
53 | 4 | $resolver = $this->getOptionsResolver($type); |
|
54 | |||
55 | 4 | $transport = $this->createTransport($transportConfig, $this->destinationDir, $this->eventDispatcher); |
|
56 | 4 | $resources = new ResourceCollection([new FileResource($transport)]); |
|
57 | |||
58 | 4 | $type->build($this, $resolver->resolve($options)); |
|
59 | |||
60 | 4 | if (isset($this->transformers[$resourceType])) { |
|
61 | 4 | foreach ($this->transformers[$resourceType] as $transformer) { |
|
62 | 4 | $resources->addTransformer($transformer); |
|
63 | } |
||
64 | } |
||
65 | |||
66 | 4 | switch ($this->readerType) { |
|
67 | 4 | case self::READER_TYPE_JSONLINES: |
|
68 | return new JsonLinesReader($resources, $this->eventDispatcher); |
||
69 | break; |
||
|
|||
70 | |||
71 | 4 | case self::READER_TYPE_XML: |
|
72 | // xml is the default, let it fall through |
||
73 | default: |
||
74 | 4 | return new XmlReader($resources, $this->eventDispatcher); |
|
75 | } |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @inheritdoc |
||
80 | */ |
||
81 | public function addResourceTransformer(ResourceTransformerInterface $transformer) |
||
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | 4 | public function addPartResourceTransformer(ResourceTransformerInterface $transformer) |
|
93 | |||
94 | /** |
||
95 | * @inheritdoc |
||
96 | */ |
||
97 | public function setReaderType($type) |
||
101 | |||
102 | /** |
||
103 | * @param ReaderTypeInterface $type |
||
104 | * |
||
105 | * @return OptionsResolver |
||
106 | */ |
||
107 | 4 | protected function getOptionsResolver(ReaderTypeInterface $type) |
|
114 | |||
115 | /** |
||
116 | * @param array $transportConfig |
||
117 | * @param string $destinationDir |
||
118 | * @param EventDispatcherInterface $dispatcher |
||
119 | * |
||
120 | * @return TransportInterface |
||
121 | */ |
||
122 | 4 | protected function createTransport(array $transportConfig, $destinationDir, EventDispatcherInterface $dispatcher) |
|
130 | } |
||
131 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.