Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Updating standards to PSR-2. (#225)
Browse files Browse the repository at this point in the history
* Updating standards to PSR-2.

* Fix indenting of migrations.

* Fixing formatting in remainder of files.
  • Loading branch information
euantorano authored Jun 27, 2016
1 parent a2adad5 commit b3a6b9e
Show file tree
Hide file tree
Showing 324 changed files with 19,266 additions and 19,263 deletions.
188 changes: 94 additions & 94 deletions app/Captcha/CaptchaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,98 +14,98 @@

class CaptchaFactory implements CaptchaInterface
{
/**
* @var Store
*/
private $settings;

/**
* @var Application
*/
private $app;

const NONE = 'none';
const MYBB = 'mybb';
const RECAPTCHA = 'recaptcha';
const NOCAPTCHA = 'nocaptcha';

/**
* @param Store $settings
* @param Application $app
*/
public function __construct(Store $settings, Application $app)
{
$this->settings = $settings;
$this->app = $app;
}

/**
* {@inheritdoc}
*/
public function render($captcha = false)
{
$captcha = $this->getCaptchaClass($captcha);

// Not supported
if ($captcha === null) {
return '';
}

return $captcha->render();
}

/**
* {@inheritdoc}
*/
public function validate($captcha = false)
{
$captcha = $this->getCaptchaClass($captcha);

// Not supported
if ($captcha === null) {
return true;
}

return $captcha->validate();
}

/**
* {@inheritdoc}
*/
public function supported()
{
return true;
}

/**
* @param string $captchaName
*
* @return CaptchaInterface|null
*
* @throws CaptchaInvalidClassException
*/
private function getCaptchaClass($captchaName)
{
if ($captchaName == false) {
$captchaName = $this->settings->get('captcha.method', static::NONE);
}

if ($captchaName === static::NONE) {
return null;
}

$captchaClass = 'MyBB\\Core\\Captcha\\Captcha' . ucfirst($captchaName);

if (!class_exists($captchaClass)) {
return null;
}

$captcha = $this->app->make($captchaClass);

if (!$captcha || !($captcha instanceof CaptchaInterface) || !$captcha->supported()) {
throw new CaptchaInvalidClassException($captchaClass);
}

return $captcha;
}
/**
* @var Store
*/
private $settings;

/**
* @var Application
*/
private $app;

const NONE = 'none';
const MYBB = 'mybb';
const RECAPTCHA = 'recaptcha';
const NOCAPTCHA = 'nocaptcha';

/**
* @param Store $settings
* @param Application $app
*/
public function __construct(Store $settings, Application $app)
{
$this->settings = $settings;
$this->app = $app;
}

/**
* {@inheritdoc}
*/
public function render($captcha = false)
{
$captcha = $this->getCaptchaClass($captcha);

// Not supported
if ($captcha === null) {
return '';
}

return $captcha->render();
}

/**
* {@inheritdoc}
*/
public function validate($captcha = false)
{
$captcha = $this->getCaptchaClass($captcha);

// Not supported
if ($captcha === null) {
return true;
}

return $captcha->validate();
}

/**
* {@inheritdoc}
*/
public function supported()
{
return true;
}

/**
* @param string $captchaName
*
* @return CaptchaInterface|null
*
* @throws CaptchaInvalidClassException
*/
private function getCaptchaClass($captchaName)
{
if ($captchaName == false) {
$captchaName = $this->settings->get('captcha.method', static::NONE);
}

if ($captchaName === static::NONE) {
return null;
}

$captchaClass = 'MyBB\\Core\\Captcha\\Captcha' . ucfirst($captchaName);

if (!class_exists($captchaClass)) {
return null;
}

$captcha = $this->app->make($captchaClass);

if (!$captcha || !($captcha instanceof CaptchaInterface) || !$captcha->supported()) {
throw new CaptchaInvalidClassException($captchaClass);
}

return $captcha;
}
}
24 changes: 12 additions & 12 deletions app/Captcha/CaptchaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@

interface CaptchaInterface
{
/**
* @return string
*/
public function render();
/**
* @return string
*/
public function render();

/**
* @return bool
*/
public function validate();
/**
* @return bool
*/
public function validate();

/**
* @return bool
*/
public function supported();
/**
* @return bool
*/
public function supported();
}
108 changes: 54 additions & 54 deletions app/Captcha/CaptchaMybb.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,68 @@

class CaptchaMybb implements CaptchaInterface
{
/**
* @var DatabaseManager
*/
private $database;
/**
* @var DatabaseManager
*/
private $database;

/**
* @var Request
*/
private $request;
/**
* @var Request
*/
private $request;

/**
* @param DatabaseManager $database
* @param Request $request
*/
public function __construct(DatabaseManager $database, Request $request)
{
$this->database = $database;
$this->request = $request;
}
/**
* @param DatabaseManager $database
* @param Request $request
*/
public function __construct(DatabaseManager $database, Request $request)
{
$this->database = $database;
$this->request = $request;
}

/**
* {@inheritdoc}
*/
public function render()
{
$imagehash = md5(str_random(12));
/**
* {@inheritdoc}
*/
public function render()
{
$imagehash = md5(str_random(12));

$this->database->table('captcha')->insert([
'imagehash' => $imagehash,
'imagestring' => str_random(5),
'created_at' => new \DateTime()
]);
$this->database->table('captcha')->insert([
'imagehash' => $imagehash,
'imagestring' => str_random(5),
'created_at' => new \DateTime(),
]);

return view('captcha.mybb', compact('imagehash'));
}
return view('captcha.mybb', compact('imagehash'));
}

/**
* {@inheritdoc}
*/
public function validate()
{
$check = $this->database->table('captcha')
->where('imagehash', '=', $this->request->get('imagehash'))
->where('imagestring', '=', $this->request->get('imagestring'));
/**
* {@inheritdoc}
*/
public function validate()
{
$check = $this->database->table('captcha')
->where('imagehash', '=', $this->request->get('imagehash'))
->where('imagestring', '=', $this->request->get('imagestring'));

if ($check->count() != 1) {
$this->database->table('captcha')
->where('imagehash', '=', $this->request->get('imagehash'))
->delete();
if ($check->count() != 1) {
$this->database->table('captcha')
->where('imagehash', '=', $this->request->get('imagehash'))
->delete();

return false;
}
return false;
}

return true;
}
return true;
}

/**
* {@inheritdoc}
*/
public function supported()
{
// We need to be able to create images
return function_exists('imagecreatefrompng');
}
/**
* {@inheritdoc}
*/
public function supported()
{
// We need to be able to create images
return function_exists('imagecreatefrompng');
}
}
Loading

0 comments on commit b3a6b9e

Please sign in to comment.