PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← All changes | includes/sdk/google/google/gax/src/ResourceTemplate/Parser.php +26 -26 1.0.3 → 1.4.2 View file →
@@ -29,11 +29,11 @@
29 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 32 */
33 -namespace Dudlewebs\WPMCS\Google\ApiCore\ResourceTemplate;
33 +namespace Dudlewebs\WPMCS\GCP\Google\ApiCore\ResourceTemplate;
34 34
35 -use Dudlewebs\WPMCS\Google\ApiCore\ValidationException;
35 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\ValidationException;
36 36 /**
37 37 * Collection of methods for parsing Segments.
38 38 *
39 39 * @internal
@@ -46,18 +46,18 @@
46 46 * @param string|null $path
47 47 * @return array
48 48 * @throws ValidationException
49 49 */
50 - public static function parseSegments(string $path = null)
50 + public static function parseSegments(?string $path = null)
51 51 {
52 52 if (empty($path)) {
53 - throw new ValidationException("Cannot parse empty path");
53 + throw new ValidationException('Cannot parse empty path');
54 54 }
55 55 $segments = [];
56 56 $index = 0;
57 57 $nextLiteral = '';
58 58 $segments[] = self::parseSegmentFromPath($path, $nextLiteral, $index);
59 - while ($index < strlen($path)) {
59 + while ($index < \strlen($path)) {
60 60 self::parseLiteralFromPath($nextLiteral, $path, $index);
61 61 $segments[] = self::parseSegmentFromPath($path, $nextLiteral, $index);
62 62 }
63 63 return $segments;
@@ -73,31 +73,31 @@
73 73 * @throws ValidationException
74 74 */
75 75 private static function parseSegmentFromPath(string $path, string &$nextLiteral, int &$index)
76 76 {
77 - if ($index >= strlen($path)) {
77 + if ($index >= \strlen($path)) {
78 78 // A trailing '/' has caused the index to exceed the bounds
79 79 // of the string - provide a helpful error message.
80 - throw self::parseError($path, strlen($path) - 1, "invalid trailing '/'");
80 + throw self::parseError($path, \strlen($path) - 1, "invalid trailing '/'");
81 81 }
82 82 if ($path[$index] === '{') {
83 83 // Validate that the { has a matching }
84 - $closingBraceIndex = strpos($path, '}', $index);
84 + $closingBraceIndex = \strpos($path, '}', $index);
85 85 if ($closingBraceIndex === \false) {
86 - throw self::parseError($path, strlen($path), "Expected '}' to match '{' at index {$index}, got end of string");
86 + throw self::parseError($path, \strlen($path), "Expected '}' to match '{' at index {$index}, got end of string");
87 87 }
88 88 $segmentStringLengthWithoutBraces = $closingBraceIndex - $index - 1;
89 - $segmentStringWithoutBraces = substr($path, $index + 1, $segmentStringLengthWithoutBraces);
89 + $segmentStringWithoutBraces = \substr($path, $index + 1, $segmentStringLengthWithoutBraces);
90 90 $index = $closingBraceIndex + 1;
91 91 $nextLiteral = '/';
92 - $remainingPath = substr($path, $index);
92 + $remainingPath = \substr($path, $index);
93 93 if (!empty($remainingPath)) {
94 94 // Find the firstnon-slash separator seen, if any.
95 - $nextSlashIndex = strpos($remainingPath, '/', 0);
95 + $nextSlashIndex = \strpos($remainingPath, '/', 0);
96 96 $nonSlashSeparators = ['-', '_', '~', '.'];
97 97 foreach ($nonSlashSeparators as $nonSlashSeparator) {
98 - $nonSlashSeparatorIndex = strpos($remainingPath, $nonSlashSeparator, 0);
99 - $nextOpenBraceIndex = strpos($remainingPath, '{', 0);
98 + $nonSlashSeparatorIndex = \strpos($remainingPath, $nonSlashSeparator, 0);
99 + $nextOpenBraceIndex = \strpos($remainingPath, '{', 0);
100 100 if ($nonSlashSeparatorIndex !== \false && $nonSlashSeparatorIndex === $nextOpenBraceIndex - 1) {
101 101 $index += $nonSlashSeparatorIndex;
102 102 $nextLiteral = $nonSlashSeparator;
103 103 break;
@@ -105,13 +105,13 @@
105 105 }
106 106 }
107 107 return self::parseVariableSegment($segmentStringWithoutBraces, $nextLiteral);
108 108 } else {
109 - $nextSlash = strpos($path, '/', $index);
109 + $nextSlash = \strpos($path, '/', $index);
110 110 if ($nextSlash === \false) {
111 - $nextSlash = strlen($path);
111 + $nextSlash = \strlen($path);
112 112 }
113 - $segmentString = substr($path, $index, $nextSlash - $index);
113 + $segmentString = \substr($path, $index, $nextSlash - $index);
114 114 $nextLiteral = '/';
115 115 $index = $nextSlash;
116 116 return self::parse($segmentString, $path, $index);
117 117 }
@@ -149,20 +149,20 @@
149 149 */
150 150 private static function parseVariableSegment(string $segmentStringWithoutBraces, string $separatorLiteral)
151 151 {
152 152 // Validate there are no nested braces
153 - $nestedOpenBracket = strpos($segmentStringWithoutBraces, '{');
153 + $nestedOpenBracket = \strpos($segmentStringWithoutBraces, '{');
154 154 if ($nestedOpenBracket !== \false) {
155 155 throw new ValidationException("Unexpected '{' parsing segment {$segmentStringWithoutBraces} at index {$nestedOpenBracket}");
156 156 }
157 - $equalsIndex = strpos($segmentStringWithoutBraces, '=');
157 + $equalsIndex = \strpos($segmentStringWithoutBraces, '=');
158 158 if ($equalsIndex === \false) {
159 159 // If the variable does not contain '=', we assume the pattern is '*' as per google.rpc.Http
160 160 $variableKey = $segmentStringWithoutBraces;
161 - $nestedResource = new RelativeResourceTemplate("*");
161 + $nestedResource = new RelativeResourceTemplate('*');
162 162 } else {
163 - $variableKey = substr($segmentStringWithoutBraces, 0, $equalsIndex);
164 - $nestedResourceString = substr($segmentStringWithoutBraces, $equalsIndex + 1);
163 + $variableKey = \substr($segmentStringWithoutBraces, 0, $equalsIndex);
164 + $nestedResourceString = \substr($segmentStringWithoutBraces, $equalsIndex + 1);
165 165 $nestedResource = new RelativeResourceTemplate($nestedResourceString);
166 166 }
167 167 if (!self::isValidLiteral($variableKey)) {
168 168 throw new ValidationException("Unexpected characters in variable name {$variableKey}");
@@ -177,13 +177,13 @@
177 177 * @throws ValidationException
178 178 */
179 179 private static function parseLiteralFromPath(string $literal, string $path, int &$index)
180 180 {
181 - $literalLength = strlen($literal);
182 - if (strlen($path) < $index + $literalLength) {
181 + $literalLength = \strlen($literal);
182 + if (\strlen($path) < $index + $literalLength) {
183 183 throw self::parseError($path, $index, "expected '{$literal}'");
184 184 }
185 - $consumedLiteral = substr($path, $index, $literalLength);
185 + $consumedLiteral = \substr($path, $index, $literalLength);
186 186 if ($consumedLiteral !== $literal) {
187 187 throw self::parseError($path, $index, "expected '{$literal}'");
188 188 }
189 189 $index += $literalLength;
@@ -201,7 +201,7 @@
201 201 * @return bool
202 202 */
203 203 private static function isValidLiteral(string $literal)
204 204 {
205 - return preg_match("/^[0-9a-zA-Z\\.\\-~_]+\$/", $literal) === 1;
205 + return \preg_match('/^[0-9a-zA-Z\\.\\-~_]+$/', $literal) === 1;
206 206 }
207 207 }