Last active
September 20, 2023 08:15
-
-
Save trikitrok/9c3eed83ef2cd64b19884a60696c16ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from Ayush Jindal's exercises for code smells https://github.com/ayjindal/CodeSmells | |
<?php | |
class Address { | |
private string $addressLine1; | |
private string $addressLine2; | |
private string $city; | |
private string $state; | |
private string $country; | |
private string $postalCode; | |
public function __construct( | |
string $addressLine1, string $addressLine2, | |
string $city, string $state, | |
string $country, string $postalCode | |
) { | |
$this->addressLine1 = $addressLine1; | |
$this->addressLine2 = $addressLine2; | |
$this->city = $city; | |
$this->state = $state; | |
$this->country = $country; | |
$this->postalCode = $postalCode; | |
} | |
public function getAddressLine1() : string { | |
return $this->addressLine1; | |
} | |
public function getAddressLine2() : string { | |
return $this->addressLine2; | |
} | |
public function getCity() : string { | |
return $this->city; | |
} | |
public function getState() : string { | |
return $this->state; | |
} | |
public function getCountry() : string { | |
return $this->country; | |
} | |
public function getPostalCode() : string { | |
return $this->postalCode; | |
} | |
} | |
class Customer | |
{ | |
private string $name; | |
private Address $currentAddress; | |
public function __construct(string $name, Address $address) | |
{ | |
$this->name = $name; | |
$this->currentAddress = $address; | |
} | |
public function printAddress() :void | |
{ | |
var_dump( | |
$this->currentAddress->getAddressLine1() . "\n" . | |
$this->currentAddress->getAddressLine2() . "\n" . | |
$this->currentAddress->getCity() . ", " . | |
$this->currentAddress->getState() . "\n" . | |
$this->currentAddress->getPostalCode() | |
); | |
} | |
//other methods related to customer class..... | |
} | |
//---------------------------------------------------------------------------- | |
//---------------------------------------------------------------------------- | |
class Customer { | |
private string $name; | |
private Address $currentAddress; | |
public function __construct(string $name, Address $address) { | |
$this->name = $name; | |
$this->currentAddress = $address; | |
} | |
public function printAddress(): void { | |
var_dump($this->currentAddress->format()); | |
} | |
//other methods in customer class..... | |
} | |
class Address { | |
private string $addressLine1; | |
private string $addressLine2; | |
private string $city; | |
private string $state; | |
private string $country; | |
private string $postalCode; | |
public function __construct( | |
string $addressLine1, string $addressLine2, | |
string $city, string $state, | |
string $country, string $postalCode | |
) { | |
$this->addressLine1 = $addressLine1; | |
$this->addressLine2 = $addressLine2; | |
$this->city = $city; | |
$this->state = $state; | |
$this->country = $country; | |
$this->postalCode = $postalCode; | |
} | |
public function format(): string { | |
return $this->addressLine1 . "\n" . | |
$this->addressLine2 . "\n" . | |
$this->city . ", " . | |
$this->state . "\n" . | |
$this->postalCode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment