8. Nechybí tu něco?
public function getMeValue($text) {
return ‘Do I really return ‘ . $text . ‘?’;
}
9. Nechybí tu ještě něco?
public function getMeValue(string $text) {
return ‘Do I really return ‘ . $text . ‘?’;
}
10. Nechybí tu JEŠTĚ něco?
public function getMeValue(string $text): string {
return ‘Do I really return ‘ . $text . ‘?’;
}
11. Takže takhle? Není to málo? :-)
/**
* @param string $text
* @return string
*/
public function getMeValue(string $text): string {
return ‘Do I really return ‘ . $text . ‘?’;
}
12. Který zápis platí? Anotace? Typehint?
/**
* @param AppCustomer[]|DoctrineCommonCollectionsArrayCollection
*/
public function processCustomer(CustomerList $customerList) {
// do some business logic…
}
16. Toto je tedy vše?
/**
* @param AppCustomer[] $recipients
*/
public function sendBulkNotification(array $recipients): void {
foreach ($recipients as $recipient) {
$this->sendNotifiacation($recipient);
}
}
17. A co bude teď?
$recipients = [
new Customer(‘Vratislav’, ‘vrata1@gmail.com’),
new Customer(‘Čestmír’, ‘cesta@seznam.cz’),
5,
];
$notifier->sendBulkNotification($recipients);
18. Pomůže nám List (a Consistence)
Následuje ukázka kódu:
https://github.com/TomasBlaha/pehapkari
https://github.com/consistence/consistence
27. Co s komplexní třídou?
class Car(
string $name,
string $make,
float $width,
float $height,
float $lenght,
int $doorsCount,
int $weight,
…
28. Rozpadnout!
class Car(
string $name,
string $make,
CarBody $carBody,
Color $color
)
class CarBody(
float $width,
float $height,
float $lenght,
int $doorsCount,
int $weight
)
29. Co s volitelnými parametry?
Následuje ukázka kódu:
https://github.com/TomasBlaha/pehapkari
30. Jak jsme si pomohli?
1. Fail fast
• https://www.martinfowler.com/ieeeSoftware/failFast.pdf
• Chyba se projeví hned
• Snadná debugovatelnost
• Chyba se nepřenáší do business logiky
31. Jak jsme si pomohli?
2. Atomizovaný kód
• Znovupoužitelnost komponent
32. Jak jsme si pomohli?
3. Čitelnější
• Přehlednější metody (constructor etc.)
• Anotace uvádíme pouze na 1 místě
(anotce deprecují kód)
33. Jak jsme si pomohli?
4. Lépe testovatelný
• Přehlednější testy
• Méně závislostí
• Immutability
• SRP:
https://www.facebook.com/pehapkari/videos/1652303308152806/
• Nullable:
https://www.facebook.com/pehapkari/videos/1616785535037917/
34. Jak jsme si pomohli?
5. Větší a snazší kontrola
• DDD - https://en.wikipedia.org/wiki/Domain-driven_design
• Hinting v IDE
• Práce s daty na jednom místě
35. Jak jsme si pomohli?
6. Maintenovatelnost
• Find usages
• Refactor
• Držíme type na jednom místě (anotace vs typehint)