Skip to content

Instantly share code, notes, and snippets.

@ozumoo
Created February 22, 2019 22:48
Show Gist options
  • Select an option

  • Save ozumoo/c2bd87e5294d4149649bfddae0a1295c to your computer and use it in GitHub Desktop.

Select an option

Save ozumoo/c2bd87e5294d4149649bfddae0a1295c to your computer and use it in GitHub Desktop.
indentation in php
<?php
//Bank Accounts class
class BankAccounts
{
//constructor
protected $accounts;
function __construct($accounts)
{
$this->accounts = $accounts;
}
//filter method
public function filterBy($accountType)
{
return array_filter($this->accounts , function($account) use ($accountType)
{
return $account->isOfType($accountType) ;
});
}
}
//Account class
class Account
{
protected $type;
private function __construct($type)
{
$this->type = $type;
}
// as we open a bank account
public static function open($type)
{
return new static($type) ;
}
public function isOfType($accountType)
{
return $this->type() == $accountType && $this->isActive();
}
private function type()
{
return $this->type ;
}
private function isActive()
{
return true;
}
}
$accounts = [
Account::open('checking'),
Account::open('savings'),
Account::open('checking'),
Account::open('savings')
];
$accounts = new BankAccounts($accounts);
$savings = $accounts->filterBy('savings');
var_dump($savings);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment