Conditions | 5 |
Paths | 3 |
Total Lines | 26 |
Code Lines | 16 |
Lines | 6 |
Ratio | 23.08 % |
Changes | 0 |
1 | <?php |
||
22 | public function createView(ViewFactory $factory, $data, array $options): ViewInterface |
||
23 | { |
||
24 | View Code Duplication | if (!is_array($data) && !$data instanceof \Traversable) { |
|
|
|||
25 | throw new \InvalidArgumentException(sprintf( |
||
26 | 'Data must be traversable or an array, got: "%s"', |
||
27 | is_object($data) ? get_class($data) : gettype($data) |
||
28 | )); |
||
29 | } |
||
30 | |||
31 | if (is_array($data)) { |
||
32 | $data = new \ArrayIterator($data); |
||
33 | } |
||
34 | |||
35 | $field = $this->fieldLoader->load( |
||
36 | $options['field_type'], |
||
37 | $options['field_options'] |
||
38 | ); |
||
39 | |||
40 | return new CollectionView( |
||
41 | $options['template'], |
||
42 | $factory, |
||
43 | $data, |
||
44 | $field->getViewType(), |
||
45 | $field->getViewOptions() |
||
46 | ); |
||
47 | } |
||
48 | |||
58 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.