Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.
This generates a lower bound for the ^8 value of 800800000000 and an upper bound for the ^9 of 100000000000 (which would be <10).
But them comparing the numbers, 800800000000 is bigger than 100000000000 which makes no sense.
If we pad the zeroes on the left then we could easily do integer version comparisons, which is the most likely usage of the integer version.
So this line return str_pad($val, $this->zeros, 0); could change to return str_pad($val, $this->zeros, 0, STR_PAD_LEFT);
The zeroes are being added on the right side, but this generates wrong ranges.
ie:
var_dump((new SemverConverter(3, 4))->convert('^8.8 || ^9');
This generates a lower bound for the
^8
value of800800000000
and an upper bound for the^9
of100000000000
(which would be<10
).But them comparing the numbers, 800800000000 is bigger than 100000000000 which makes no sense. If we pad the zeroes on the left then we could easily do integer version comparisons, which is the most likely usage of the integer version.
So this line
return str_pad($val, $this->zeros, 0);
could change toreturn str_pad($val, $this->zeros, 0, STR_PAD_LEFT);