I'm replacing my dryer. Old one came with the house.
There is a NM 10/3 plus ground cable coming out of the floor of the laundry closet with about 4 feet loose in the closet, and attached to a 4-pin dryer socket in a metal box.
I was pleasantly surprised to find a 4-pin outlet, with ground wire, and it was properly wired inside the box with ground screwed to the box. But the box was just loose on the floor and is made of a too-shallow box with an extension.
I'd like to attach the cable to a wall with screw-on plastic cable clips and screw the box to the wall.
Is that ok? Is there any reason I should replace the box with a single deeper one rather than one with an extension? It seems inelegant but aside from that I see no reason to take it all apart just to put it in a one-piece box.
I know there shouldn't be exposed NM but there is. It's inside a closet behind the laundry machine. I could shove it into the floor into the basement ceiling joists but then the socket will remain at floor level, which really bothers me.
EDIT with more info
The question about the box extension has been answered but other concerns raised about routing and clamping of the cable so I'm adding some info here. First, a wider picture:
The area of the floor to the left of the red line is in an exterior overhanging bay structure. Getting underneath the floor there would be very very hard. However I may be able to reroute the cable by digging through the festival of foam and into the adjacent wall. I'll look into that. If too difficult I'll use surface raceway as suggested in the accepted answer.
I'm not too concerned about damage to the cable by the machine because the cable is protected by the PVC drain and some extra framing on that wall, put there to support the closet door. Still, raceway is easy and a good idea.