Test Setup Failed
Pull Request — master (#62)
by Alex
03:33
created

IronicSerialiser   F

Complexity

Total Complexity 56

Size/Duplication

Total Lines 593
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 22

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 56
c 1
b 0
f 0
lcom 1
cbo 22
dl 0
loc 593
rs 1.7098

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
C writeTopLevelElement() 0 102 11
B writeTopLevelElements() 0 41 4
A writeUrlElement() 0 16 2
B writeUrlElements() 0 27 6
A writeTopLevelComplexObject() 0 4 1
A writeTopLevelBagObject() 0 4 1
A writeTopLevelPrimitive() 0 4 1
A getRequest() 0 6 1
A setRequest() 0 5 1
A getService() 0 4 1
A getStack() 0 4 1
B getEntryInstanceKey() 0 27 3
B writeMediaData() 0 38 4
A getProjectionNodes() 0 9 3
B getCurrentExpandedProjectionNode() 0 28 4
A shouldExpandSegment() 0 12 2
A needNextPageLink() 0 15 4
A getCurrentResourceSetWrapper() 0 7 2
A getNextLinkUri() 0 9 1
A loadStackIfEmpty() 0 7 2

How to fix   Complexity   

Complex Class

Complex classes like IronicSerialiser often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use IronicSerialiser, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace AlgoWeb\PODataLaravel\Serialisers;
4
5
use POData\Common\Messages;
6
use POData\Common\ODataConstants;
7
use POData\Common\ODataException;
8
use POData\IService;
9
use POData\ObjectModel\IObjectSerialiser;
10
use POData\ObjectModel\ODataEntry;
11
use POData\ObjectModel\ODataFeed;
12
use POData\ObjectModel\ODataLink;
13
use POData\ObjectModel\ODataMediaLink;
14
use POData\ObjectModel\ODataNavigationPropertyInfo;
15
use POData\ObjectModel\ODataPropertyContent;
16
use POData\ObjectModel\ODataURL;
17
use POData\ObjectModel\ODataURLCollection;
18
use POData\Providers\Metadata\ResourceEntityType;
19
use POData\Providers\Metadata\ResourceProperty;
20
use POData\Providers\Metadata\ResourcePropertyKind;
21
use POData\Providers\Metadata\ResourceSet;
22
use POData\Providers\Metadata\ResourceSetWrapper;
23
use POData\Providers\Metadata\ResourceType;
24
use POData\Providers\Metadata\Type\IType;
25
use POData\Providers\Query\QueryType;
26
use POData\UriProcessor\QueryProcessor\ExpandProjectionParser\ExpandedProjectionNode;
27
use POData\UriProcessor\QueryProcessor\ExpandProjectionParser\ProjectionNode;
28
use POData\UriProcessor\RequestDescription;
29
use POData\UriProcessor\SegmentStack;
30
31
class IronicSerialiser implements IObjectSerialiser
32
{
33
    /**
34
     * The service implementation.
35
     *
36
     * @var IService
37
     */
38
    protected $service;
39
40
    /**
41
     * Request description instance describes OData request the
42
     * the client has submitted and result of the request.
43
     *
44
     * @var RequestDescription
45
     */
46
    protected $request;
47
48
    /**
49
     * Collection of complex type instances used for cycle detection.
50
     *
51
     * @var array
52
     */
53
    protected $complexTypeInstanceCollection;
54
55
    /**
56
     * Absolute service Uri.
57
     *
58
     * @var string
59
     */
60
    protected $absoluteServiceUri;
61
62
    /**
63
     * Absolute service Uri with slash.
64
     *
65
     * @var string
66
     */
67
    protected $absoluteServiceUriWithSlash;
68
69
    /**
70
     * Holds reference to segment stack being processed.
71
     *
72
     * @var SegmentStack
73
     */
74
    protected $stack;
75
76
    /**
77
     * Lightweight stack tracking for recursive descent fill
78
     */
79
    private $lightStack = [];
80
81
    /**
82
     * @param IService           $service Reference to the data service instance
83
     * @param RequestDescription $request Type instance describing the client submitted request
84
     */
85
    public function __construct(IService $service, RequestDescription $request = null)
86
    {
87
        $this->service = $service;
88
        $this->request = $request;
89
        $this->absoluteServiceUri = $service->getHost()->getAbsoluteServiceUri()->getUrlAsString();
90
        $this->absoluteServiceUriWithSlash = rtrim($this->absoluteServiceUri, '/') . '/';
91
        $this->stack = new SegmentStack($request);
92
        $this->complexTypeInstanceCollection = [];
93
    }
94
95
    /**
96
     * Write a top level entry resource.
97
     *
98
     * @param mixed $entryObject Reference to the entry object to be written
99
     *
100
     * @return ODataEntry
101
     */
102
    public function writeTopLevelElement($entryObject)
103
    {
104
        if (!isset($entryObject)) {
105
            array_pop($this->lightStack);
106
            return null;
107
        }
108
109
        $this->loadStackIfEmpty();
110
111
        $stackCount = count($this->lightStack);
112
        $topOfStack = $this->lightStack[$stackCount-1];
113
        $resourceType = $this->getService()->getProvidersWrapper()->resolveResourceType($topOfStack[0]);
114
        $rawProp = $resourceType->getAllProperties();
115
        $relProp = [];
116
        foreach ($rawProp as $prop) {
117
            if ($prop->getResourceType() instanceof ResourceEntityType) {
118
                $relProp[] = $prop;
119
            }
120
        }
121
122
        $resourceSet = $resourceType->getCustomState();
123
        assert($resourceSet instanceof ResourceSet);
124
        $title = $resourceType->getName();
125
        $type = $resourceType->getFullName();
126
127
        $relativeUri = $this->getEntryInstanceKey(
128
            $entryObject,
129
            $resourceType,
130
            $resourceSet->getName()
131
        );
132
        $absoluteUri = rtrim($this->absoluteServiceUri, '/') . '/' . $relativeUri;
133
134
        list($mediaLink, $mediaLinks) = $this->writeMediaData($entryObject, $type, $relativeUri, $resourceType);
135
136
        $propertyContent = new ODataPropertyContent();
137
138
        $links = [];
139
        foreach ($relProp as $prop) {
140
            $nuLink = new ODataLink();
141
            $propKind = $prop->getKind();
142
143
            assert(
144
                ResourcePropertyKind::RESOURCESET_REFERENCE == $propKind
145
                || ResourcePropertyKind::RESOURCE_REFERENCE == $propKind,
146
                '$propKind != ResourcePropertyKind::RESOURCESET_REFERENCE &&'
147
                .' $propKind != ResourcePropertyKind::RESOURCE_REFERENCE'
148
            );
149
            $propTail = ResourcePropertyKind::RESOURCE_REFERENCE == $propKind ? 'entry' : 'feed';
150
            $propType = 'application/atom+xml;type='.$propTail;
151
            $propName = $prop->getName();
152
            $nuLink->title = $propName;
153
            $nuLink->name = ODataConstants::ODATA_RELATED_NAMESPACE . $propName;
154
            $nuLink->url = $relativeUri . '/' . $propName;
155
            $nuLink->type = $propType;
156
157
            $navProp = new ODataNavigationPropertyInfo($prop, $this->shouldExpandSegment($propName));
158
            if ($navProp->expanded) {
159
                $nextName = $prop->getResourceType()->getName();
160
                $nuLink->isExpanded = true;
161
                $isCollection = ResourcePropertyKind::RESOURCESET_REFERENCE == $propKind;
162
                $nuLink->isCollection = $isCollection;
163
                $value = $entryObject->$propName;
164
                array_push($this->lightStack, [$nextName, $propName]);
165
                if (!$isCollection) {
166
                    $expandedResult = $this->writeTopLevelElement($value);
167
                } else {
168
                    $expandedResult = $this->writeTopLevelElements($value);
169
                }
170
                $nuLink->expandedResult = $expandedResult;
171
                if (!isset($nuLink->expandedResult)) {
172
                    $nuLink->isCollection = null;
173
                    $nuLink->isExpanded = null;
174
                } else {
175
                    if (isset($nuLink->expandedResult->selfLink)) {
176
                        $nuLink->expandedResult->selfLink->title = $propName;
177
                        $nuLink->expandedResult->selfLink->url = $nuLink->url;
178
                        $nuLink->expandedResult->title = $propName;
179
                        $nuLink->expandedResult->id = rtrim($this->absoluteServiceUri, '/') . '/' . $nuLink->url;
180
                    }
181
                }
182
            }
183
184
            $links[] = $nuLink;
185
        }
186
187
        $odata = new ODataEntry();
188
        $odata->resourceSetName = $resourceSet->getName();
189
        $odata->id = $absoluteUri;
190
        $odata->title = $title;
191
        $odata->type = $type;
192
        $odata->propertyContent = $propertyContent;
193
        $odata->isMediaLinkEntry = $resourceType->isMediaLinkEntry();
194
        $odata->editLink = $relativeUri;
195
        $odata->mediaLink = $mediaLink;
196
        $odata->mediaLinks = $mediaLinks;
197
        $odata->links = $links;
198
199
        $newCount = count($this->lightStack);
200
        assert($newCount == $stackCount, "Should have $stackCount elements in stack, have $newCount elements");
201
        array_pop($this->lightStack);
202
        return $odata;
203
    }
204
205
    /**
206
     * Write top level feed element.
207
     *
208
     * @param array &$entryObjects Array of entry resources to be written
209
     *
210
     * @return ODataFeed
211
     */
212
    public function writeTopLevelElements(&$entryObjects)
213
    {
214
        assert(is_array($entryObjects), '!is_array($entryObjects)');
215
216
        $this->loadStackIfEmpty();
217
        $setName = $this->getRequest()->getTargetResourceSetWrapper()->getName();
218
219
        $title = $this->getRequest()->getContainerName();
220
        $relativeUri = $this->getRequest()->getIdentifier();
221
        $absoluteUri = $this->getRequest()->getRequestUrl()->getUrlAsString();
222
223
        $selfLink = new ODataLink();
224
        $selfLink->name = 'self';
225
        $selfLink->title = $relativeUri;
226
        $selfLink->url = $relativeUri;
227
228
        $odata = new ODataFeed();
229
        $odata->title = $title;
230
        $odata->id = $absoluteUri;
231
        $odata->selfLink = $selfLink;
232
233
        if ($this->getRequest()->queryType == QueryType::ENTITIES_WITH_COUNT()) {
234
            $odata->rowCount = $this->getRequest()->getCountValue();
235
        }
236
        foreach ($entryObjects as $entry) {
237
            $odata->entries[] = $this->writeTopLevelElement($entry);
238
        }
239
240
241
        if ($this->needNextPageLink(count($entryObjects))) {
242
            $stackSegment = $setName;
243
            $lastObject = end($entryObjects);
244
            $segment = $this->getNextLinkUri($lastObject, $absoluteUri);
245
            $nextLink = new ODataLink();
246
            $nextLink->name = ODataConstants::ATOM_LINK_NEXT_ATTRIBUTE_STRING;
247
            $nextLink->url = rtrim($this->absoluteServiceUri, '/') . '/' . $stackSegment . $segment;
248
            $odata->nextPageLink = $nextLink;
249
        }
250
251
        return $odata;
252
    }
253
254
    /**
255
     * Write top level url element.
256
     *
257
     * @param mixed $entryObject The entry resource whose url to be written
258
     *
259
     * @return ODataURL
260
     */
261
    public function writeUrlElement($entryObject)
262
    {
263
        $url = new ODataURL();
264
        if (!is_null($entryObject)) {
265
            $currentResourceType = $this->getCurrentResourceSetWrapper()->getResourceType();
266
            $relativeUri = $this->getEntryInstanceKey(
267
                $entryObject,
268
                $currentResourceType,
269
                $this->getCurrentResourceSetWrapper()->getName()
270
            );
271
272
            $url->url = rtrim($this->absoluteServiceUri, '/') . '/' . $relativeUri;
273
        }
274
275
        return $url;
276
    }
277
278
    /**
279
     * Write top level url collection.
280
     *
281
     * @param array $entryObjects Array of entry resources
282
     *                            whose url to be written
283
     *
284
     * @return ODataURLCollection
285
     */
286
    public function writeUrlElements($entryObjects)
287
    {
288
        $urls = new ODataURLCollection();
289
        if (!empty($entryObjects)) {
290
            $i = 0;
291
            foreach ($entryObjects as $entryObject) {
292
                $urls->urls[$i] = $this->writeUrlElement($entryObject);
293
                ++$i;
294
            }
295
296
            if ($i > 0 && $this->needNextPageLink(count($entryObjects))) {
297
                $stackSegment = $this->getRequest()->getTargetResourceSetWrapper()->getName();
298
                $lastObject = end($entryObjects);
299
                $segment = $this->getNextLinkUri($lastObject, $this->getRequest()->getRequestUrl()->getUrlAsString());
300
                $nextLink = new ODataLink();
301
                $nextLink->name = ODataConstants::ATOM_LINK_NEXT_ATTRIBUTE_STRING;
302
                $nextLink->url = rtrim($this->absoluteServiceUri, '/') . '/' . $stackSegment . $segment;
303
                $urls->nextPageLink = $nextLink;
304
            }
305
        }
306
307
        if ($this->getRequest()->queryType == QueryType::ENTITIES_WITH_COUNT()) {
308
            $urls->count = $this->getRequest()->getCountValue();
309
        }
310
311
        return $urls;
312
    }
313
314
    /**
315
     * Write top level complex resource.
316
     *
317
     * @param mixed &$complexValue The complex object to be
318
     *                                    written
319
     * @param string $propertyName The name of the
320
     *                                    complex property
321
     * @param ResourceType &$resourceType Describes the type of
322
     *                                    complex object
323
     *
324
     * @return ODataPropertyContent
325
     * @codeCoverageIgnore
326
     */
327
    public function writeTopLevelComplexObject(&$complexValue, $propertyName, ResourceType &$resourceType)
328
    {
329
        // TODO: Figure out if we need to bother implementing this
330
    }
331
332
    /**
333
     * Write top level bag resource.
334
     *
335
     * @param mixed &$BagValue The bag object to be
336
     *                                    written
337
     * @param string $propertyName The name of the
338
     *                                    bag property
339
     * @param ResourceType &$resourceType Describes the type of
340
     *                                    bag object
341
     * @codeCoverageIgnore
342
     * @return ODataPropertyContent
343
     */
344
    public function writeTopLevelBagObject(&$BagValue, $propertyName, ResourceType &$resourceType)
345
    {
346
        // TODO: Figure out if we need to bother implementing this
347
    }
348
349
    /**
350
     * Write top level primitive value.
351
     *
352
     * @param mixed &$primitiveValue The primitve value to be
353
     *                                            written
354
     * @param ResourceProperty &$resourceProperty Resource property
355
     *                                            describing the
356
     *                                            primitive property
357
     *                                            to be written
358
     * @codeCoverageIgnore
359
     * @return ODataPropertyContent
360
     */
361
    public function writeTopLevelPrimitive(&$primitiveValue, ResourceProperty &$resourceProperty = null)
362
    {
363
        // TODO: Figure out if we need to bother implementing this
364
    }
365
366
    /**
367
     * Gets reference to the request submitted by client.
368
     *
369
     * @return RequestDescription
370
     */
371
    public function getRequest()
372
    {
373
        assert(null != $this->request, 'Request not yet set');
374
375
        return $this->request;
376
    }
377
378
    /**
379
     * Sets reference to the request submitted by client.
380
     *
381
     * @param RequestDescription $request
382
     */
383
    public function setRequest(RequestDescription $request)
384
    {
385
        $this->request = $request;
386
        $this->stack->setRequest($request);
387
    }
388
389
    /**
390
     * Gets the data service instance.
391
     *
392
     * @return IService
393
     */
394
    public function getService()
395
    {
396
        return $this->service;
397
    }
398
399
    /**
400
     * Gets the segment stack instance.
401
     *
402
     * @return SegmentStack
403
     */
404
    public function getStack()
405
    {
406
        return $this->stack;
407
    }
408
409
    protected function getEntryInstanceKey($entityInstance, ResourceType $resourceType, $containerName)
410
    {
411
        $typeName = $resourceType->getName();
412
        $keyProperties = $resourceType->getKeyProperties();
413
        assert(count($keyProperties) != 0, 'count($keyProperties) == 0');
414
        $keyString = $containerName . '(';
415
        $comma = null;
416
        foreach ($keyProperties as $keyName => $resourceProperty) {
417
            $keyType = $resourceProperty->getInstanceType();
418
            assert($keyType instanceof IType, '$keyType not instanceof IType');
419
            $keyName = $resourceProperty->getName();
420
            $keyValue = $entityInstance->$keyName;
421
            if (!isset($keyValue)) {
422
                throw ODataException::createInternalServerError(
423
                    Messages::badQueryNullKeysAreNotSupported($typeName, $keyName)
424
                );
425
            }
426
427
            $keyValue = $keyType->convertToOData($keyValue);
428
            $keyString .= $comma . $keyName . '=' . $keyValue;
429
            $comma = ',';
430
        }
431
432
        $keyString .= ')';
433
434
        return $keyString;
435
    }
436
437
    /**
438
     * @param $entryObject
439
     * @param $type
440
     * @param $relativeUri
441
     * @param $resourceType
442
     * @return array
443
     */
444
    protected function writeMediaData($entryObject, $type, $relativeUri, ResourceType $resourceType)
445
    {
446
        $context = $this->getService()->getOperationContext();
447
        $streamProviderWrapper = $this->getService()->getStreamProviderWrapper();
448
        assert(null != $streamProviderWrapper, "Retrieved stream provider must not be null");
449
450
        $mediaLink = null;
451
        if ($resourceType->isMediaLinkEntry()) {
452
            $eTag = $streamProviderWrapper->getStreamETag2($entryObject, null, $context);
0 ignored issues
show
Bug introduced by
The method getStreamETag2() does not exist on POData\Providers\Stream\StreamProviderWrapper. Did you maybe mean getStreamETag()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
453
            $mediaLink = new ODataMediaLink($type, '/$value', $relativeUri . '/$value', '*/*', $eTag);
454
        }
455
        $mediaLinks = [];
456
        if ($resourceType->hasNamedStream()) {
457
            $namedStreams = $resourceType->getAllNamedStreams();
458
            foreach ($namedStreams as $streamTitle => $resourceStreamInfo) {
459
                $readUri = $streamProviderWrapper->getReadStreamUri2(
0 ignored issues
show
Bug introduced by
The method getReadStreamUri2() does not exist on POData\Providers\Stream\StreamProviderWrapper. Did you maybe mean getReadStream()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
460
                    $entryObject,
461
                    $resourceStreamInfo,
462
                    $context,
463
                    $relativeUri
464
                );
465
                $mediaContentType = $streamProviderWrapper->getStreamContentType2(
0 ignored issues
show
Bug introduced by
The method getStreamContentType2() does not exist on POData\Providers\Stream\StreamProviderWrapper. Did you maybe mean getStreamContentType()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
466
                    $entryObject,
467
                    $resourceStreamInfo,
468
                    $context
469
                );
470
                $eTag = $streamProviderWrapper->getStreamETag2(
0 ignored issues
show
Bug introduced by
The method getStreamETag2() does not exist on POData\Providers\Stream\StreamProviderWrapper. Did you maybe mean getStreamETag()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
471
                    $entryObject,
472
                    $resourceStreamInfo,
473
                    $context
474
                );
475
476
                $nuLink = new ODataMediaLink($streamTitle, $readUri, $readUri, $mediaContentType, $eTag);
477
                $mediaLinks[] = $nuLink;
478
            }
479
        }
480
        return [$mediaLink, $mediaLinks];
481
    }
482
483
    /**
484
     * Gets collection of projection nodes under the current node.
485
     *
486
     * @return ProjectionNode[]|ExpandedProjectionNode[]|null List of nodes
487
     *                                                        describing projections for the current segment, If this method returns
488
     *                                                        null it means no projections are to be applied and the entire resource
489
     *                                                        for the current segment should be serialized, If it returns non-null
490
     *                                                        only the properties described by the returned projection segments should
491
     *                                                        be serialized
492
     */
493
    protected function getProjectionNodes()
494
    {
495
        $expandedProjectionNode = $this->getCurrentExpandedProjectionNode();
496
        if (is_null($expandedProjectionNode) || $expandedProjectionNode->canSelectAllProperties()) {
497
            return null;
498
        }
499
500
        return $expandedProjectionNode->getChildNodes();
501
    }
502
503
    /**
504
     * Find a 'ExpandedProjectionNode' instance in the projection tree
505
     * which describes the current segment.
506
     *
507
     * @return ExpandedProjectionNode|null
508
     */
509
    protected function getCurrentExpandedProjectionNode()
510
    {
511
        $expandedProjectionNode = $this->getRequest()->getRootProjectionNode();
512
        if (is_null($expandedProjectionNode)) {
513
            return null;
514
        } else {
515
            $segmentNames = $this->getStack()->getSegmentNames();
516
            $depth = count($segmentNames);
517
            // $depth == 1 means serialization of root entry
518
            //(the resource identified by resource path) is going on,
519
            //so control won't get into the below for loop.
520
            //we will directly return the root node,
521
            //which is 'ExpandedProjectionNode'
522
            // for resource identified by resource path.
523
            if (0 != $depth) {
524
                for ($i = 1; $i < $depth; ++$i) {
525
                    $expandedProjectionNode = $expandedProjectionNode->findNode($segmentNames[$i]);
526
                    assert(!is_null($expandedProjectionNode), 'is_null($expandedProjectionNode)');
527
                    assert(
528
                        $expandedProjectionNode instanceof ExpandedProjectionNode,
529
                        '$expandedProjectionNode not instanceof ExpandedProjectionNode'
530
                    );
531
                }
532
            }
533
        }
534
535
        return $expandedProjectionNode;
536
    }
537
538
    /**
539
     * Check whether to expand a navigation property or not.
540
     *
541
     * @param string $navigationPropertyName Name of naviagtion property in question
542
     *
543
     * @return bool True if the given navigation should be
544
     *              explanded otherwise false
545
     */
546
    protected function shouldExpandSegment($navigationPropertyName)
547
    {
548
        $expandedProjectionNode = $this->getCurrentExpandedProjectionNode();
549
        if (is_null($expandedProjectionNode)) {
550
            return false;
551
        }
552
553
        $expandedProjectionNode = $expandedProjectionNode->findNode($navigationPropertyName);
554
555
        // null is a valid input to an instanceof call as of PHP 5.6 - will always return false
556
        return $expandedProjectionNode instanceof ExpandedProjectionNode;
557
    }
558
559
    /**
560
     * Wheter next link is needed for the current resource set (feed)
561
     * being serialized.
562
     *
563
     * @param int $resultSetCount Number of entries in the current
564
     *                            resource set
565
     *
566
     * @return bool true if the feed must have a next page link
567
     */
568
    protected function needNextPageLink($resultSetCount)
569
    {
570
        $currentResourceSet = $this->getCurrentResourceSetWrapper();
571
        $recursionLevel = count($this->getStack()->getSegmentNames());
572
        $pageSize = $currentResourceSet->getResourceSetPageSize();
573
574
        if (1 == $recursionLevel) {
575
            //presence of $top option affect next link for root container
576
            $topValueCount = $this->getRequest()->getTopOptionCount();
577
            if (!is_null($topValueCount) && ($topValueCount <= $pageSize)) {
578
                return false;
579
            }
580
        }
581
        return $resultSetCount == $pageSize;
582
    }
583
584
    /**
585
     * Resource set wrapper for the resource being serialized.
586
     *
587
     * @return ResourceSetWrapper
588
     */
589
    protected function getCurrentResourceSetWrapper()
590
    {
591
        $segmentWrappers = $this->getStack()->getSegmentWrappers();
592
        $count = count($segmentWrappers);
593
594
        return 0 == $count ? $this->getRequest()->getTargetResourceSetWrapper() : $segmentWrappers[$count - 1];
595
    }
596
597
    /**
598
     * Get next page link from the given entity instance.
599
     *
600
     * @param mixed  &$lastObject Last object serialized to be
601
     *                            used for generating $skiptoken
602
     * @param string $absoluteUri Absolute response URI
603
     *
604
     * @return string for the link for next page
605
     */
606
    protected function getNextLinkUri(&$lastObject, $absoluteUri)
0 ignored issues
show
Unused Code introduced by
The parameter $absoluteUri is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
607
    {
608
        $currentExpandedProjectionNode = $this->getCurrentExpandedProjectionNode();
609
        $internalOrderByInfo = $currentExpandedProjectionNode->getInternalOrderByInfo();
610
        $skipToken = $internalOrderByInfo->buildSkipTokenValue($lastObject);
611
        assert(!is_null($skipToken), '!is_null($skipToken)');
612
        $skipToken = '?$skip='.$skipToken;
613
        return $skipToken;
614
    }
615
616
    private function loadStackIfEmpty()
617
    {
618
        if (0 == count($this->lightStack)) {
619
            $typeName = $this->getRequest()->getTargetResourceType()->getName();
620
            array_push($this->lightStack, [$typeName, $typeName]);
621
        }
622
    }
623
}
624