From 784531b5ceee4eaf14ffd6ea93d7ccac330e0638 Mon Sep 17 00:00:00 2001 From: Larry Lewis Date: Thu, 23 Oct 2014 10:15:37 +1100 Subject: [PATCH 1/2] Added 'dev' to stability --- src/Version/Stability.php | 167 ++++++++++++++++++++++---------------- 1 file changed, 97 insertions(+), 70 deletions(-) diff --git a/src/Version/Stability.php b/src/Version/Stability.php index c4b1bb8..01193b7 100644 --- a/src/Version/Stability.php +++ b/src/Version/Stability.php @@ -7,82 +7,109 @@ class Stability { - const REGEX = '[-|_|\.]{0,1}([R|r][C|c]|pl|a|alpha|[B|b][E|e][T|t][A|a]|b|B|patch|stable|p)\.{0,1}(\d*)'; + const REGEX = '[-|_|\.]{0,1}([R|r][C|c]|pl|a|alpha|[B|b][E|e][T|t][A|a]|b|B|patch|stable|p)\.{0,1}(\d*)'; - /** - * @var string - */ - private $stability; + /** + * @var string + */ + private $stability; - /** - * @var int - */ - private $number; + /** + * @var int + */ + private $number; - public function __construct($stability = 'stable', $number = null) - { - if (strlen($stability) == 0) { - $stability = 'stable'; - } + public function __construct( $stability = 'stable', $number = null ) + { + if( strlen( $stability ) == 0 ) + { + $stability = 'stable'; + } + $stability = strtolower( $stability ); + switch( $stability ) + { + case 'rc': + $stability = 'RC'; + break; + case 'patch': + case 'pl': + case 'p': + $stability = 'patch'; + break; + case 'beta': + case 'b': + $stability = 'beta'; + break; + case 'alpha': + case 'a': + $stability = 'alpha'; + break; + case 'dev': + case 'd': + $stability = 'dev'; + break; + } + $this->stability = $stability; + $this->number = $number; + } - if (strtolower($stability) == 'rc') { - $stability = 'RC'; - } elseif (in_array(strtolower($stability), array('pl', 'patch', 'p'))) { - $stability = 'patch'; - } elseif (in_array(strtolower($stability), array('beta', 'b'))) { - $stability = 'beta'; - } elseif (in_array(strtolower($stability), array('a'))) { - $stability = 'alpha'; - } + public function __toString() + { + return $this->stability . $this->number; + } - $this->stability = $stability; - $this->number = $number; - } + public function isStable() + { + return $this->stability == 'stable'; + } - public function __toString() - { - return $this->stability . $this->number; - } + /** + * @return string + */ + public function getStability() + { + return $this->stability; + } - public function isStable() - { - return $this->stability == 'stable'; - } + public function compare( Stability $stability ) + { + if( $this->toInt( $this->stability ) > $this->toInt( $stability->stability ) ) + { + return 1; + } + if( $this->toInt( $this->stability ) < $this->toInt( $stability->stability ) ) + { + return -1; + } + if( $this->number > $stability->number ) + { + return 1; + } + if( $this->number < $stability->number ) + { + return -1; + } + return 0; + } - /** - * @return string - */ - public function getStability() - { - return $this->stability; - } - - public function compare(Stability $stability) - { - if($this->toInt($this->stability) > $this->toInt($stability->stability)) { - return 1; - } - if($this->toInt($this->stability) < $this->toInt($stability->stability)) { - return -1; - } - if($this->number > $stability->number) { - return 1; - } - if($this->number < $stability->number) { - return -1; - } - return 0; - } - - private function toInt($stability) - { - switch($stability) { - case 'alpha': return 1; - case 'beta': return 2; - case 'RC': return 3; - case 'stable': return 4; - case 'patch': return 5; - default: throw new InvalidArgumentException('Invalid stability: ' . $stability); - } - } + private function toInt( $stability ) + { + switch( $stability ) + { + case 'dev': + return 1; + case 'alpha': + return 2; + case 'beta': + return 3; + case 'RC': + return 4; + case 'stable': + return 5; + case 'patch': + return 6; + default: + throw new InvalidArgumentException( 'Invalid stability: ' . $stability ); + } + } } From 4b7486ab5b34932578a0b972a86e9c936186a042 Mon Sep 17 00:00:00 2001 From: Larry Lewis Date: Sat, 25 Oct 2014 10:20:09 +1100 Subject: [PATCH 2/2] As requested set to spaces rather han tabs --- src/Version/Stability.php | 194 +++++++++++++++++++------------------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/src/Version/Stability.php b/src/Version/Stability.php index 01193b7..5b715c7 100644 --- a/src/Version/Stability.php +++ b/src/Version/Stability.php @@ -7,109 +7,109 @@ class Stability { - const REGEX = '[-|_|\.]{0,1}([R|r][C|c]|pl|a|alpha|[B|b][E|e][T|t][A|a]|b|B|patch|stable|p)\.{0,1}(\d*)'; + const REGEX = '[-|_|\.]{0,1}([R|r][C|c]|pl|a|alpha|[B|b][E|e][T|t][A|a]|b|B|patch|stable|p)\.{0,1}(\d*)'; - /** - * @var string - */ - private $stability; + /** + * @var string + */ + private $stability; - /** - * @var int - */ - private $number; + /** + * @var int + */ + private $number; - public function __construct( $stability = 'stable', $number = null ) - { - if( strlen( $stability ) == 0 ) - { - $stability = 'stable'; - } - $stability = strtolower( $stability ); - switch( $stability ) - { - case 'rc': - $stability = 'RC'; - break; - case 'patch': - case 'pl': - case 'p': - $stability = 'patch'; - break; - case 'beta': - case 'b': - $stability = 'beta'; - break; - case 'alpha': - case 'a': - $stability = 'alpha'; - break; - case 'dev': - case 'd': - $stability = 'dev'; - break; - } - $this->stability = $stability; - $this->number = $number; - } + public function __construct( $stability = 'stable', $number = null ) + { + if( strlen( $stability ) == 0 ) + { + $stability = 'stable'; + } + $stability = strtolower( $stability ); + switch( $stability ) + { + case 'rc': + $stability = 'RC'; + break; + case 'patch': + case 'pl': + case 'p': + $stability = 'patch'; + break; + case 'beta': + case 'b': + $stability = 'beta'; + break; + case 'alpha': + case 'a': + $stability = 'alpha'; + break; + case 'dev': + case 'd': + $stability = 'dev'; + break; + } + $this->stability = $stability; + $this->number = $number; + } - public function __toString() - { - return $this->stability . $this->number; - } + public function __toString() + { + return $this->stability . $this->number; + } - public function isStable() - { - return $this->stability == 'stable'; - } + public function isStable() + { + return $this->stability == 'stable'; + } - /** - * @return string - */ - public function getStability() - { - return $this->stability; - } + /** + * @return string + */ + public function getStability() + { + return $this->stability; + } - public function compare( Stability $stability ) - { - if( $this->toInt( $this->stability ) > $this->toInt( $stability->stability ) ) - { - return 1; - } - if( $this->toInt( $this->stability ) < $this->toInt( $stability->stability ) ) - { - return -1; - } - if( $this->number > $stability->number ) - { - return 1; - } - if( $this->number < $stability->number ) - { - return -1; - } - return 0; - } + public function compare( Stability $stability ) + { + if( $this->toInt( $this->stability ) > $this->toInt( $stability->stability ) ) + { + return 1; + } + if( $this->toInt( $this->stability ) < $this->toInt( $stability->stability ) ) + { + return -1; + } + if( $this->number > $stability->number ) + { + return 1; + } + if( $this->number < $stability->number ) + { + return -1; + } + return 0; + } - private function toInt( $stability ) - { - switch( $stability ) - { - case 'dev': - return 1; - case 'alpha': - return 2; - case 'beta': - return 3; - case 'RC': - return 4; - case 'stable': - return 5; - case 'patch': - return 6; - default: - throw new InvalidArgumentException( 'Invalid stability: ' . $stability ); - } - } + private function toInt( $stability ) + { + switch( $stability ) + { + case 'dev': + return 1; + case 'alpha': + return 2; + case 'beta': + return 3; + case 'RC': + return 4; + case 'stable': + return 5; + case 'patch': + return 6; + default: + throw new InvalidArgumentException( 'Invalid stability: ' . $stability ); + } + } }