A man who had pleaded guilty and testified against his partner in crime in the slaying of an off-duty cop was sentenced Tuesday to 20 to 40 years in prison. 

Chancier McFarland was one of two suspects arrested for the killing of Officer Moses Walker, who was targeted for a robbery while walking to public transit after he had finished an overnight shift as a turnkey at the 22nd District on the morning of Aug. 18, 2012.

RELATED: Cop-killer gets life in prison. 

McFarland told investigators that he and accomplice Rafael Jones didn't know Walker was a cop. They thought he was a Temple University student who would have been easy pickings. Jones shot Walker when the off-duty cop reached for a gun.

Jones was sentenced to life in prison without the possibility of parole. McFarland's testimony spared him that sentence in a negotiated plea deal.  

A graduate of Benjamin Franklin High School, Walker entered the police academy in March of 1993 at the age of 21 and was assigned to the 22nd District, where his uncle also serves as a lieutenant, a year later.

"He was known by both his fellow officers and the residents he served as a courteous, polite and humble man," said an obituary posted on the police department's website.

RELATED: Police Department mourns death of Moses Walker

Walker was an an active member of Deliverance Evangelistic Church on the 2000 block of Lehigh Avenue in North Philadelphia. The police obituary describes him as "an optimistic man who always saw the good in people."

McFarland pleaded guilty to third-degree murder, testified against Jones and is serving 20 to 40 years in prison.