Redukuj znaky challenge v PHP

Po tom, co se zde objevil článek s touto "challenge" v Rustu, napadlo mě v jedný dlouhý chvilce si to zkusit napsat v php, jako speedcode. Přikládám nejdříve nerefaktorované řešení.

<?php

function checkSide($char, &$ls, &$t, $leftKeys, $rightKeys) {
    if (in_array($char, $leftKeys)) {
        if ($ls === 'L') {
            $t += 75;
        } else {
            $t += 50;
        }
        $ls = 'L';
    } else {
        if ($ls === 'R') {
            $t += 75;
        } else {
            $t += 50;
        }
        $ls = 'R';
    }
}

function timeToWrite($stringToWrite) {
    $lengthOfString = strlen($stringToWrite);
    if ($lengthOfString === 0) {
        return 0;
    } 
    $leftKeys = [' ', 'q', 'w', 'e', 'r', 't', 'a', 's', 'd', 'f', 'g', 'z', 'x', 'c', 'v', 'b'];
    $rightKeys = [' ', 'y', 'u', 'i', 'o', 'p', 'h', 'j', 'k', 'l', 'n', 'm'];

    if ($stringToWrite[0] === ' ') {
        $j = 1;
        while ($stringToWrite[$j] === ' ' && $j < ($lengthOfString - 1)) {
            $j++;
        }
        if (in_array($stringToWrite[$j], $leftKeys)) {
            $lastSide = $j%2 === 0 ? 'L' : 'R';
        } else {
            $lastSide = $j%2 === 0 ? 'R' : 'L';
        }
    } else {
        $lastSide = in_array($stringToWrite[0], $rightKeys) ? 'R' : 'L';
    }

    $i = 1;
    $time = 50;
    while ($i < $lengthOfString) {
        if ($stringToWrite[$i] !== ' ') {
            checkSide($stringToWrite[$i], $lastSide, $time, $leftKeys, $rightKeys);
        } else {
            $time += 50;
            $lastSide = $lastSide === 'R' ? 'L' : 'R';
        }
        $i++;
    }
    return $time;
}

function assertMe($string, $expected) {
    var_dump(timeToWrite($string) === $expected);
}

assertMe("abc",200);
assertMe("land",200);
assertMe("nice job",500);
assertMe("this string is a bit longer so it should probably take a longer time to type out maybe",5075);
assertMe("",0); 
assertMe("f",50);
assertMe("spacebars  ",700);
assertMe("   ",150);
assertMe("something really long with a whole bunch of characters that takes a super long time to type out and keeps going on for a long time in what you could call a run on sentence since this challenge does not support the use of punctuation in the text but that will not stop us from making it a super long string that goes on for a really long time and is a really nice thing to read and enjoy on a beautiful day",23875);

// custom
assertMe("a k",175);
assertMe("a a",150);
assertMe("k a",175);
assertMe("k k",150);

assertMe(" k",100);
assertMe(" a",100);
assertMe("  a",150);

This article is my 2nd oldest. It is 32 words long, and it’s got 0 comments for now.