A homeless man fell into dealing drugs after his tent was burned down and he moved into a friend’s house,which ended up being cuckooed by gangsters.

Former addict James Scanlon was facing a seven-year minimum sentence usually doled out to “third strikers.”But his brief convinced the judge it would be unjust.

Instead, Judge Peter Crabtree sentenced the 38-year-old to three years’ imprisonment.

He told the crook, who had managed to get clean since moving from Swindon to Derbyshire: “Anyone who’s involved in dealing class A drugs is involved in criminality which wrecks lives and undermines the fabric of society.

“That is why it is so serious. That is why the custodial threshold is almost always passed.”

Prosecutor Alec Small said Scanlon had twice dealt class A drugs to undercover police officers posing as addicts in Swindon last June.

The officers called the Ramsey line to order and were directed to a park near the Tesco supermarket in Ocotal Way for the pick up.

On the first occasion, on June 12, the officers had to call the line back up to complain that the delivery boy had not turned up.

The dealer told them he would “call his man.” And 10 minutes later Scanlon appeared and spat out three wraps, handing them over in exchange for £20.

The next day, the officers were back at Tesco. An undercover cop named in court as “Rob” bought two wraps of crack cocaine for £20, noticing Scanlon picked the drugs out of a plastic bag containing an estimated 20 to 30 wraps.

The runner was photographed and identified as Scanlon by a beat officer who had gone to school with him.

The court heard Scanlon had two previous convictions for drug supply; in 2009 when he received three years’ imprisonment and in 2017 when a merciful judge gave him a community order.

Defending, Emma Handslip recognised that the latest offences made him a third striker and subject to the mandatory minimum sentence of seven years. But she said it would be unjust to activate the minimum sentence and asked the judge to take an exceptional course.

Scanlon had been homeless and living in a tent in Swindon last year, she said. But when his tent burned down he moved in with an old friend – whose house was then taken over by dealers working for the Ramsey line. “He was surrounded by it. He gave into that temptation and the rest is history.”

Since he had been arrested he had reunited with his family and moved north to Derbyshire, where he was working closely with probation and drug rehabilitation services. He had managed to kick his addiction to class A drugs and had been supporting his teenaged daughter, who would have to move back to Swindon if he were jailed. He was remorseful.

Ms Handslip said her client continued to be affected by the death of a daughter, which had led to his 2017 conviction.

Scanlon, formerly of Tibshelf, Derbyshire, admitted three counts of supplying class A drugs.

Judge Crabtree gave five reasons for setting the guidelines to one side and not imposing the mandatory minimum sentence - the circumstances that had led to him coming into contact with the Ramsey line; his daughter’s death and its continued impact on him; his surviving daughter’s reliance on him; his decision to leave Swindon; and the work he had done with the probation service.

Jailing him for three years, the judge said: “I am satisfied that this is an unusual – exceptional – case.”