1 | <?php |
||
14 | class SegmentRepository |
||
15 | { |
||
16 | |||
17 | const BASE_URL = 'https://api.adnxs.com/segment/'; |
||
18 | |||
19 | /** @var Client */ |
||
20 | protected $client; |
||
21 | |||
22 | /** @var int */ |
||
23 | protected $memberId; |
||
24 | |||
25 | /** @var Cache */ |
||
26 | protected $cache; |
||
27 | |||
28 | /** @var bool */ |
||
29 | protected $cacheEnabled; |
||
30 | |||
31 | const CACHE_NAMESPACE = 'appnexus_segment_repository_find_all'; |
||
32 | |||
33 | const CACHE_EXPIRATION = 3600; |
||
34 | |||
35 | /** |
||
36 | * SegmentRepository constructor. |
||
37 | * |
||
38 | * @param ClientInterface $client |
||
39 | * @param Cache|null $cache |
||
40 | */ |
||
41 | public function __construct(ClientInterface $client, Cache $cache = null) |
||
47 | |||
48 | /** |
||
49 | * @param Segment $segment |
||
50 | * |
||
51 | * @return RepositoryResponse |
||
52 | * @throws \Exception |
||
53 | */ |
||
54 | public function add(Segment $segment) |
||
55 | { |
||
56 | |||
57 | $compiledUrl = self::BASE_URL.$segment->getMemberId(); |
||
58 | |||
59 | $payload = [ |
||
60 | 'segment' => $segment->torray(), |
||
61 | ]; |
||
62 | |||
63 | $response = $this->client->request('POST', $compiledUrl, ['body' => json_encode($payload)]); |
||
64 | |||
65 | $repositoryResponse = RepositoryResponse::fromResponse($response); |
||
66 | |||
67 | if ($repositoryResponse->isSuccessful()) { |
||
68 | |||
69 | $stream = $response->getBody(); |
||
70 | $responseContent = json_decode($stream->getContents(), true); |
||
71 | $stream->rewind(); |
||
72 | |||
73 | if (!(isset($responseContent['response']['segment']['id']))) { |
||
74 | throw RepositoryException::wrongFormat(serialize($responseContent)); |
||
75 | } |
||
76 | |||
77 | $segment->setId($responseContent['response']['segment']['id']); |
||
78 | } |
||
79 | |||
80 | return $repositoryResponse; |
||
81 | |||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param $id |
||
86 | * @param $memberId |
||
87 | * |
||
88 | * @return RepositoryResponse |
||
89 | */ |
||
90 | public function remove($id, $memberId) |
||
102 | |||
103 | /** |
||
104 | * @param Segment $segment |
||
105 | * |
||
106 | * @return RepositoryResponse |
||
107 | * @throws \Exception |
||
108 | */ |
||
109 | public function update(Segment $segment) |
||
129 | |||
130 | /** |
||
131 | * @param $id |
||
132 | * @param $memberId |
||
133 | * |
||
134 | * @return Segment|null |
||
135 | */ |
||
136 | public function findOneById($id, $memberId) |
||
156 | |||
157 | /** |
||
158 | * @param $memberId |
||
159 | * @param int $start |
||
160 | * @param int $maxResults |
||
161 | * |
||
162 | * @return Segment[]|null |
||
163 | */ |
||
164 | public function findAll($memberId, $start = 0, $maxResults = 100) |
||
203 | |||
204 | /** |
||
205 | * @return boolean |
||
206 | */ |
||
207 | public function isCacheEnabled() |
||
211 | |||
212 | public function disableCache() |
||
216 | |||
217 | public function enableCache() |
||
221 | |||
222 | } |
||
223 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.