Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anunay/83b60711bfaaa4fd9e94a03c8c6f91ce to your computer and use it in GitHub Desktop.
Save anunay/83b60711bfaaa4fd9e94a03c8c6f91ce to your computer and use it in GitHub Desktop.
An example of the coding standards by AnomalyLabs.
<?php namespace Acme;
/**
* Class FooBar
*
* @link http://anomaly.is/foo-bar
* @author AnomalyLabs, Inc. <hello@anomaly.is>
* @author Ryan Thompson <ryan@anomaly.is>
* @package Acme
*/
class FooBar
{
/**
* The foo value.
*
* @var int
*/
protected $foo = 20;
/**
* The bar value.
*
* @var int
*/
protected $bar;
/**
* Create a new FooBar instance.
*
* @param string $bar
*/
public function __construct($bar)
{
$this->bar = $bar;
}
/**
* Do something awesome.
*
* @param string $dummy
* @param array $options
* @return string|null
* @throws \Exception
*/
public function awesome($dummy, array $options = [])
{
$mergedOptions = array_merge(
[
'some_default' => 'values',
'another_default' => 'more values',
],
$options
);
if ($dummy === true) {
return 'wowzers';
}
if ($dummy === 'something') {
if ($mergedOptions['some_default'] === 'values') {
return substr($dummy, 0, 5);
}
return ucwords($dummy);
}
throw new \Exception(sprintf('Unrecognized dummy option "%s"', $dummy));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment