Skip to content

Instantly share code, notes, and snippets.

@RyanThompson
Last active June 22, 2016 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RyanThompson/ca3b35ffca01288a6d5d to your computer and use it in GitHub Desktop.
Save RyanThompson/ca3b35ffca01288a6d5d 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