The Phillies have spent this week planting bamboo trees in their clubhouse, accepting good-luck charms from fans, and doing whatever else they could to regain the mojo that had carried them to the top of the National League East through May.

It’s impossible to say if any of the rituals really played a role, but the 20 runs and 27 hits they posted in consecutive victories over the New York Mets sure made things fun for a couple of nights again.

The magic continued Wednesday night with a 5-4, 10-inning victory over the Mets after the Phillies had been placed in a four-run hole by righthander Nick Pivetta. As uplifting as the Phillies’ first walk-off win of the year was for a team that had recently lost seven in a row, Pivetta’s performance still created more doubt about the starting rotation.

“I don’t think it was his best outing,” manager Gabe Kapler said. “I certainly want to talk to Nick about maintaining his composure a little bit, particularly about some of the calls at the plate. I think he can do a better job of keeping his emotions in check. When he keeps his emotions in check, he doesn’t allow one pitch to spill into the next and he’s a much better pitcher.”

After being exiled to triple-A Lehigh Valley for a month, the Phillies gave Pivetta the ball again the day after Memorial Day. He responded with five solid innings in a win over St. Louis. Then he pitched six sensational innings against the mighty Los Angeles Dodgers. When he followed that with a complete-game victory over the Cincinnati Reds, it sure looked as if Pivetta had tapped into something and maybe even turned a career corner.

Three starts later, he has given the Phillies a reason to think about replacing him again, although Kapler said Pivetta will remain in the rotation.

“I think it’s a matter of saying the right things to Nick to help him get back on track,” the manager said. “I think that’s going to take a little work before we find what those things are, but certainly Nick has shown since he has been back from Lehigh Valley that he deserves his spot in the rotation and he has earned it.”

Pivetta’s last pitch Wednesday night against the Mets was a biting curveball that left rookie slugger Pete Alonso helplessly flailing at a third strike. It was a good breaking ball on a night when he threw two really bad ones.

Alonso was the second out of the sixth inning and Pivetta was visibly disturbed that it was his final out. But manager Gabe Kapler decided to give the ball to lefty Jose Alvarez in an attempt to keep the Mets from adding to their four-run lead. It did not go unnoticed that Pivetta exited in a huff.

“I think Nick at that point was just in a hurry to get off the mound,” Kapler said. “I’ll talk to him about pausing for one more second before he rushes off. That’s the most professional way to handle getting taken out of a game.”

Pivetta said Kapler made the right decision to remove him. In fact, it was a vital one that allowed the Phillies to get back into the game. Alvarez retired Robinson Cano and got three more outs in the seventh while the Phillies rallied to even the score at 4-4 with Jean Segura playing the leading role with a solo homer in the sixth and a two-run single that tied the game in the seventh.

Pivetta was off the hook for a decision he could only have lost, but it did not change the fact he had put together a third straight clunker. He has allowed 24 hits, walked eight, and surrendered 14 runs in 17⅔ innings over his last three starts, which computes to a 7.13 earned run average.

“I thought I could have been crisper, better, especially in the sixth inning,” Pivetta said. “But guys picked me up as they’ve been doing the past couple of days and we won the baseball game.”

Pivetta, however, would not concede that his composure was a problem.

“I think I compete and I’m an emotional pitcher for the most part, but I compete,” he said. “At the end of the day, I don’t think any of that gets in the way. I just care.”

Wednesday night’s effort by the 26-year-old righthander was slightly below mediocre. He delivered three scoreless innings at the start, but he hung curveballs in the fourth and fifth innings that resulted in solo home runs by Domonic Smith and Jeff McNeil.

The Phillies could have lived with that, but Pivetta opened the sixth with consecutive walks to Smith and Amed Rosario.

That’s asking for trouble, and it found him.

Backup catcher Tomas Nido singled home New York’s third run of the game before opposing pitcher Jason Vargas gave Pivetta an out by bunting a two-strike pitch foul. McNeil followed with an RBI double to make it 4-0.

When Kapler decided to pull Pivetta after he struck out Alonso, the pitcher had only himself to blame for his failure to get through the sixth inning for the seventh time in 10 big-league starts this season.

If Matt Klentak was sincere in his appraisal of his team earlier this week, then the general manager also knows he needs rotation reinforcements at the trade deadline. For now, Pivetta will remain in the rotation, but he does not have much time left to prove he belongs there for the long haul.