Sending digital information over a wire requires a 'modulation' scheme; ie a way to represent a zero or one.
Electrical
NRZ (Non Return to Zero) is the most common modulation scheme and is what is used for S/PDIF. One voltage represents a one and another lower voltage represents a zero [positive logic NRZ]. There are no intermediate values, which is why it is called non-return to zero.
So if +5 volts is a one and +2 volts is a zero, then to send 101, a 'pulse' of +5 volts is followed by a pulse of +2 volts is followed by a pulse of +5 volts. The 'pulse' is how long that voltage level persists.
If the cable is damaged or is affected by rfi/emi interference (ie 'poorly constructed') then it may interfere with the levels and/or timing seen by the receiving device. For example, if the device sees a voltage of +3 volts, should it interpret it as 1 with too low a voltage or as a zero with too high a voltage?
Optical
Optical is far easier to explain with an analogy. If the sender and receiver agree that a zero is a .5 second pulse of light and a one is a 1 second pulse of light, then all you have to do to ensure the message is received correctly is to make sure your pulses are exactly .5 seconds or 1 second long (with an agreed upon time between each 'bit' so the receiver can distinguish when one ends and another begins). [The pulses are far shorter than that for digital audio].
The pulses of light travel down the cable because of the principle of 'total internal reflection'. If the cable is bent severely or is made poorly and some of the light escapes the tunnel it is travelling down, it won't propagate down the tunnel with the correct timing. So again, if the receiving devices thinks it sees a pulse that is .75 seconds long, was that meant to be a zero but the pulse was too long or was it meant to be a one and the pulse was too short?
So cables CAN affect the transmission of digital audio but generally only if they are broken or really poorly made. Small errors can often be corrected but over the short distances and fairly low bitrate of audio, errors are practically nonexistent.