mirror of
https://github.com/jupeter/clean-code-php.git
synced 2025-09-25 21:49:04 +02:00
use VO in example of "Function arguments (2 or fewer ideally)"
This commit is contained in:
64
README.md
64
README.md
@@ -443,33 +443,73 @@ of the time a higher-level object will suffice as an argument.
|
|||||||
**Bad:**
|
**Bad:**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
function createMenu(string $title, string $body, string $buttonText, bool $cancellable): void
|
class Questionnaire
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
string $firstname,
|
||||||
|
string $lastname,
|
||||||
|
string $patronymic,
|
||||||
|
string $region,
|
||||||
|
string $district,
|
||||||
|
string $city,
|
||||||
|
string $phone,
|
||||||
|
string $email
|
||||||
|
) {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Good:**
|
**Good:**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
class MenuConfig
|
class Name
|
||||||
{
|
{
|
||||||
public $title;
|
private $firstname = '';
|
||||||
public $body;
|
private $lastname = '';
|
||||||
public $buttonText;
|
private $patronymic = '';
|
||||||
public $cancellable = false;
|
|
||||||
|
public function __construct(string $firstname, string $lastname, string $patronymic)
|
||||||
|
{
|
||||||
|
$this->firstname = $firstname;
|
||||||
|
$this->lastname = $lastname;
|
||||||
|
$this->patronymic = $patronymic;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = new MenuConfig();
|
class City
|
||||||
$config->title = 'Foo';
|
{
|
||||||
$config->body = 'Bar';
|
private $region = '';
|
||||||
$config->buttonText = 'Baz';
|
private $district = '';
|
||||||
$config->cancellable = true;
|
private $city = '';
|
||||||
|
|
||||||
function createMenu(MenuConfig $config): void
|
public function __construct(string $region, string $district, string $city)
|
||||||
|
{
|
||||||
|
$this->region = $region;
|
||||||
|
$this->district = $district;
|
||||||
|
$this->city = $city;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Contact
|
||||||
|
{
|
||||||
|
private $phone = '';
|
||||||
|
private $email = '';
|
||||||
|
|
||||||
|
public function __construct(string $phone, string $email)
|
||||||
|
{
|
||||||
|
$this->phone = $phone;
|
||||||
|
$this->email = $email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Questionnaire
|
||||||
|
{
|
||||||
|
public function __construct(Name $name, City $city, Contact $contact)
|
||||||
{
|
{
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**[⬆ back to top](#table-of-contents)**
|
**[⬆ back to top](#table-of-contents)**
|
||||||
|
Reference in New Issue
Block a user