-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some DocBlocks, comments, formatting because why not try? #1
Open
marcusmoore
wants to merge
3
commits into
sdphp:master
Choose a base branch
from
marcusmoore:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
composer.phar | ||
vendor/ | ||
|
||
.idea* | ||
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file | ||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file | ||
# composer.lock |
128 changes: 75 additions & 53 deletions
128
projects/rpsls-laravel-example/app/controllers/HomeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,78 @@ | ||
<?php | ||
|
||
class HomeController extends BaseController { | ||
|
||
var $actionLog, $actionLogTransformer; | ||
|
||
public function __construct(ActionLogInterface $actionLog, TransformerInterface $actionLogTransformer) | ||
{ | ||
$this->actionLog = $actionLog; | ||
$this->actionLogTransformer = $actionLogTransformer; | ||
} | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Home Controller | ||
|-------------------------------------------------------------------------- | ||
| | ||
| You may wish to use controllers instead of, or in addition to, Closure | ||
| based routes. That's great! Here is an example controller method to | ||
| get you started. To route to this controller, just add the route: | ||
| | ||
| Route::get('/', 'HomeController@showWelcome'); | ||
| | ||
*/ | ||
|
||
public function showChooser() | ||
{ | ||
return View::make('chooser'); | ||
} | ||
class HomeController extends BaseController { | ||
|
||
var $actionLog, $actionLogTransformer; | ||
|
||
public function __construct(ActionLogInterface $actionLog, TransformerInterface $actionLogTransformer) | ||
{ | ||
$this->actionLog = $actionLog; | ||
$this->actionLogTransformer = $actionLogTransformer; | ||
} | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Home Controller | ||
|-------------------------------------------------------------------------- | ||
| | ||
| You may wish to use controllers instead of, or in addition to, Closure | ||
| based routes. That's great! Here is an example controller method to | ||
| get you started. To route to this controller, just add the route: | ||
| | ||
| Route::get('/', 'HomeController@showWelcome'); | ||
| | ||
*/ | ||
|
||
public function showChooser() | ||
{ | ||
// Load default view | ||
return View::make('chooser'); | ||
} | ||
|
||
public function throwAction($action) | ||
{ | ||
/* | ||
* Make sure the action given is valid | ||
* /throw/rock works... | ||
* /throw/nothing doesn't... | ||
*/ | ||
$validator = Validator::make(['action' => $action], [ | ||
'action' => 'required|in:rock,paper,scissors,lizard,spock' | ||
]); | ||
|
||
if ( $validator->passes() ) | ||
{ | ||
// Represents the user | ||
$judge = new \RPSLS\Referee(); | ||
|
||
// Represents the server | ||
$player = new \RPSLS\Player(); | ||
|
||
public function throwAction($action) | ||
{ | ||
$validator = Validator::make(['action' => $action], [ | ||
'action' => 'required|in:rock,paper,scissors,lizard,spock' | ||
]); | ||
if($validator->passes()) | ||
{ | ||
$judge = new \RPSLS\Referee(); | ||
$player = new \RPSLS\Player(); | ||
$myAction = $player->chooseAction(); | ||
$results = $judge->judgeResults($action, $myAction); | ||
$record = $this->actionLog->create( | ||
$this->actionLogTransformer->transform([ | ||
'user_action' => $action, | ||
'ai_action' => $myAction, | ||
'results' => $results, | ||
]) | ||
); | ||
return View::make('chooser')->with( | ||
['results' => $results, 'yourChoice' => $action, 'myChoice' => $myAction] | ||
); | ||
} | ||
Session::flash('error', $validator->messages()); | ||
return Redirect::route('chooser'); | ||
} | ||
|
||
} | ||
// Chose server action | ||
$myAction = $player->chooseAction(); | ||
|
||
// Who won? | ||
$results = $judge->judgeResults($action, $myAction); | ||
|
||
// Record results to persistance | ||
$record = $this->actionLog->create( | ||
$this->actionLogTransformer->transform([ | ||
'user_action' => $action, | ||
'ai_action' => $myAction, | ||
'results' => $results, | ||
]) | ||
); | ||
|
||
// Display results to user | ||
return View::make('chooser')->with( | ||
['results' => $results, 'yourChoice' => $action, 'myChoice' => $myAction] | ||
); | ||
} | ||
|
||
// Validation failed...pass an error message to the user | ||
Session::flash('error', $validator->messages()); | ||
|
||
return Redirect::route('chooser'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
<?php | ||
|
||
namespace RPSLS; | ||
namespace RPSLS; | ||
|
||
class Player { | ||
class Player { | ||
|
||
var $options = [ | ||
'rock', | ||
'paper', | ||
'scissors', | ||
'lizard', | ||
'spock', | ||
]; | ||
var $options = [ | ||
'rock', | ||
'paper', | ||
'scissors', | ||
'lizard', | ||
'spock', | ||
]; | ||
|
||
public function chooseAction() | ||
{ | ||
return $this->options[array_rand($this->options)]; | ||
} | ||
} | ||
|
||
/** | ||
* Get the Player's action | ||
*/ | ||
public function chooseAction() | ||
{ | ||
return $this->options[array_rand($this->options)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,54 @@ | ||
<?php | ||
|
||
namespace RPSLS; | ||
namespace RPSLS; | ||
|
||
class Referee { | ||
public function judgeResults($throw1, $throw2) | ||
{ | ||
$rules = [ | ||
'rock' => [ | ||
'rock' => 'draw', | ||
'paper' => 'lose', | ||
'scissors' => 'win', | ||
'lizard' => 'win', | ||
'spock' => 'lose', | ||
], | ||
'paper' => [ | ||
'rock' => 'win', | ||
'paper' => 'draw', | ||
'scissors' => 'lose', | ||
'lizard' => 'lose', | ||
'spock' => 'win', | ||
], | ||
'scissors' => [ | ||
'rock' => 'lose', | ||
'paper' => 'win', | ||
'scissors' => 'draw', | ||
'lizard' => 'win', | ||
'spock' => 'lose', | ||
], | ||
'lizard' => [ | ||
'rock' => 'lose', | ||
'paper' => 'win', | ||
'scissors' => 'lose', | ||
'lizard' => 'tie', | ||
'spock' => 'win', | ||
], | ||
'spock' => [ | ||
'rock' => 'win', | ||
'paper' => 'lose', | ||
'scissors' => 'win', | ||
'lizard' => 'lose', | ||
'spock' => 'draw', | ||
], | ||
]; | ||
$result = $rules[$throw1][$throw2]; | ||
return $result; | ||
} | ||
} | ||
class Referee { | ||
|
||
protected $rules = [ | ||
'rock' => [ | ||
'rock' => 'draw', | ||
'paper' => 'lose', | ||
'scissors' => 'win', | ||
'lizard' => 'win', | ||
'spock' => 'lose', | ||
], | ||
'paper' => [ | ||
'rock' => 'win', | ||
'paper' => 'draw', | ||
'scissors' => 'lose', | ||
'lizard' => 'lose', | ||
'spock' => 'win', | ||
], | ||
'scissors' => [ | ||
'rock' => 'lose', | ||
'paper' => 'win', | ||
'scissors' => 'draw', | ||
'lizard' => 'win', | ||
'spock' => 'lose', | ||
], | ||
'lizard' => [ | ||
'rock' => 'lose', | ||
'paper' => 'win', | ||
'scissors' => 'lose', | ||
'lizard' => 'tie', | ||
'spock' => 'win', | ||
], | ||
'spock' => [ | ||
'rock' => 'win', | ||
'paper' => 'lose', | ||
'scissors' => 'win', | ||
'lizard' => 'lose', | ||
'spock' => 'draw', | ||
], | ||
]; | ||
|
||
/** | ||
* Return winner of match | ||
*/ | ||
public function judgeResults($throw1, $throw2) | ||
{ | ||
$result = $this->rules[$throw1][$throw2]; | ||
|
||
return $result; | ||
} | ||
} |
44 changes: 29 additions & 15 deletions
44
projects/rpsls-laravel-example/app/lib/Repositories/ActionLogEloquent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
<?php | ||
|
||
class ActionLogEloquent implements ActionLogInterface | ||
{ | ||
public function all(){ | ||
return ActionLog::all(); | ||
} | ||
class ActionLogEloquent implements ActionLogInterface { | ||
|
||
public function find($id){ | ||
return ActionLog::find($id); | ||
} | ||
/** | ||
* Return all logged actions | ||
*/ | ||
public function all() | ||
{ | ||
return ActionLog::all(); | ||
} | ||
|
||
public function create($data) | ||
{ | ||
$record = new ActionLog; | ||
$record->user_action = $data['user_action']; | ||
return ActionLog::create($data); | ||
} | ||
} | ||
/** | ||
* Return specific logged action | ||
* @param $id integer | ||
*/ | ||
public function find($id) | ||
{ | ||
return ActionLog::find($id); | ||
} | ||
|
||
/** | ||
* Create a logged action | ||
* @param $data array | ||
*/ | ||
public function create(array $data) | ||
{ | ||
$record = new ActionLog; | ||
$record->user_action = $data['user_action']; | ||
|
||
return ActionLog::create($data); | ||
} | ||
} |
24 changes: 19 additions & 5 deletions
24
projects/rpsls-laravel-example/app/lib/Repositories/ActionLogInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
<?php | ||
|
||
interface ActionLogInterface { | ||
public function all(); | ||
public function find($id); | ||
public function create($data); | ||
} | ||
interface ActionLogInterface { | ||
|
||
/** | ||
* Return all logged actions | ||
*/ | ||
public function all(); | ||
|
||
/** | ||
* Return specific logged action | ||
* @param $id integer | ||
*/ | ||
public function find($id); | ||
|
||
/** | ||
* Create a logged action | ||
* @param $data array | ||
*/ | ||
public function create(array $data); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its actually a good idea to put this in your global gitignore, instead of the project one, as not everyone uses phpstorm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would it matter if someone wasn't using phpStorm? It just wouldn't do anything. What if someone was using phpStorm and didn't have this in their global gitignore? (<= Rhetorical question)
I don't see any harm having it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It adds stuff to the gitignore that isn't necessary.
project gitignores are meant to house things that should be ignored for that specific project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are being overly critical. I will restate my original opinion, I don't see any harm having it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not being critical at all, i'm simply offering an point of view that is commonly accepted by the open source community.
https://github.com/laravel/framework/blob/4.2/.gitignore
https://github.com/symfony/symfony/blob/2.7/.gitignore
just two of the biggest OS php projects out there, as reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa! I honestly didn't know (or forgot) about a global gitignore file. This is news to me and as Eric said, noted.
I can go either way.
Thanks for the input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theres a really good repo by github, https://github.com/github/gitignore/ that's got a lot of good gitignore information.
They list all of the IDE and system specific ones in the Global directory.
Its a pretty good resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we cloned it to the SDPHP Repo sometime ago to bring it to peoples attention
https://github.com/sdphp/gitignore