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/RelativeResourceTemplate.php +28 -28 1.0.1 → 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 * Represents a relative resource template, meaning that it will never contain a leading slash or
38 38 * trailing verb (":<verb>").
39 39 *
@@ -100,16 +100,16 @@
100 100 if ($segment->getSegmentType() === Segment::LITERAL_SEGMENT) {
101 101 $literalSegments[] = $segment;
102 102 continue;
103 103 }
104 - if (!array_key_exists($key, $bindings)) {
104 + if (!\array_key_exists($key, $bindings)) {
105 105 throw $this->renderingException($bindings, "missing required binding '{$key}' for segment '{$segment}'");
106 106 }
107 107 $value = $bindings[$key];
108 - if (!is_null($value) && $segment->matches($value)) {
108 + if (!\is_null($value) && $segment->matches($value)) {
109 109 $literalSegments[] = new Segment(Segment::LITERAL_SEGMENT, $value, $segment->getValue(), $segment->getTemplate(), $segment->getSeparator());
110 110 } else {
111 - $valueString = is_null($value) ? "null" : "'{$value}'";
111 + $valueString = \is_null($value) ? 'null' : "'{$value}'";
112 112 throw $this->renderingException($bindings, "expected binding '{$key}' to match segment '{$segment}', instead got {$valueString}");
113 113 }
114 114 }
115 115 return self::renderSegments($literalSegments);
@@ -143,24 +143,24 @@
143 143 // build a list of [string, Segment] tuples, where the string component is the appropriate
144 144 // key.
145 145 $keySegmentTuples = self::buildKeySegmentTuples($this->segments);
146 146 $flattenedKeySegmentTuples = self::flattenKeySegmentTuples($keySegmentTuples);
147 - $flattenedKeySegmentTuplesCount = count($flattenedKeySegmentTuples);
148 - assert($flattenedKeySegmentTuplesCount > 0);
149 - $slashPathPieces = explode('/', $path);
147 + $flattenedKeySegmentTuplesCount = \count($flattenedKeySegmentTuples);
148 + \assert($flattenedKeySegmentTuplesCount > 0);
149 + $slashPathPieces = \explode('/', $path);
150 150 $pathPieces = [];
151 151 $pathPiecesIndex = 0;
152 152 $startIndex = 0;
153 - $slashPathPiecesCount = count($slashPathPieces);
153 + $slashPathPiecesCount = \count($slashPathPieces);
154 154 $doubleWildcardPieceCount = $slashPathPiecesCount - $flattenedKeySegmentTuplesCount + 1;
155 - for ($i = 0; $i < count($flattenedKeySegmentTuples); $i++) {
155 + for ($i = 0; $i < \count($flattenedKeySegmentTuples); $i++) {
156 156 $segmentKey = $flattenedKeySegmentTuples[$i][0];
157 157 $segment = $flattenedKeySegmentTuples[$i][1];
158 158 // In our flattened list of segments, we should never encounter a variable segment
159 - assert($segment->getSegmentType() !== Segment::VARIABLE_SEGMENT);
159 + \assert($segment->getSegmentType() !== Segment::VARIABLE_SEGMENT);
160 160 if ($segment->getSegmentType() == Segment::DOUBLE_WILDCARD_SEGMENT) {
161 - $pathPiecesForSegment = array_slice($slashPathPieces, $pathPiecesIndex, $doubleWildcardPieceCount);
162 - $pathPiece = implode('/', $pathPiecesForSegment);
161 + $pathPiecesForSegment = \array_slice($slashPathPieces, $pathPiecesIndex, $doubleWildcardPieceCount);
162 + $pathPiece = \implode('/', $pathPiecesForSegment);
163 163 $pathPiecesIndex += $doubleWildcardPieceCount;
164 164 $pathPieces[] = $pathPiece;
165 165 continue;
166 166 }
@@ -170,16 +170,16 @@
170 170 }
171 171 }
172 172 if ($segment->getSeparator() === '/') {
173 173 if ($pathPiecesIndex >= $slashPathPiecesCount) {
174 - throw $this->matchException($path, "segment and path length mismatch");
174 + throw $this->matchException($path, 'segment and path length mismatch');
175 175 }
176 - $pathPiece = substr($slashPathPieces[$pathPiecesIndex++], $startIndex);
176 + $pathPiece = \substr($slashPathPieces[$pathPiecesIndex++], $startIndex);
177 177 $startIndex = 0;
178 178 } else {
179 - $rawPiece = substr($slashPathPieces[$pathPiecesIndex], $startIndex);
180 - $pathPieceLength = strpos($rawPiece, $segment->getSeparator());
181 - $pathPiece = substr($rawPiece, 0, $pathPieceLength);
179 + $rawPiece = \substr($slashPathPieces[$pathPiecesIndex], $startIndex);
180 + $pathPieceLength = \strpos($rawPiece, $segment->getSeparator());
181 + $pathPiece = \substr($rawPiece, 0, $pathPieceLength);
182 182 $startIndex += $pathPieceLength + 1;
183 183 }
184 184 $pathPieces[] = $pathPiece;
185 185 }
@@ -184,13 +184,13 @@
184 184 $pathPieces[] = $pathPiece;
185 185 }
186 186 if ($flattenedKeySegmentTuples[$i - 1][1]->getSegmentType() !== Segment::DOUBLE_WILDCARD_SEGMENT) {
187 187 // Process any remaining pieces. The binding logic will throw exceptions for any invalid paths.
188 - for (; $pathPiecesIndex < count($slashPathPieces); $pathPiecesIndex++) {
188 + for (; $pathPiecesIndex < \count($slashPathPieces); $pathPiecesIndex++) {
189 189 $pathPieces[] = $slashPathPieces[$pathPiecesIndex];
190 190 }
191 191 }
192 - $pathPiecesCount = count($pathPieces);
192 + $pathPiecesCount = \count($pathPieces);
193 193 // We would like to match pieces of our path 1:1 with the segments of our template. However,
194 194 // this is confounded by the presence of double wildcards ('**') in the template, which can
195 195 // match multiple segments in the path.
196 196 // Because there can only be one '**' present, we can determine how many segments it must
@@ -198,9 +198,9 @@
198 198 // path pieces.
199 199 if ($pathPiecesCount < $flattenedKeySegmentTuplesCount) {
200 200 // Each segment in $flattenedKeyedSegments must consume at least one
201 201 // segment in $pathSegments, so matching must fail.
202 - throw $this->matchException($path, "path does not contain enough segments to be matched");
202 + throw $this->matchException($path, 'path does not contain enough segments to be matched');
203 203 }
204 204 $doubleWildcardPieceCount = $pathPiecesCount - $flattenedKeySegmentTuplesCount + 1;
205 205 $bindings = [];
206 206 $pathPiecesIndex = 0;
@@ -226,9 +226,9 @@
226 226 }
227 227 // Collapse the bindings from lists into strings
228 228 $collapsedBindings = [];
229 229 foreach ($bindings as $key => $boundPieces) {
230 - $collapsedBindings[$key] = implode('/', $boundPieces);
230 + $collapsedBindings[$key] = \implode('/', $boundPieces);
231 231 }
232 232 return $collapsedBindings;
233 233 }
234 234 private function matchException(string $path, string $reason)
@@ -236,9 +236,9 @@
236 236 return new ValidationException("Could not match path '{$path}' to template '{$this}': {$reason}");
237 237 }
238 238 private function renderingException(array $bindings, string $reason)
239 239 {
240 - $bindingsString = print_r($bindings, \true);
240 + $bindingsString = \print_r($bindings, \true);
241 241 return new ValidationException("Error rendering '{$this}': {$reason}\n" . "Provided bindings: {$bindingsString}");
242 242 }
243 243 /**
244 244 * @param Segment[] $segments
@@ -244,9 +244,9 @@
244 244 * @param Segment[] $segments
245 245 * @param string|null $separator An optional string separator
246 246 * @return array[] A list of [string, Segment] tuples
247 247 */
248 - private static function buildKeySegmentTuples(array $segments, string $separator = null)
248 + private static function buildKeySegmentTuples(array $segments, ?string $separator = null)
249 249 {
250 250 $keySegmentTuples = [];
251 251 $positionalArgumentCounter = 0;
252 252 foreach ($segments as $segment) {
@@ -283,9 +283,9 @@
283 283 $nestedKeySegmentTuples = self::buildKeySegmentTuples($template->segments, $segment->getSeparator());
284 284 foreach ($nestedKeySegmentTuples as list($nestedKey, $nestedSegment)) {
285 285 /** @var Segment $nestedSegment */
286 286 // Nested variables are not allowed
287 - assert($nestedSegment->getSegmentType() !== Segment::VARIABLE_SEGMENT);
287 + \assert($nestedSegment->getSegmentType() !== Segment::VARIABLE_SEGMENT);
288 288 // Insert the nested segment with key set to the outer key of the
289 289 // parent variable segment
290 290 $flattenedKeySegmentTuples[] = [$key, $nestedSegment];
291 291 }
@@ -322,13 +322,13 @@
322 322 * @return string
323 323 */
324 324 private static function renderSegments(array $segmentsToRender)
325 325 {
326 - $renderResult = "";
327 - for ($i = 0; $i < count($segmentsToRender); $i++) {
326 + $renderResult = '';
327 + for ($i = 0; $i < \count($segmentsToRender); $i++) {
328 328 $segment = $segmentsToRender[$i];
329 329 $renderResult .= $segment;
330 - if ($i < count($segmentsToRender) - 1) {
330 + if ($i < \count($segmentsToRender) - 1) {
331 331 $renderResult .= $segment->getSeparator();
332 332 }
333 333 }
334 334 return $renderResult;