Skip to content

Commit

Permalink
MINOR Updated coding conventions to require the 'public' keyword for …
Browse files Browse the repository at this point in the history
…class methods and variables
  • Loading branch information
chillu committed Jan 30, 2012
1 parent 008ecf7 commit 04a10a4
Show file tree
Hide file tree
Showing 41 changed files with 156 additions and 152 deletions.
10 changes: 5 additions & 5 deletions docs/en/howto/csv-import.md
Expand Up @@ -70,11 +70,11 @@ You can have more customized logic and interface feedback through a custom contr
class MyController extends Controller {
protected $template = "BlankPage";
function Link($action = null) {
public function Link($action = null) {
return Controller::join_links('MyController', $action);
}
function Form() {
public function Form() {
$form = new Form(
$this,
'Form',
Expand All @@ -89,7 +89,7 @@ You can have more customized logic and interface feedback through a custom contr
return $form;
}
function doUpload($data, $form) {
public function doUpload($data, $form) {
$loader = new CsvBulkLoader('MyDataObject');
$results = $loader->load($_FILES['CsvFile']['tmp_name']);
$messages = array();
Expand Down Expand Up @@ -177,13 +177,13 @@ Sample implementation of a custom loader. Assumes a CSV-file in a certain format
'callback' => 'getTeamByTitle'
)
);
static function importFirstAndLastName(&$obj, $val, $record) {
public static function importFirstAndLastName(&$obj, $val, $record) {
$parts = explode(' ', $val);
if(count($parts) != 2) return false;
$obj->FirstName = $parts[0];
$obj->LastName = $parts[1];
}
static function getTeamByTitle(&$obj, $val, $record) {
public static function getTeamByTitle(&$obj, $val, $record) {
$SQL_val = Convert::raw2sql($val);
return DataObject::get_one(
'FootballTeam', "Title = '{$SQL_val}'"
Expand Down
6 changes: 3 additions & 3 deletions docs/en/howto/extend-cms-interface.md
Expand Up @@ -85,10 +85,10 @@ Create a new file called `zzz_admin/code/BookmarkedPageExtension.php` and insert
:::php
<?php
class BookmarkedPageExtension extends DataExtension {
function extraStatics() {
public function extraStatics() {
return array('db' => array('IsBookmarked' => 'Boolean'));
}
function updateCMSFields(&$fields) {
public function updateCMSFields(&$fields) {
$fields->addFieldToTab('Root.Main',
new CheckboxField('IsBookmarked', "Show in CMS bookmarks?")
);
Expand All @@ -114,7 +114,7 @@ Add the following code to a new file `zzz_admin/code/BookmarkedLeftAndMainExtens
:::php
<?php
class BookmarkedPagesLeftAndMainExtension extends LeftAndMainExtension {
function BookmarkedPages() {
public function BookmarkedPages() {
return DataList::create('Page')->where('"IsBookmarked" = 1');
}
}
Expand Down
28 changes: 16 additions & 12 deletions docs/en/misc/coding-conventions.md
Expand Up @@ -48,15 +48,15 @@ Successive capitalized letters are not allowed, e.g. a class `XMLImporter` is no
Static methods should be in `lowercase_with_underscores()` format:

:::php
static function my_static_method() {}
public static function my_static_method() {}

Action handlers on controllers should be in `completelylowercase()` format.
This is because they go into the controller URL in the same format (eg, `home/successfullyinstalled`).
Method names are allowed to contain underscores here, in order to allow URL parts with dashes
(`mypage\my-action` gets translated to `my_action()` automatically).

:::php
function mycontrolleraction() {}
public function mycontrolleraction() {}

Object methods that will be callable from templates should be in `$this->UpperCamelCase()` format.
Alternatively, `$this->getUpperCamelCase()` will work the same way in templates -
Expand All @@ -65,7 +65,9 @@ you can access both coding styles as `$UpperCamelCase`.
Other instance methods should be in `$this->lowerCamelCase()` format:

:::php
function myInstanceMethod() {}
public function myInstanceMethod() {}

Methods inside classes must always declare their visibility by using one of the private, protected, or public modifiers.

### Variables

Expand All @@ -74,10 +76,12 @@ Static variables should be `self::$lowercase_with_underscores`
:::php
self::$my_static_variable = 'foo';

Object variables should be `$this->lowerCamelCase`
Member variables should be `$this->lowerCamelCase`

:::php
$this->myObjectVariable = 'foo';
$this->myMemberVariable = 'foo';

Member variables always declare their visibility by using one of the private, protected, or public modifiers

### Constants

Expand Down Expand Up @@ -232,20 +236,20 @@ No method or function invocation is allowed to have spaces directly
before or after the opening parathesis, as well as no space before the closing parenthesis.

:::php
function foo($arg1, $arg2) {} // good
function foo ( $arg1, $arg2 ) {} // bad
public function foo($arg1, $arg2) {} // good
public function foo ( $arg1, $arg2 ) {} // bad

Keep the opening brace on the same line as the statement.

:::php
// good
function foo() {
public function foo() {
// ...
}

:::php
// bad
function bar()
public function bar()
{
// ...
}
Expand Down Expand Up @@ -346,7 +350,7 @@ Try to avoid using PHP's ability to mix HTML into the code.

:::php
// PHP code
function getTitle() {
public function getTitle() {
return "<h2>Bad Example</h2>";
}

Expand All @@ -357,7 +361,7 @@ Better: Keep HTML in template files:

:::php
// PHP code
function getTitle() {
public function getTitle() {
return "Better Example";
}

Expand Down Expand Up @@ -410,7 +414,7 @@ Example:
Put code into the classes in the following order (where applicable).

* Static variables
* Object variables
* Member variables
* Static methods
* Data-model definition static variables. (`$db`, `$has_one`, `$many_many`, etc)
* Commonly used methods like `getCMSFields()`
Expand Down
2 changes: 1 addition & 1 deletion docs/en/misc/release-process.md
Expand Up @@ -107,7 +107,7 @@ Here's an example for replacing `Director::isDev()` with a (theoretical) `Env::i
* Returns true if your are in development mode
* @deprecated (since 2.2.2) Use {@link Env::is_dev()} instead.
*/
function isDev() {
public function isDev() {
user_error("DEPRECATED: Use Env::is_dev() instead.", E_USER_NOTICE);
return Env::is_dev();
}
Expand Down
2 changes: 1 addition & 1 deletion docs/en/misc/ss-markdown.md
Expand Up @@ -76,7 +76,7 @@ Example for PHP:

:::php
class Page extends SiteTree {
function myFunction() {
public function myFunction() {
// ...
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/en/reference/dataextension.md
Expand Up @@ -52,7 +52,7 @@ The function should return a map where the keys are the names of the static vari
:::php
class CustomMember extends DataExtension {

function extraStatics() {
public function extraStatics() {
return array(
'db' => array(
'AvatarURL' => 'Varchar',
Expand Down Expand Up @@ -161,7 +161,7 @@ extended by.

class CustomerWorkflow extends DataExtension {

function IsMarkedForDeletion() {
public function IsMarkedForDeletion() {
return ($this->owner->Account()->IsMarkedForDeletion == 1) ? true : false;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/dataobject.md
Expand Up @@ -17,7 +17,7 @@ which returns a `[api:FieldList]`''.

:::php
class MyPage extends Page {
function getCMSFields() {
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content',new CheckboxField('CustomProperty'));
return $fields;
Expand Down
4 changes: 2 additions & 2 deletions docs/en/reference/execution-pipeline.md
Expand Up @@ -64,7 +64,7 @@ This will add an object with ID 12 to the cart.
When you create a function, you can access the ID like this:

:::php
function addToCart ($request) {
public function addToCart ($request) {
$param = $r->allParams();
echo "my ID = ".$param["ID"];
$obj = DataObject::get("myProduct", $param["ID"]);
Expand All @@ -83,7 +83,7 @@ You can access the following controller-method with /team/signup
class Team extends DataObject {}

class Team_Controller extends Controller {
function signup($id, $otherId) {
public function signup($id, $otherId) {
return $this->renderWith('MyTemplate');
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/image.md
Expand Up @@ -59,7 +59,7 @@ You can also create your own functions by extending the image class, for example
return $this->getWidth() < $this->getHeight();
}
function generatePaddedImageByWidth(GD $gd,$width=600,$color="fff"){
public function generatePaddedImageByWidth(GD $gd,$width=600,$color="fff"){
return $gd->paddedResize($width, round($gd->getHeight()/($gd->getWidth()/$width),0),$color);
}
Expand Down
10 changes: 5 additions & 5 deletions docs/en/reference/member.md
Expand Up @@ -63,12 +63,12 @@ Note that if you want to look this class-name up, you can call Object::getCustom

## Overloading getCMSFields()

If you overload the built-in function getCMSFields(), then you can change the form that is used to view & edit member
If you overload the built-in public function getCMSFields(), then you can change the form that is used to view & edit member
details in the newsletter system. This function returns a `[api:FieldList]` object. You should generally start by calling
parent::getCMSFields() and manipulate the `[api:FieldList]` from there.

:::php
function getCMSFields() {
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->insertBefore(new TextField("Age"), "HTMLEmail");
$fields->removeByName("JobTitle");
Expand Down Expand Up @@ -106,18 +106,18 @@ things, you should add appropriate `[api:Permission::checkMember()]` calls to th

* Modify the field set to be displayed in the CMS detail pop-up
*/
function updateCMSFields(FieldList $currentFields) {
public function updateCMSFields(FieldList $currentFields) {
// Only show the additional fields on an appropriate kind of use
if(Permission::checkMember($this->owner->ID, "VIEW_FORUM")) {
// Edit the FieldList passed, adding or removing fields as necessary
}
}

function extraStatics() {
public function extraStatics() {
// Return an array containing keys 'db', 'has_one', 'many_many', 'belongs_many_many',
}

function somethingElse() {
public function somethingElse() {
// You can add any other methods you like, which you can call directly on the member object.
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/en/reference/partial-caching.md
Expand Up @@ -84,7 +84,7 @@ That last example is a bit large, and is complicating our template up with icky
logic into the controller

:::php
function FavouriteCacheKey() {
public function FavouriteCacheKey() {
$member = Member::currentUser();
return implode('_', array(
'favourites',
Expand Down Expand Up @@ -122,7 +122,7 @@ which will invalidate after the cache lifetime expires. If you need more control
configurable only on a site-wide basis), you could add a special function to your controller:

:::php
function BlogStatisticsCounter() {
public function BlogStatisticsCounter() {
return (int)(time() / 60 / 5); // Returns a new number every five minutes
}

Expand Down
4 changes: 2 additions & 2 deletions docs/en/reference/permission.md
Expand Up @@ -28,11 +28,11 @@ map of permission code names with a human readable explanation of its purpose (s

:::php
class Page_Controller implements PermissionProvider {
function init() {
public function init() {
if(!Permission::check("VIEW_SITE")) Security::permissionFailure();
}

function providePermissions() {
public function providePermissions() {
return array(
"VIEW_SITE" => "Access the site",
);
Expand Down
8 changes: 4 additions & 4 deletions docs/en/reference/restfulservice.md
Expand Up @@ -30,7 +30,7 @@ RestfulService (see [flickrservice](http://silverstripe.org/flickr-module/) and
//example for extending RestfulService
class FlickrService extends RestfulService {
function __construct($expiry=NULL){
public function __construct($expiry=NULL){
parent::__construct('http://www.flickr.com/services/rest/', $expiry);
$this->checkErrors = true;
}
Expand Down Expand Up @@ -121,7 +121,7 @@ could delgate the error handling to it's descendant class. To handle the errors
This will raise Youtube API specific error messages (if any).

*/
function errorCatch($response){
public function errorCatch($response){
$err_msg = $response;
if(strpos($err_msg, '<') === false)
//user_error("YouTube Service Error : $err_msg", E_USER_ERROR);
Expand All @@ -135,7 +135,7 @@ could delgate the error handling to it's descendant class. To handle the errors
If you want to bypass error handling on your sub-classes you could define that in the constructor.

:::php
function __construct($expiry=NULL){
public function __construct($expiry=NULL){
parent::__construct('http://www.flickr.com/services/rest/', $expiry);
$this->checkErrors = false; //Set checkErrors to false to bypass error checking
}
Expand All @@ -152,7 +152,7 @@ Put something like this code in mysite/code/Page.php inside class Page_Controlle

:::php
// Accepts an RSS feed URL and outputs a list of links from it
function RestfulLinks($url){
public function RestfulLinks($url){
$delicious = new RestfulService($url);
$conn = $delicious->connect();
Expand Down
10 changes: 5 additions & 5 deletions docs/en/reference/rssfeed.md
Expand Up @@ -17,12 +17,12 @@ your website, so its advisable to just create feeds from subclasses of `[api:Sit
* The second part sets up /this-page/rss to return the RSS feed. This one returns the children of the current page.

:::php
function init() {
public function init() {
RSSFeed::linkToFeed($this->Link() . "rss", "RSS feed of this blog");
parent::init();
}
function rss() {
public function rss() {
$rss = new RSSFeed($this->Children(), $this->Link(), "My feed", "This is an example feed.", "Title", "Content", "Author");
$rss->outputToBrowser();
}
Expand All @@ -45,17 +45,17 @@ something like this:

class Page_Controller extends ContentController {
function init() {
public function init() {
RSSFeed::linkToFeed($this->Link() . "rss", "10 Most Recently Updated Pages");
parent::init();
}
function rss() {
public function rss() {
$rss = new RSSFeed($this->LatestUpdates(), $this->Link(), "10 Most Recently Updated Pages", "Shows a list of the 10 most recently updated pages.", "Title", "Content", "Author");
$rss->outputToBrowser();
}

function LatestUpdates() {
public function LatestUpdates() {
// 10 is the number of pages
return DataObject::get("Page", "", "LastEdited DESC", "", 10);
}
Expand Down

0 comments on commit 04a10a4

Please sign in to comment.