SlideShare a Scribd company logo
1 of 62
Download to read offline
„KTO TO PISAŁ?!… A, TO JA.”
czyli sposoby, żeby znienawidzić
siebie z przeszłości
🔥🔥🔥
„KTO TO PISAŁ?! A, TO JA…”
czyli jak wiedźmin i angielski teolog
„KTO TO PISAŁ?! A, TO JA…”
czyli jak wiedźmin i angielski teolog
mogą pomóc Ci pisać lepszy kod
„KTO TO PISAŁ?! A, TO JA…”
„KTO TO PISAŁ?! A, TO JA…”
czyli jak wiedźmin i angielski teolog
mogą pomóc Ci pisać lepszy kod
albo przynajmniej zrozumieć, czemu nie
jest tak dobry, jak byś chciał(a)
S P Ó J N O Ś Ć
😕
😕
😠
😕
😠
😕
😠
🤬🤬🤬🤬
final class ProductVariantPriceCalculatorSpec extends ObjectBehavior
{
function it_implements_product_variant_price_calculator_interface(): void
{
$this->shouldImplement(ProductVariantPricesCalculatorInterface::class);
}
function it_gets_price_for_product_variant_in_given_channel(
ChannelInterface $channel,
ChannelPricingInterface $channelPricing,
ProductVariantInterface $productVariant,
): void {
$productVariant->getChannelPricingForChannel($channel)->willReturn($channelPricing);
$channelPricing->getPrice()->willReturn(1000);
$this->calculate($productVariant, ['channel' => $channel])->shouldReturn(1000);
}
}
final class ProductVariantPriceCalculatorSpec extends ObjectBehavior
{
function it_implements_product_variant_price_calculator_interface(): void
{
$this->shouldImplement(ProductVariantPricesCalculatorInterface::class);
}
function it_gets_price_for_product_variant_in_given_channel(
ChannelInterface $channel,
ChannelPricingInterface $channelPricing,
ProductVariantInterface $productVariant,
): void {
$productVariant->getChannelPricingForChannel($channel)->willReturn($channelPricing);
$channelPricing->getPrice()->willReturn(1000);
$this->calculate($productVariant, ['channel' => $channel])->shouldReturn(1000);
}
}
😡
1 . P O P R A W N O Ś Ć
2 . S P Ó J N O Ś Ć
P U Ł A P K A
S P Ó J N O Ś C I
D O K U M E N T A C J A
P Ł O T C H E S T E R T O N A
T E S T Y
A D R
K O N T E K S T
final class GrossPriceCalculatorTest extends TestCase
{
/** @dataProvider provideGrossCalculationData */
public function testItCountsGrossPriceForGivenNetPriceAndTaxRate(
int $netPrice,
float $taxRate,
int $expectedGrossPrice
): void {
self::assertSame(
$expectedGrossPrice,
GrossPriceCalculator::calculateGrossPrice($netPrice, $taxRate)
);
}
private function provideGrossCalculationData(): iterable
{
yield 'net price 500, tax rate 7.0%' => [
'netPrice' => 500,
'taxRate' => 0.07,
'expectedGrossPrice' => 535,
];
yield 'net price 750, tax rate 7.7%' => [
'netPrice' => 750,
'taxRate' => 0.077,
'expectedGrossPrice' => 808,
];
yield 'net price 1500, tax rate 8.5%' => [
'netPrice' => 1500,
'taxRate' => 0.085,
'expectedGrossPrice' => 1628,
];
}
}
final class GrossPriceCalculatorTest extends TestCase
{
/** @dataProvider provideGrossCalculationData */
public function testItCountsGrossPriceForGivenNetPriceAndTaxRate(
int $netPrice,
float $taxRate,
int $expectedGrossPrice
): void {
self::assertSame(
$expectedGrossPrice,
GrossPriceCalculator::calculateGrossPrice($netPrice, $taxRate)
);
}
private function provideGrossCalculationData(): iterable
{
yield 'net price 500, tax rate 7.0%' => [
'netPrice' => 500,
'taxRate' => 0.07,
'expectedGrossPrice' => 535,
];
yield 'net price 750, tax rate 7.7%' => [
'netPrice' => 750,
'taxRate' => 0.077,
'expectedGrossPrice' => 808,
];
yield 'net price 1500, tax rate 8.5%' => [
'netPrice' => 1500,
'taxRate' => 0.085,
'expectedGrossPrice' => 1628,
];
}
}
❗
❗
final class GrossPriceCalculatorTest extends TestCase
{
/** @dataProvider provideGrossCalculationData */
public function testItCountsGrossPriceForGivenNetPriceAndTaxRate(
int $netPrice,
float $taxRate,
int $expectedGrossPrice
): void {
self::assertSame(
$expectedGrossPrice,
GrossPriceCalculator::calculateGrossPrice($netPrice, $taxRate)
);
}
private function provideGrossCalculationData(): iterable
{
yield 'net price 500, tax rate 7.0%' => [
'netPrice' => 500,
'taxRate' => 0.07,
'expectedGrossPrice' => 535,
];
yield 'net price 750, tax rate 7.7%' => [
'netPrice' => 750,
'taxRate' => 0.077,
'expectedGrossPrice' => 810,
];
yield 'net price 1500, tax rate 8.5%' => [
'netPrice' => 1500,
'taxRate' => 0.085,
'expectedGrossPrice' => 1630,
];
}
}
✅
✅
🤨
K O N T E K S T
W I E D Z Y I
C Z A S U
D Ł U G
T E C H N I C Z N Y
https://twitter.com/vincentdnl/status/1647630936060600322
final class OrderTaxesProcessor implements OrderProcessorInterface
{
public function __construct(
private ZoneProviderInterface $defaultTaxZoneProvider,
private ZoneMatcherInterface $zoneMatcher,
private PrioritizedServiceRegistryInterface $strategyRegistry,
private ?TaxationAddressResolverInterface $taxationAddressResolver = null,
) {
}
public function process(BaseOrderInterface $order): void
{
if (OrderInterface::STATE_CART !== $order->getState()) {
return;
}
$this->clearTaxes($order);
if ($order->isEmpty()) {
return;
}
$zone = $this->getTaxZone($order);
if (null === $zone) {
return;
}
/** @var TaxCalculationStrategyInterface $strategy */
foreach ($this->strategyRegistry->all() as $strategy) {
if ($strategy->supports($order, $zone)) {
$strategy->applyTaxes($order, $zone);
public function process(BaseOrderInterface $order): void
{
if (OrderInterface::STATE_CART !== $order->getState()) {
return;
}
$this->clearTaxes($order);
if ($order->isEmpty()) {
return;
}
😡
public function process(BaseOrderInterface $order): void
{
if ($order->canBeProcessed()) {
return;
}
$this->clearTaxes($order);
if ($order->isEmpty()) {
return;
}
if ($order->canBeProcessed()) {
return;
}
2 0 2 0
2 0 2 0
/api/v2 header /new-api
😂
2 0 2 0
/api/v2 header /new-api
🤡
„ P O S T Ę P J E S T
J A K S T A D O
Ś W I Ń ”
R E F A C T O R I N G
Z A S A D A S K A U T A
Z A S A D Y
S O L I D
K I S S
D R Y
Y A G N I
C U P I D
S R P
public function process(BaseOrderInterface $order): void
{
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);
if (OrderInterface::STATE_CART !== $order->getState()) {
return;
}
$this->clearTaxes($order);
if ($order->isEmpty()) {
return;
}
$zone = $this->getTaxZone($order);
if (null === $zone) {
return;
}
/** @var TaxCalculationStrategyInterface $strategy */
foreach ($this->strategyRegistry->all() as $strategy) {
if ($strategy->supports($order, $zone)) {
$strategy->applyTaxes($order, $zone);
return;
}
}
throw new UnsupportedTaxCalculationStrategyException();
}
private function getTaxZone(OrderInterface $order): ?ZoneInterface
{
$taxationAddress = $order->getBillingAddress();
$zone = $this->zoneMatcher->match($taxationAddress, Scope::TAX);
return $zone ?: $this->defaultTaxZoneProvider->getZone($order);
}
private function clearTaxes(OrderInterface $order): void
{
$order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
foreach ($order->getItems() as $item) {
$item->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT);
}
/** @var ShipmentInterface $shipment */
foreach ($order->getShipments() as $shipment) {
$shipment->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
}
}
public function process(BaseOrderInterface $order): void
{
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);
if (OrderInterface::STATE_CART !== $order->getState()) {
return;
}
$this->clearTaxes($order);
if ($order->isEmpty()) {
return;
}
$zone = $this->getTaxZone($order);
if (null === $zone) {
return;
}
/** @var TaxCalculationStrategyInterface $strategy */
foreach ($this->strategyRegistry->all() as $strategy) {
if ($strategy->supports($order, $zone)) {
$strategy->applyTaxes($order, $zone);
return;
}
}
throw new UnsupportedTaxCalculationStrategyException();
}
private function getTaxZone(OrderInterface $order): ?ZoneInterface
{
$taxationAddress = $order->getBillingAddress();
$zone = $this->zoneMatcher->match($taxationAddress, Scope::TAX);
return $zone ?: $this->defaultTaxZoneProvider->getZone($order);
}
private function clearTaxes(OrderInterface $order): void
{
$order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
foreach ($order->getItems() as $item) {
$item->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT);
}
/** @var ShipmentInterface $shipment */
foreach ($order->getShipments() as $shipment) {
$shipment->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
}
}
public function process(BaseOrderInterface $order): void
{
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);
if (OrderInterface::STATE_CART !== $order->getState()) {
return;
}
$this->clearTaxes($order);
if ($order->isEmpty()) {
return;
}
$zone = $this->getTaxZone($order);
if (null === $zone) {
return;
}
/** @var TaxCalculationStrategyInterface $strategy */
foreach ($this->strategyRegistry->all() as $strategy) {
if ($strategy->supports($order, $zone)) {
$strategy->applyTaxes($order, $zone);
return;
}
}
throw new UnsupportedTaxCalculationStrategyException();
}
private function getTaxZone(OrderInterface $order): ?ZoneInterface
{
$taxationAddress = $order->getBillingAddress();
$zone = $this->zoneMatcher->match($taxationAddress, Scope::TAX);
return $zone ?: $this->defaultTaxZoneProvider->getZone($order);
}
private function clearTaxes(OrderInterface $order): void
{
$order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
foreach ($order->getItems() as $item) {
$item->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT);
}
/** @var ShipmentInterface $shipment */
foreach ($order->getShipments() as $shipment) {
$shipment->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
}
}
I M P L E M E N T A C J A
Z P R Z Y P A D K U
D D D
D I S C O M F O R T
D R I V E N
D E V E L O P M E N T
THANK YOU
@CommerceWeavers
@mpzalewski Zales0123
https://mpzalewski.com
Mateusz Zalewski

More Related Content

Similar to "Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z przeszłości

Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosDivante
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021Ayesh Karunaratne
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web servicesMichelangelo van Dam
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using CodeceptionJeroen van Dijk
 
R57shell
R57shellR57shell
R57shellady36
 
Php tutorial handout
Php tutorial handoutPhp tutorial handout
Php tutorial handoutSBalan Balan
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access RunbookTaha Shakeel
 
Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First WidgetChris Wilcoxson
 
GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4Heather Rock
 
How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014Guillaume POTIER
 

Similar to "Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z przeszłości (20)

Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
Database api
Database apiDatabase api
Database api
 
PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
 
Broadleaf Presents Thymeleaf
Broadleaf Presents ThymeleafBroadleaf Presents Thymeleaf
Broadleaf Presents Thymeleaf
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using Codeception
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
 
R57shell
R57shellR57shell
R57shell
 
PHP 8.1: Enums
PHP 8.1: EnumsPHP 8.1: Enums
PHP 8.1: Enums
 
Php tutorial handout
Php tutorial handoutPhp tutorial handout
Php tutorial handout
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
 
Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First Widget
 
GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4
 
How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 

More from Mateusz Zalewski

[PHPCon 2023] Blaski i cienie BDD
[PHPCon 2023] Blaski i cienie BDD[PHPCon 2023] Blaski i cienie BDD
[PHPCon 2023] Blaski i cienie BDDMateusz Zalewski
 
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...Mateusz Zalewski
 
[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testing[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testingMateusz Zalewski
 
Confoo 2023 - BDD revolution, or how we came back from hell
Confoo 2023 - BDD revolution, or how we came back from hellConfoo 2023 - BDD revolution, or how we came back from hell
Confoo 2023 - BDD revolution, or how we came back from hellMateusz Zalewski
 
Confoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api PlatformConfoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api PlatformMateusz Zalewski
 
What is Sylius and why should you know it?
What is Sylius and why should you know it?What is Sylius and why should you know it?
What is Sylius and why should you know it?Mateusz Zalewski
 
BDD Revolution - or how we came back from hell
BDD Revolution - or how we came back from hellBDD Revolution - or how we came back from hell
BDD Revolution - or how we came back from hellMateusz Zalewski
 
BDD revolution - or how we came back from hell
BDD revolution - or how we came back from hellBDD revolution - or how we came back from hell
BDD revolution - or how we came back from hellMateusz Zalewski
 
Why you should be doing BDD
Why you should be doing BDDWhy you should be doing BDD
Why you should be doing BDDMateusz Zalewski
 

More from Mateusz Zalewski (9)

[PHPCon 2023] Blaski i cienie BDD
[PHPCon 2023] Blaski i cienie BDD[PHPCon 2023] Blaski i cienie BDD
[PHPCon 2023] Blaski i cienie BDD
 
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
 
[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testing[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testing
 
Confoo 2023 - BDD revolution, or how we came back from hell
Confoo 2023 - BDD revolution, or how we came back from hellConfoo 2023 - BDD revolution, or how we came back from hell
Confoo 2023 - BDD revolution, or how we came back from hell
 
Confoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api PlatformConfoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api Platform
 
What is Sylius and why should you know it?
What is Sylius and why should you know it?What is Sylius and why should you know it?
What is Sylius and why should you know it?
 
BDD Revolution - or how we came back from hell
BDD Revolution - or how we came back from hellBDD Revolution - or how we came back from hell
BDD Revolution - or how we came back from hell
 
BDD revolution - or how we came back from hell
BDD revolution - or how we came back from hellBDD revolution - or how we came back from hell
BDD revolution - or how we came back from hell
 
Why you should be doing BDD
Why you should be doing BDDWhy you should be doing BDD
Why you should be doing BDD
 

Recently uploaded

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 

Recently uploaded (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 

"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z przeszłości

  • 1. „KTO TO PISAŁ?!… A, TO JA.” czyli sposoby, żeby znienawidzić siebie z przeszłości
  • 3. „KTO TO PISAŁ?! A, TO JA…”
  • 4. czyli jak wiedźmin i angielski teolog „KTO TO PISAŁ?! A, TO JA…”
  • 5. czyli jak wiedźmin i angielski teolog mogą pomóc Ci pisać lepszy kod „KTO TO PISAŁ?! A, TO JA…”
  • 6. „KTO TO PISAŁ?! A, TO JA…” czyli jak wiedźmin i angielski teolog mogą pomóc Ci pisać lepszy kod albo przynajmniej zrozumieć, czemu nie jest tak dobry, jak byś chciał(a)
  • 7.
  • 8. S P Ó J N O Ś Ć
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. 😕
  • 17. final class ProductVariantPriceCalculatorSpec extends ObjectBehavior { function it_implements_product_variant_price_calculator_interface(): void { $this->shouldImplement(ProductVariantPricesCalculatorInterface::class); } function it_gets_price_for_product_variant_in_given_channel( ChannelInterface $channel, ChannelPricingInterface $channelPricing, ProductVariantInterface $productVariant, ): void { $productVariant->getChannelPricingForChannel($channel)->willReturn($channelPricing); $channelPricing->getPrice()->willReturn(1000); $this->calculate($productVariant, ['channel' => $channel])->shouldReturn(1000); } }
  • 18. final class ProductVariantPriceCalculatorSpec extends ObjectBehavior { function it_implements_product_variant_price_calculator_interface(): void { $this->shouldImplement(ProductVariantPricesCalculatorInterface::class); } function it_gets_price_for_product_variant_in_given_channel( ChannelInterface $channel, ChannelPricingInterface $channelPricing, ProductVariantInterface $productVariant, ): void { $productVariant->getChannelPricingForChannel($channel)->willReturn($channelPricing); $channelPricing->getPrice()->willReturn(1000); $this->calculate($productVariant, ['channel' => $channel])->shouldReturn(1000); } } 😡
  • 19. 1 . P O P R A W N O Ś Ć 2 . S P Ó J N O Ś Ć
  • 20. P U Ł A P K A S P Ó J N O Ś C I
  • 21. D O K U M E N T A C J A
  • 22. P Ł O T C H E S T E R T O N A
  • 23. T E S T Y
  • 24.
  • 25.
  • 26.
  • 27. A D R
  • 28.
  • 29.
  • 30. K O N T E K S T
  • 31. final class GrossPriceCalculatorTest extends TestCase { /** @dataProvider provideGrossCalculationData */ public function testItCountsGrossPriceForGivenNetPriceAndTaxRate( int $netPrice, float $taxRate, int $expectedGrossPrice ): void { self::assertSame( $expectedGrossPrice, GrossPriceCalculator::calculateGrossPrice($netPrice, $taxRate) ); } private function provideGrossCalculationData(): iterable { yield 'net price 500, tax rate 7.0%' => [ 'netPrice' => 500, 'taxRate' => 0.07, 'expectedGrossPrice' => 535, ]; yield 'net price 750, tax rate 7.7%' => [ 'netPrice' => 750, 'taxRate' => 0.077, 'expectedGrossPrice' => 808, ]; yield 'net price 1500, tax rate 8.5%' => [ 'netPrice' => 1500, 'taxRate' => 0.085, 'expectedGrossPrice' => 1628, ]; } }
  • 32. final class GrossPriceCalculatorTest extends TestCase { /** @dataProvider provideGrossCalculationData */ public function testItCountsGrossPriceForGivenNetPriceAndTaxRate( int $netPrice, float $taxRate, int $expectedGrossPrice ): void { self::assertSame( $expectedGrossPrice, GrossPriceCalculator::calculateGrossPrice($netPrice, $taxRate) ); } private function provideGrossCalculationData(): iterable { yield 'net price 500, tax rate 7.0%' => [ 'netPrice' => 500, 'taxRate' => 0.07, 'expectedGrossPrice' => 535, ]; yield 'net price 750, tax rate 7.7%' => [ 'netPrice' => 750, 'taxRate' => 0.077, 'expectedGrossPrice' => 808, ]; yield 'net price 1500, tax rate 8.5%' => [ 'netPrice' => 1500, 'taxRate' => 0.085, 'expectedGrossPrice' => 1628, ]; } } ❗ ❗
  • 33. final class GrossPriceCalculatorTest extends TestCase { /** @dataProvider provideGrossCalculationData */ public function testItCountsGrossPriceForGivenNetPriceAndTaxRate( int $netPrice, float $taxRate, int $expectedGrossPrice ): void { self::assertSame( $expectedGrossPrice, GrossPriceCalculator::calculateGrossPrice($netPrice, $taxRate) ); } private function provideGrossCalculationData(): iterable { yield 'net price 500, tax rate 7.0%' => [ 'netPrice' => 500, 'taxRate' => 0.07, 'expectedGrossPrice' => 535, ]; yield 'net price 750, tax rate 7.7%' => [ 'netPrice' => 750, 'taxRate' => 0.077, 'expectedGrossPrice' => 810, ]; yield 'net price 1500, tax rate 8.5%' => [ 'netPrice' => 1500, 'taxRate' => 0.085, 'expectedGrossPrice' => 1630, ]; } } ✅ ✅ 🤨
  • 34.
  • 35. K O N T E K S T W I E D Z Y I C Z A S U
  • 36. D Ł U G T E C H N I C Z N Y
  • 38. final class OrderTaxesProcessor implements OrderProcessorInterface { public function __construct( private ZoneProviderInterface $defaultTaxZoneProvider, private ZoneMatcherInterface $zoneMatcher, private PrioritizedServiceRegistryInterface $strategyRegistry, private ?TaxationAddressResolverInterface $taxationAddressResolver = null, ) { } public function process(BaseOrderInterface $order): void { if (OrderInterface::STATE_CART !== $order->getState()) { return; } $this->clearTaxes($order); if ($order->isEmpty()) { return; } $zone = $this->getTaxZone($order); if (null === $zone) { return; } /** @var TaxCalculationStrategyInterface $strategy */ foreach ($this->strategyRegistry->all() as $strategy) { if ($strategy->supports($order, $zone)) { $strategy->applyTaxes($order, $zone);
  • 39. public function process(BaseOrderInterface $order): void { if (OrderInterface::STATE_CART !== $order->getState()) { return; } $this->clearTaxes($order); if ($order->isEmpty()) { return; } 😡
  • 40. public function process(BaseOrderInterface $order): void { if ($order->canBeProcessed()) { return; } $this->clearTaxes($order); if ($order->isEmpty()) { return; } if ($order->canBeProcessed()) { return; }
  • 41.
  • 42.
  • 43. 2 0 2 0
  • 44. 2 0 2 0 /api/v2 header /new-api 😂
  • 45. 2 0 2 0 /api/v2 header /new-api 🤡
  • 46.
  • 47. „ P O S T Ę P J E S T J A K S T A D O Ś W I Ń ”
  • 48. R E F A C T O R I N G
  • 49.
  • 50.
  • 51. Z A S A D A S K A U T A
  • 52. Z A S A D Y
  • 53. S O L I D K I S S D R Y Y A G N I C U P I D
  • 54. S R P
  • 55. public function process(BaseOrderInterface $order): void { /** @var OrderInterface $order */ Assert::isInstanceOf($order, OrderInterface::class); if (OrderInterface::STATE_CART !== $order->getState()) { return; } $this->clearTaxes($order); if ($order->isEmpty()) { return; } $zone = $this->getTaxZone($order); if (null === $zone) { return; } /** @var TaxCalculationStrategyInterface $strategy */ foreach ($this->strategyRegistry->all() as $strategy) { if ($strategy->supports($order, $zone)) { $strategy->applyTaxes($order, $zone); return; } } throw new UnsupportedTaxCalculationStrategyException(); } private function getTaxZone(OrderInterface $order): ?ZoneInterface { $taxationAddress = $order->getBillingAddress(); $zone = $this->zoneMatcher->match($taxationAddress, Scope::TAX); return $zone ?: $this->defaultTaxZoneProvider->getZone($order); } private function clearTaxes(OrderInterface $order): void { $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); foreach ($order->getItems() as $item) { $item->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT); } /** @var ShipmentInterface $shipment */ foreach ($order->getShipments() as $shipment) { $shipment->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); } }
  • 56. public function process(BaseOrderInterface $order): void { /** @var OrderInterface $order */ Assert::isInstanceOf($order, OrderInterface::class); if (OrderInterface::STATE_CART !== $order->getState()) { return; } $this->clearTaxes($order); if ($order->isEmpty()) { return; } $zone = $this->getTaxZone($order); if (null === $zone) { return; } /** @var TaxCalculationStrategyInterface $strategy */ foreach ($this->strategyRegistry->all() as $strategy) { if ($strategy->supports($order, $zone)) { $strategy->applyTaxes($order, $zone); return; } } throw new UnsupportedTaxCalculationStrategyException(); } private function getTaxZone(OrderInterface $order): ?ZoneInterface { $taxationAddress = $order->getBillingAddress(); $zone = $this->zoneMatcher->match($taxationAddress, Scope::TAX); return $zone ?: $this->defaultTaxZoneProvider->getZone($order); } private function clearTaxes(OrderInterface $order): void { $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); foreach ($order->getItems() as $item) { $item->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT); } /** @var ShipmentInterface $shipment */ foreach ($order->getShipments() as $shipment) { $shipment->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); } }
  • 57. public function process(BaseOrderInterface $order): void { /** @var OrderInterface $order */ Assert::isInstanceOf($order, OrderInterface::class); if (OrderInterface::STATE_CART !== $order->getState()) { return; } $this->clearTaxes($order); if ($order->isEmpty()) { return; } $zone = $this->getTaxZone($order); if (null === $zone) { return; } /** @var TaxCalculationStrategyInterface $strategy */ foreach ($this->strategyRegistry->all() as $strategy) { if ($strategy->supports($order, $zone)) { $strategy->applyTaxes($order, $zone); return; } } throw new UnsupportedTaxCalculationStrategyException(); } private function getTaxZone(OrderInterface $order): ?ZoneInterface { $taxationAddress = $order->getBillingAddress(); $zone = $this->zoneMatcher->match($taxationAddress, Scope::TAX); return $zone ?: $this->defaultTaxZoneProvider->getZone($order); } private function clearTaxes(OrderInterface $order): void { $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); foreach ($order->getItems() as $item) { $item->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT); } /** @var ShipmentInterface $shipment */ foreach ($order->getShipments() as $shipment) { $shipment->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); } }
  • 58. I M P L E M E N T A C J A Z P R Z Y P A D K U
  • 59.
  • 60. D D D
  • 61. D I S C O M F O R T D R I V E N D E V E L O P M E N T