ARKADIUSZ KONDAS
Backend Team Leader
@ Da Vinci Studio
Zend Certified Engineer
Code Craftsman
Blogger
Ultra Runner
WeBB MeetUp Autumn
09.12.2015
@ ArkadiuszKondas
itcraftsman.pl
Zend Certified Architect
Henry Oldenburg, sekretarz Royal Society, 1665
Fagan Inspection Process
Michael Fagan
Agile Manifesto
http://agilemanifesto.org
<?php
class ArrayUtils
{
    /**
     * @param array $array
     *
     * @return mixed
     */
    public function mostRepeatedValue(array $array)
    {
    }
}
class MostRepeatedValueTest extends \PHPUnit_Framework_TestCase
{
    public function testIfItReturnMostRepeatedValueInIntegersArray()
    {
        $array = [1, 3, 4, 5, 1, 3, 1, 7];
        $utils = new ArrayUtils();
        $mostRepeatedValue = $utils->mostRepeatedValue($array);
        $this->assertEquals(1, $mostRepeatedValue);
    }
    public function testIfItReturnMostRepeatedValueInStringArray()
    {
        $array = ['Apple', 'Orange', 'Plum', 'Apple', 'Grape', 'Apple'];
        $utils = new ArrayUtils();
        $mostRepeatedValue = $utils->mostRepeatedValue($array);
        $this->assertEquals('Apple', $mostRepeatedValue);
    }
}public function mostRepeatedValue(array $array)
{
    $counts = [];
    foreach ($array as $item) {
        $item = (string) $item;
        if (!isset($counts[$item])) {
            $counts[$item] = 1;
        } else {
            ++$counts[$item];
        }
    }
    $mostRepeatedCount = 0;
    $mostRepeated = null;
    foreach ($counts as $key => $count) {
        if ($count > $mostRepeatedCount) {
            $mostRepeatedCount = $count;
            $mostRepeated = $key;
        }
    }
    return $mostRepeated;
}
public function mostRepeatedValue(array $array)
{
    $counts = array_count_values($array);
    arsort($counts);
    return key($counts);
}Czy rozumiem co przeglądany kod
ma robić ?
function same(aArr, bArr)
{
  return [].concat.apply([],aArr).sort().toString() 
    === [].concat.apply([],bArr).sort().toString();
}
 
Czy istnieją jakieś oczywiste błędy logiczne w kodzie ?
public function hasCorrectAge($user)
{
    return $user->getAge() = 18;
}// Yoda notation
public function hasCorrectAge($user)
{
    return 18 == $user->getAge();
}Czy spełnione zostały wymagania ?
Czy istnieją testy automatyczne pokrywające przeglądany kod ?
Czy przeglądany kod stosuje się do ustalonego stylu ?
Czy sam zrobiłbym coś inaczej ?
Lepsza komunikacja z zespołem
Polepszanie jakości kodu
Łatwiejsze wdrożenie nowego programisty
Wcześniejsze wykrywanie błędów
Dotrzymywanie terminów
Brak widocznego kontekstu zmian
Osoba sprawdzająca z poza projektu, brak wiedzy na temat domeny
/**
 * @throws EmptyVesselException
 */
public function emptyTheContent()
{
    if ($this->isEmpty()) {
        throw new EmptyVesselException();
    }
    
    $this->filledWith = null;
    $this->ingredients = [];
    $this->currentCapacity = new Capacity(0);
}Różny poziom osób sprawdzających kod
Mniejsze poczucie odpowiedzialności
"przecież mi zaakceptowałeś ten kodzik"
@ ArkadiuszKondas
itcraftsman.pl