Rather than both:

  (! empty( $metadata ) ) && isset( $metadata['duration'] )

you can just use empty which works for both:

  !empty( $metadata['duration'] )