Skip to content
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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
composer.phar
vendor/

.idea*

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

Copy link
Member

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.

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

Copy link
Member

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.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, thank you

Copy link
Author

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.

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.

Copy link
Member

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

# 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 projects/rpsls-laravel-example/app/controllers/HomeController.php
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');
}

}
32 changes: 18 additions & 14 deletions projects/rpsls-laravel-example/app/lib/RPSLS/Player.php
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)];
}
}
96 changes: 51 additions & 45 deletions projects/rpsls-laravel-example/app/lib/RPSLS/Referee.php
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;
}
}
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);
}
}
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);
}