With a situation like this, there could be several issues. You need to take the controller apart and look to see where the water damage exists. Clean any corrosion up with a q-tip and isopropyl alcohol. Be gentle when you clean it though.
The old analog stick needs to be de-soldered and removed and a new analog stick needs to be soldered on. If this does not correct the issue, then the conductive film needs to be replaced. The conductive film is the thin plastic film that the ps4’s d-pad and other buttons make contact with in order to register they are being pressed. Sometimes the film malfunctions and causes the controller to act in erratic ways that don’t actually make any sense. This was similar to the way the PS3’s controller would act erratic when there was not enough contact being made between the film and the contact points on the controller.