| Conditions | 6 |
| Paths | 5 |
| Total Lines | 20 |
| Lines | 3 |
| Ratio | 15 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | public function entity_jsonld( $jsonld, $post_id ) { |
||
| 26 | |||
| 27 | // Bail out if it's not a Product or the offers property isn't set. |
||
| 28 | if ( ! in_array( 'Product', (array) $jsonld['@type'] ) || ! isset( $jsonld['offers'] ) ) { |
||
| 29 | return $jsonld; |
||
| 30 | } |
||
| 31 | |||
| 32 | View Code Duplication | if ( ! is_array( $jsonld['offers'] ) || ! is_numeric( key( $jsonld['offers'] ) ) ) { |
|
|
|
|||
| 33 | $jsonld['offers'] = array( $jsonld['offers'] ); |
||
| 34 | } |
||
| 35 | |||
| 36 | $product = new Product( $post_id ); |
||
| 37 | |||
| 38 | foreach ( $jsonld['offers'] as &$offer ) { |
||
| 39 | $this->shipping_zones->add_available_delivery_method( $offer ); |
||
| 40 | $this->shipping_zones->add_offer_shipping_details( $offer, $product ); |
||
| 41 | } |
||
| 42 | |||
| 43 | return $jsonld; |
||
| 44 | } |
||
| 45 | |||
| 47 |
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.