Code Duplication    Length = 41-41 lines in 2 locations

src/repository/CategoryRepository.php 1 location

@@ 77-117 (lines=41) @@
74
     * @return Category[]|null
75
     * @throws RepositoryException
76
     */
77
    public function findAll($start = 0, $maxResults = 100)
78
    {
79
80
        $cacheKey = self::CACHE_NAMESPACE . sha1($start . $maxResults);
81
82
        if ($this->isCacheEnabled()) {
83
            if ($this->cache->contains($cacheKey)) {
84
                return $this->cache->fetch($cacheKey);
85
            }
86
        }
87
88
        $compiledUrl = $this->baseUrl . "?start_element=$start&num_elements=$maxResults";
89
90
        $response = $this->client->request('GET', $compiledUrl);
91
92
        $repositoryResponse = RepositoryResponse::fromResponse($response);
93
94
        if (!$repositoryResponse->isSuccessful()) {
95
            throw RepositoryException::failed($repositoryResponse);
96
        }
97
98
        $stream          = $response->getBody();
99
        $responseContent = json_decode($stream->getContents(), true);
100
        $stream->rewind();
101
102
        $result = [];
103
104
        if (!$responseContent['response']['content_categories']) {
105
            $responseContent['response']['content_categories'] = [];
106
        }
107
108
        foreach ($responseContent['response']['content_categories'] as $segmentArray) {
109
            $result[] = Category::fromArray($segmentArray);
110
        }
111
112
        if ($this->isCacheEnabled()) {
113
            $this->cache->save($cacheKey, $result, self::CACHE_EXPIRATION);
114
        }
115
116
        return $result;
117
    }
118
}
119

src/repository/SegmentRepository.php 1 location

@@ 184-224 (lines=41) @@
181
     * @return Segment[]|null
182
     * @throws RepositoryException
183
     */
184
    public function findAll($memberId, $start = 0, $maxResults = 100)
185
    {
186
187
        $cacheKey = self::CACHE_NAMESPACE.sha1($memberId.$start.$maxResults);
188
189
        if ($this->isCacheEnabled()) {
190
            if ($this->cache->contains($cacheKey)) {
191
                return $this->cache->fetch($cacheKey);
192
            }
193
        }
194
195
        $compiledUrl = $this->baseUrl.$memberId."?start_element=$start&num_elements=$maxResults";
196
197
        $response = $this->client->request('GET', $compiledUrl);
198
199
        $repositoryResponse = RepositoryResponse::fromResponse($response);
200
201
        if (!$repositoryResponse->isSuccessful()) {
202
            throw RepositoryException::failed($repositoryResponse);
203
        }
204
205
        $stream = $response->getBody();
206
        $responseContent = json_decode($stream->getContents(), true);
207
        $stream->rewind();
208
209
        $result = [];
210
211
        if (!$responseContent['response']['segments']) {
212
            $responseContent['response']['segments'] = [];
213
        }
214
215
        foreach ($responseContent['response']['segments'] as $segmentArray) {
216
            $result[] = Segment::fromArray($segmentArray);
217
        }
218
219
        if ($this->isCacheEnabled()) {
220
            $this->cache->save($cacheKey, $result, self::CACHE_EXPIRATION);
221
        }
222
223
        return $result;
224
    }
225
}
226