Comments (3)
@peter-gribanov It's a good point. I think that solution is to use private properties, setters and typed getters. E.g.
class MenuConfig
{
private $title;
private $body;
private $buttonText;
private $cancellable = false;
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
public function getBody(): string
{
return $this->body;
}
public function setBody(string $body): void
{
$this->body = $body;
}
public function getButtonText(): string
{
return $this->buttonText;
}
public function setButtonText(string $buttonText): void
{
$this->buttonText = $buttonText;
}
public function getCancellable(): bool
{
return $this->cancellable;
}
public function setCancellable(bool $cancellable): void
{
$this->cancellable = $cancellable;
}
}
It means that if required properties(title, body, buttonText) are not set the TypeError exception will be thrown. But if optional property isn't set all will be ok and default value will be returned.
from clean-code-php.
@yuriyzinchenko Yes, by adding access methods we return control over the data types.
You can make a PR for fix it.
from clean-code-php.
This issue was about the problem of required properties, but i now looked more closely and realized that there was no problem. Sorry.
from clean-code-php.
Related Issues (20)
- Change from JS to PHP in "Functions should only be one level of abstraction" HOT 1
- Database Interface Layer concrete example HOT 1
- Need help to understand the Avoid Conditionals section. HOT 2
- Possibly incorrect: "Zero arguments is the ideal case" HOT 4
- Question on coupling of static classes HOT 4
- Comparison text HOT 1
- Discussion about "Don't add unneeded context" HOT 4
- reusable value-objects w/ better type safety HOT 4
- Persian translation
- "Use default arguments instead of short circuiting or conditionals" HOT 2
- Arabic translation HOT 2
- Indonesia translation
- How to handle un/happy paths HOT 6
- An array is a dumb container of unknown data
- Define constants in those methods where you use, not globally
- adding ndonesian translation section + Refactor code under collapsible markdown
- Problem in the fibonacci function
- Book PHp
- Premier jet du dictionnaire de données
- Cleen code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clean-code-php.