ComparisonCompactor

In questo esempio andremo a realizzare e rifattorizzare un comparatore di stringhe. Date due stringhe differenti, come abc e abbc, mostra la differenza generando una stringa del tipo: "expected: {ab[]c} but was: {ab[b]c}".

Substring

<?php

/**
 * @param string $str
 * @param int $start
 * @param int|null $end
 * @return false|string
 */
function substring(string $str, int $start, int $end = null)
{
    if ($end !== null) {
        return substr($str, $start, $end - $start);
    }

    return substr($str, $start);
}

ComparisonCompactor (prima del refactoring)

ComparisonCompactor (dopo il refactoring)

Index

Last updated

Was this helpful?