PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.8.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.8.2
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / composer / semver / src / Semver.php
matomo / app / vendor / composer / semver / src Last commit date
Constraint 1 year ago Comparator.php 1 year ago CompilingMatcher.php 1 year ago Interval.php 1 year ago Intervals.php 1 year ago Semver.php 7 months ago VersionParser.php 1 year ago
Semver.php
130 lines
1 <?php
2
3 /*
4 * This file is part of composer/semver.
5 *
6 * (c) Composer <https://github.com/composer>
7 *
8 * For the full copyright and license information, please view
9 * the LICENSE file that was distributed with this source code.
10 */
11
12 namespace Composer\Semver;
13
14 use Composer\Semver\Constraint\Constraint;
15
16 class Semver
17 {
18 const SORT_ASC = 1;
19 const SORT_DESC = -1;
20
21 /** @var VersionParser */
22 private static $versionParser;
23
24 /**
25 * Determine if given version satisfies given constraints.
26 *
27 * @param string $version
28 * @param string $constraints
29 *
30 * @return bool
31 */
32 public static function satisfies($version, $constraints)
33 {
34 if (null === self::$versionParser) {
35 self::$versionParser = new VersionParser();
36 }
37
38 $versionParser = self::$versionParser;
39 $provider = new Constraint('==', $versionParser->normalize($version));
40 $parsedConstraints = $versionParser->parseConstraints($constraints);
41
42 return $parsedConstraints->matches($provider);
43 }
44
45 /**
46 * Return all versions that satisfy given constraints.
47 *
48 * @param string[] $versions
49 * @param string $constraints
50 *
51 * @return list<string>
52 */
53 public static function satisfiedBy(array $versions, $constraints)
54 {
55 $versions = array_filter($versions, function ($version) use ($constraints) {
56 return Semver::satisfies($version, $constraints);
57 });
58
59 return array_values($versions);
60 }
61
62 /**
63 * Sort given array of versions.
64 *
65 * @param string[] $versions
66 *
67 * @return list<string>
68 */
69 public static function sort(array $versions)
70 {
71 return self::usort($versions, self::SORT_ASC);
72 }
73
74 /**
75 * Sort given array of versions in reverse.
76 *
77 * @param string[] $versions
78 *
79 * @return list<string>
80 */
81 public static function rsort(array $versions)
82 {
83 return self::usort($versions, self::SORT_DESC);
84 }
85
86 /**
87 * @param string[] $versions
88 * @param int $direction
89 *
90 * @return list<string>
91 */
92 private static function usort(array $versions, $direction)
93 {
94 if (null === self::$versionParser) {
95 self::$versionParser = new VersionParser();
96 }
97
98 $versionParser = self::$versionParser;
99 $normalized = array();
100
101 // Normalize outside of usort() scope for minor performance increase.
102 // Creates an array of arrays: [[normalized, key], ...]
103 foreach ($versions as $key => $version) {
104 $normalizedVersion = $versionParser->normalize($version);
105 $normalizedVersion = $versionParser->normalizeDefaultBranch($normalizedVersion);
106 $normalized[] = array($normalizedVersion, $key);
107 }
108
109 usort($normalized, function (array $left, array $right) use ($direction) {
110 if ($left[0] === $right[0]) {
111 return 0;
112 }
113
114 if (Comparator::lessThan($left[0], $right[0])) {
115 return -$direction;
116 }
117
118 return $direction;
119 });
120
121 // Recreate input array, using the original indexes which are now in sorted order.
122 $sorted = array();
123 foreach ($normalized as $item) {
124 $sorted[] = $versions[$item[1]];
125 }
126
127 return $sorted;
128 }
129 }
130