-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert interval arrays to a value object
- Loading branch information
Showing
3 changed files
with
126 additions
and
59 deletions.
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of composer/semver. | ||
* | ||
* (c) Composer <https://github.com/composer> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Composer\Semver; | ||
|
||
use Composer\Semver\Constraint\Constraint; | ||
|
||
class Interval | ||
{ | ||
/** @var Constraint */ | ||
private $start; | ||
/** @var Constraint */ | ||
private $end; | ||
|
||
public function __construct(Constraint $start, Constraint $end) | ||
{ | ||
$this->start = $start; | ||
$this->end = $end; | ||
} | ||
|
||
/** | ||
* @return Constraint | ||
*/ | ||
public function getStart() | ||
{ | ||
return $this->start; | ||
} | ||
|
||
/** | ||
* @return Constraint | ||
*/ | ||
public function getEnd() | ||
{ | ||
return $this->end; | ||
} | ||
|
||
/** | ||
* @return Constraint | ||
*/ | ||
public static function zero() | ||
{ | ||
static $zero; | ||
|
||
if (null === $zero) { | ||
$zero = new Constraint('>=', '0.0.0.0-dev'); | ||
} | ||
|
||
return $zero; | ||
} | ||
|
||
/** | ||
* @return Constraint | ||
*/ | ||
public static function positiveInfinity() | ||
{ | ||
static $positiveInfinity; | ||
|
||
if (null === $positiveInfinity) { | ||
$positiveInfinity = new Constraint('<', PHP_INT_MAX.'.0.0.0'); | ||
} | ||
|
||
return $positiveInfinity; | ||
} | ||
|
||
/** | ||
* @return self | ||
*/ | ||
public static function any() | ||
{ | ||
return new self(self::zero(), self::positiveInfinity()); | ||
} | ||
|
||
/** | ||
* @return Constraint | ||
*/ | ||
public static function anyDev() | ||
{ | ||
static $anyDev; | ||
|
||
if (null === $anyDev) { | ||
// this ideally should be an EmptyConstraint but the code expects Constraint instances so | ||
// this makes it work with less workarounds/checks above | ||
$anyDev = new Constraint('==', 'dev*'); | ||
} | ||
|
||
return $anyDev; | ||
} | ||
} |
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
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