$before =
"This is an example of
some html content!
click for drama
console.log('boo!');";
$after = strip_tags($before, " ");
"This is an example of
some html content!"
# php.net/function.strip_tags
Slide 16
Slide 16 text
$before =
"This is an example of
some html content!
click for drama
console.log('boo!');";
$after = htmlentities($before);
"This is an example of<br>
some html content!
<a href='http://twitter.com'>click for drama</a>
<script>console.log('boo!');</script>"
# php.net/function.htmlentities
/**
* @param string $property
* @param mixed $value
*/
public function cloneWith($property, $value)
{
$clone = clone $this;
$clone->$property = $value;
return $clone;
}
/**
* @param string $type
*/
public function withType($type)
{
assert(is_string($type));
return $this->cloneWith("type", $type);
}
Slide 33
Slide 33 text
clone&is&shallow,
so#manage#deep#cloning#yourself
Slide 34
Slide 34 text
write&simple&code
(it's&the&hardest&thing)
Slide 35
Slide 35 text
do#the#one#thing
Slide 36
Slide 36 text
function sendOrdersAndRenderInvoice(array $orders, $templatePath)
{
foreach ($orders as $order) {
if (!($order instanceof Order)) {
throw new InvalidArgumentException("Invalid order type");
}
try {
$this->api->send($order);
} catch (ApiException $exception) {
$this->logger->log("There was a problem sending an order");
throw $exception;
}
}
if (!file_exists($templatePath)) {
throw new InvalidArgumentException("Template not found");
}
$template = file_get_contents($templatePath);
return $this->renderer->render($template, $orders);
}
Slide 37
Slide 37 text
function sendOrders(array $orders)
{
$this->validateOrders($orders);
foreach ($orders as $order) {
$this->sendOrder($order);
}
}
function validateOrders(array $orders)
{
foreach ($orders as $order) {
if (!($order instanceof Order)) {
throw new InvalidArgumentException("Invalid order type");
}
};
}
function sendOrder(Order $order)
{
try {
$this->api->send($order);
} catch (ApiException $exception) {
$this->logger->log("There was a problem sending an order");
throw $exception;
}
}
Slide 38
Slide 38 text
exit%early
Slide 39
Slide 39 text
function openAccount(AccountHolder $holder, AccountType $type)
{
if ($holder->getAge() > 18 || $holder->hasParentPermission()) {
if (in_array($type->getName(), $holder->getAllowedAccountTypes())) {
if ($this->canOpenAccountType($type->getName())) {
$this->openApprovedAccount($holder, $type);
return true;
}
}
}
return false;
}
Slide 40
Slide 40 text
function openAccount(AccountHolder $holder, AccountType $type)
{
if ($holder->getAge() < 18 && !$holder->hasParentPermission()) {
return false;
}
if (!in_array($type->getName(), $holder->getAllowedAccountTypes())) {
return false;
}
if ($this->canOpenAccountType($type->getName())) {
return false;
}
$this->openApprovedAccount($holder, $type);
return true;
}