Skip to content

Commit

Permalink
Clean up classes
Browse files Browse the repository at this point in the history
Add missing PHP documentation, ensure camelcase, etc
  • Loading branch information
atimmer committed Feb 21, 2017
1 parent 6c87cf8 commit f2b69dd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/Whip_PHPVersionDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public function detect() {
}

/**
* Returns the message relevant for an outdated PHP version.
*
* @returns string The message to show to the user.
*/
public function getMessage() {
$textdomain = $this->textdomain;
Expand Down
4 changes: 3 additions & 1 deletion src/Whip_VersionDetector.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php


/**
* An interface that represents a version detector and message.
*/
interface Whip_VersionDetector {

/**
Expand Down
19 changes: 12 additions & 7 deletions src/Whip_VersionMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ class Whip_VersionMessage {
*/
protected $messagePresenters;

/**
* @param Whip_VersionDetector $versionDetector The version detector to use for detecting the version.
* @param array $messagePresenters The presenters that should show the message.
*/
public function __construct( Whip_VersionDetector $versionDetector, array $messagePresenters ) {
$this->versionDetector = $versionDetector;
$this->messagePresenters = $messagePresenters;
}
/**
* Requires a certain version for the given version detector and show a message using the message presenter.
*
* @param string $version
* @param string $version The version that we want to require.
*/
public function requireVersion( $version ) {
if ( ! $this->isStatisfied( $version ) ) {
Expand All @@ -33,13 +37,14 @@ public function requireVersion( $version ) {
/**
* Returns if the given version is statisfied by the installed version
*
* @param string $required_version The required version.
* @returns bool
* @param string $requiredVersion The required version.
*
*@returns bool
*/
public function isStatisfied( $required_version ) {
public function isStatisfied( $requiredVersion ) {
$current_version = $this->versionDetector->detect();

return version_compare( $current_version, $required_version, ">=" );
return version_compare( $current_version, $requiredVersion, '>=' );
}

/**
Expand All @@ -64,7 +69,7 @@ public function getVersionDetector() {
}

/**
* @param Whip_VersionDetector $versionDetector
* @param Whip_VersionDetector $versionDetector The new version detector.
*/
public function setVersionDetector( $versionDetector ) {
$this->versionDetector = $versionDetector;
Expand All @@ -80,7 +85,7 @@ public function getMessagePresenters() {
}

/**
* @param Whip_MessagePresenter[] $messagePresenters
* @param Whip_MessagePresenter[] $messagePresenters The new message presenters.
*/
public function setMessagePresenters( $messagePresenters ) {
$this->messagePresenters = $messagePresenters;
Expand Down
22 changes: 17 additions & 5 deletions src/Whip_WPMessagePresenter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php


/**
* A message presenter to show a WordPress notice.
*/
class Whip_WPMessagePresenter implements Whip_MessagePresenter {

/**
Expand All @@ -25,6 +27,9 @@ public function show( $message ) {
$this->addMessage( $message );
}

/**
* Renders the messages present in the global to notices.
*/
public function renderMessage() {
if ( empty( $GLOBALS['whip_messages'] ) ) {
return;
Expand All @@ -33,12 +38,19 @@ public function renderMessage() {
$message = $this->getLatestMessage();

?>
<div class="error">
<div class="error">
<?php echo $this->kses( $message ); ?>
</div>
</div>
<?php
}

/**
* Removes content from the message that we don't want to show
*
* @param string $message The message to clean.
*
* @return string The cleaned message.
*/
public function kses( $message ) {
return wp_kses( $message, array(
'a' => array(
Expand Down Expand Up @@ -66,7 +78,7 @@ public function ensureDataStructure() {
* @param string $message The message to add to the global.
*/
public function addMessage( $message ) {
$whipVersion = require dirname( __FILE__ ) . '/version.php';
$whipVersion = require dirname( __FILE__ ) . '/version.php';

$this->ensureDataStructure();

Expand All @@ -76,7 +88,7 @@ public function addMessage( $message ) {
/**
* Retrieves the latest message from the messages global
*
* @return string The latest message from the messages global.
* @return string The latest message from the messages global.
*/
public function getLatestMessage() {
$messages = $GLOBALS['whip_messages'];
Expand Down

0 comments on commit f2b69dd

Please sign in to comment.