Hint : You could have factor the 2 conditions this way :

```php
foreach ( array( 'data', 'externalData' ) as $property )
{
    if (
        !empty( $field->value->$property ) &&
        is_string( $field->value->$property ) &&
        strpos( $field->value->$property, self::FIELD_VALUE_DOM_DOCUMENT_KEY ) === 0
    )
    {
        // Do your stuff
    }
}
```