Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 575 Bytes

File metadata and controls

27 lines (18 loc) · 575 Bytes

Programming

Getters

Information Hiding

Treat objects with lots of getters as a smell. Instead, try to hide information within the class, and expose other affordances. For example:

// Before
if ($order->getStatus() === 'shipped') {...}

// After
if ($order->shipped()) {...}

Avoid Direct Property Access

Try not to directly access properties. Attributes change a lot, and you'll need to update usages across your project and test cases every time the properties change.

// Bad
$user->phone_number;

// Better
$user->getPhoneNumber();